Why does my cnn model doesnt generalize well to unseen data?

I have just started learning cnn and i tried using transfer learning (pretrained model mobilenet) for creating model that recognizes sign language digits from image. it works well for trained data but when i apply my hand images it doesnt provide correct prediction. What should i do??

Are you familiar with deep learning specialization?

What was the original MobilNet model trained to recognize? If it’s anything different than sign language digits then you presumably added your own output layer and did incremental training on your images of sign language digits. How big is your additional training set? How does your training set differ from the “my hand images” that you refer to?

CNNs and DL models in general typically require a large amount of data in order to get a generalizable model.

As Balaji suggests, all the issues here are covered in the Deep Learning Specialization, in particular you’d want to take Course 4 on ConvNets which includes a section on Transfer Learning as well.

1 Like

i have just completed week 2 of course 4 from deep learning specialization. the dataset for the model was picked from kaggle that contains 1500 images each for a number that means total 15000 images. i tried making "my hand image " pretty similar to one in dataset but its not working

this one is from dataset

and this one is my hand:

Ok, that should work then. I’ll bet the problem is that you did not normalize your pixel values. Image processing models are always trained on normalized pixel values because the convergence is much better. Raw pixel values are uint8, so they are 0 to 255 and that gives crazy cost surfaces. The simplest form of normalization is just dividing by 255, but sometimes they normalize to -1 to 1. You need to read the specs on the model you are using to know which method to use.

If that’s not the issue, then also notice that the background in the sample image is basically blank, whereas your image has a pretty complex background. Try taking your pictures in front of a blank wall and see if that makes a difference. But definitely check the normalization first.

1 Like

i have used normalization but i will try the blank wall one

1 Like

And are you sure you used the same form of normalization? Did the specs actually specify that? You can also just dump the pixel values of one of their images and see for yourself.

1 Like

it looks like there are other images on dataset that have similar backgrounds

1 Like

i will look after what you said thank you for your help.

1 Like

Also note that your image is much higher resolution than the one from the dataset, so you are obviously “preprocessing” your images into the size and form expected by the model. Are you sure that process is correct? E.g. have you printed your images after the normalization and resizing?

This is an interesting type of problem that a lot of people will encounter when they first try Transfer Learning, so it would be helpful if you could share with us what the answer is once you figure it out. The benefit of the community is that we can share the knowledge we gain. :nerd_face:

1 Like

thank you for your suggesyions ill make sure to try it all out and share the answer as soon as possible

2 Likes