I trained model with transfer learning weights and with cat vs dog data, I got over 95% accuracy for both train and validation accuracy. When I upload cat images, for some images it classifies cat and for some images classifies dog but for all dog images it classifies cat, why is this happening? what is the solution? Also when I trained horse vs human data, it happens like every time model classifies as horse for horse or human images?
Brian. I can’t quite understand your question properly.
- How many cat / dog images was the model trained on?
- When you say you uploaded cat / dog images, where did these images come from?
- How many images did you test on?
Balaji Thanks for replying.
I trained on full data set i.e. of 22500 images with image generator.
after training I downloaded images from internet(instructor did same thing in some videos) and upload for prediction but it always predict same class i.e. cat.
also I trained horse vs human data with 1300 images and it always predicts horse. why is this happening.
Is it possible that you’re reading the labels incorrectly?
Could you try with 80% of all data for training and 20% for testing. That way, you’ll have a better understanding if all dogs were tagged as cats. It’s also possible that a few images you tried were misclassified.
Could you share the links to the pictures you’re testing on?
This solves my problem
The following line should be replaced
x=np.expand_dims(x,axis=0)
by
x=np.expand_dims(x,axis=0)/255
Thank you Brian for your post. I experienced the same issue and your proposed solution also solves the PB in my case. But do you know why? I thought when we do
x= img_to_array
x/=255
We already normalize the image’s pixels.