Skip to content
Advertisement

Keras model.evaluate accuracy stuck at 50 percent while using ImageDataGenerator

I am trying to find the accuracy of my saved Keras model using model.evaluate.

I have loaded in my model using this:

JavaScript

I have a CSV file with two columns, one for the filename of an image and one for the label. Here is a sample:

JavaScript

I have loaded this CSV into a pandas dataframe and fed it into an ImageDataGenerator:

JavaScript

Now I try to evaluate my model using:

JavaScript

However, the accuracy doesn’t change from 50 percent, but, my model had a 90 percent validation accuracy when trained.

Here is what is returned:

JavaScript

I was able to ensure that my model worked and the generator was properly feeding data, by creating an ROC curve using matplotlib and scikit-learn, which produced a 90 percent AUC, so I’m not sure where the problem is:

JavaScript

Similar questions say that the problem came from setting shuffle parameter in the ImageDataGenerator to True, but mine has always been set to False. Another similar problem was fixed by retraining with a sigmoid activation rather than softmax, but I used sigmoid in my final layer, so that can’t be the problem

This is my first time using Keras. What did I do wrong?

Advertisement

Answer

The problem was because of class_mode parameter in flow function. Default is categorical.

Setting it as binary solved the problem. Corrected code:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement