-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keras fine tuned VGG16 with good accuracy gives many wrong predictions #11590
Comments
We can't really assume that it's a keras bug unless you know what is going on or that you can provide a minimal example with a very small network to reproduce the bug. Having different performance at training/testing time is very common in ML. |
Thank you for the answer @gabrieldemarmiesse. I understand that it is common to have a difference in the performance due to different factors. However, even if we assume that the model overfit on the training dataset, isn't it weird that model.predict() gives a very low accuracy even on the training set? |
Do you have batchnorm in your model? |
This is the code I used. I will try to update the notebook and add the code with predict_classes(). The dataset is not loaded since I don't have it ready on my laptop. If you need it, I will upload it later too. |
Here is a link to the dataset https://drive.google.com/drive/folders/1lXQQhsIw4XnSIkPnBcuva4myY8raHLba?usp=sharing |
This happens even when I train inception model. Downgrading keras to 2.1.6 works. |
@adityapatadia downgrading to keras 2.1.6 and running the same code significantly changed the results? |
Yes. Everything is back to normal. Latest keras has issues. |
I'll tag this as a bug since many people reported the same behaviour. It would be nice to know which commit exactly did this. Can someone make a test to expose this behaviour easily in one single run? |
@GabrielBianconi since you are on it, please also check this issue #9965. It's closed long ago but the bug is still haunting lot of users. The example give here #9214 proves that batchnorm is doing wrong math. |
This "issue" with batchnorm isn't really an issue. It's just something to be aware about. |
I understand that, but as per my knowledge it's not possible to set 'training' flag to |
Did you train the model again using that Keras version or just use predict_classes() ? |
@adityapatadia Can you please tell me what version of tensorflow you used? I tried again with this specific version and I still have the same issue. When I try to predict classes, on one class I get accuracy 0 while for the 3 others accuracy is between 60 and 90. The training/validation shows very good results ... so I'm getting really confused here. Or is it a VGG16 issue? |
I used TF 1.12. May be it is VGG 16 issue. I was facing same issue with inception and it was resolved after downgrade. |
I trained new model. |
I understand the difficulties to hide some mecanisms.... |
PR welcome to fix the current example in the docs :) |
I have fine-tuned VGG16 to classify my own dataset (of 4 classes) and while the training seemed to go well (high accuracy on training and validating during training and on testing set when the training finished) and the results of both model.evaluate() and the use of confusion matrix show really good results, once I tried to predict on my dataset using the model, it's a nightmare. I am using the following code:
I divided the total of correct prediction by the total number of images to estimate the accuracy, and the result is around 30% for 1 class and 50 % for another class (on testing data) and it tends to classify the images as the 4rth class a lot. I even tried with training data and the accuracy is still low. I don't understand why there is this big difference in performance calculation. Am I not supposed to trust the accuracy, loss, confusion matrix and model.evaluate() ?? If so, how can I monitor the learning of my model and how can I make sure it is learning ?
For the reference, this is how I compiled the VGG16 (after loading it without top and adding my own classifier then freezing everything except the top 2 blocks)
I would really appreciate any help. I am no longer sure whether there is a bug somewhere in Keras VGG or if I am not using predict correctly. It is just weird how the predictions are wrong this much after all the good results the model seemed to give.
The text was updated successfully, but these errors were encountered: