I am using celeba dataset to train my CNN face landmark detection model. Here is my model

class LandmarkModel:
    def __init__(self,inp_shape):
        self.model = models.Sequential()
        self.model.add(layers.Conv2D(16, (3, 3), activation='relu', input_shape=inp_shape))#l1
        self.model.add(layers.Conv2D(32,(3, 3), activation='relu'))
        self.model.add(layers.MaxPooling2D((2, 2)))
        self.model.add(layers.Conv2D(64,(3, 3), activation='relu'))

    def getModel(self):
        return self.model

I have trained my model for around 5k-6k images with loss of 0.1. When I use image from dataset that is outside of training sample I get correct prediction. But when I use my own clicked images predictions are completely off. I have clicked photos exactly like in dataset. I have also tried with downloaded celeb images still wrong predictions. What is the reason of this behavior?

  • $\begingroup$ Are you preprocessing any new images in the same way as your training and validation images? $\endgroup$
    – Oxbowerce
    Commented Apr 23, 2021 at 8:43
  • $\begingroup$ @Oxbowerce Yes. As I said Validation Images from dataset works but not for my images $\endgroup$
    – LOLs
    Commented Apr 23, 2021 at 8:49
  • $\begingroup$ A little bit offtop, but why Dense(512) doesn't have activation? $\endgroup$ Commented Apr 23, 2021 at 9:37
  • $\begingroup$ @LOLs perhaps some printouts from training and evaluation phases would help verify the process. $\endgroup$
    – lpounng
    Commented May 24, 2022 at 4:32

1 Answer 1


That could a lot of reasons for that. For example, images are sometimes represented with numbers in range 0-1 and sometimes in range 0-255 and it's very easy to mix these ranges for in-dataset / external as the model would fail silently without any warnings.

In general, if the same model gives you different results, then images are not exactly the same. I suggest you take the same image from your dataset and internet and compare the raw numbers on the input of the model. If results different, then input tensors should be different and you can check your preprocessing pipeline step by step to find the point of discrepancy.

The debugging tools like ipdb are usually very useful in such situations.

  • $\begingroup$ Can you tell any other reasons. Both the image value are similar and image format is also same $\endgroup$
    – LOLs
    Commented Apr 23, 2021 at 12:24
  • $\begingroup$ I didn't mean similar, I mean exact. Take the image from dataset, make reverse search by image with something like images.google.com, find the exact same photo in the internet, apply the approach I proposed. $\endgroup$ Commented Apr 23, 2021 at 13:24
  • $\begingroup$ It's a lot of small thing to mess up with neural net and unfortunately nobody can guess your problem without debugging your code. See, 1. What is the clicked images exactly? 2. Why don't you apply activation function on Dense(512)? 3. Double check you didn't use validation samples during training 4. It's good idea to split by identities, i.e. use all photo of a specific person either in train or val 5. Make sure you don't apply training augmentations during inference, etc, etc. $\endgroup$ Commented Apr 23, 2021 at 13:25
  • $\begingroup$ You can try a lot of things from this thread twitter.com/karpathy/status/1013244313327681536, but approach I proposed would be more direct and probably the fastest. $\endgroup$ Commented Apr 23, 2021 at 13:25
  • $\begingroup$ Can Image size cause problem? Cause my images are of different resolution than I have trained. I have resized to same but I still doubt that $\endgroup$
    – LOLs
    Commented Apr 24, 2021 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.