Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference in predictions between model.predict() and model.predict_generator() in keras

When I use model.predict_generator() on my test_set (images) I am getting a different prediction and when I use mode.predict() on the same test_Set I am getting a different set of predictions.

For using model.predict_generator I followed the below steps to create a generator:

  1. Imagedatagenerator(no arguments here) and used flow_from_directory with shuffle = False.
  2. There are no augmentations nor preprocessing of images(normalization,zero-centering etc) while training the model.

I am working on a binary classification problem involving dogs and cats (from kaggle).On the test set, I have 1000 cat images. and by using model.predict_generator() I am able to get 87% accuracy()i.e 870 images are classified correctly. But while using model.predict I am getting 83% accuracy.

This is confusing because both should give identical results right? Thanks in advance :)

like image 247
Abhijit Balaji Avatar asked Jul 15 '17 07:07

Abhijit Balaji


People also ask

What is model predict in Keras?

Keras model predicts is the method of function provided in Keras that helps in the predictions of output depending on the specified samples of input to the model.

What is Predict_generator?

predict_generator. (Deprecated) Generates predictions for the input samples from a data generator.

What does model Evaluate_generator do?

(Deprecated) Evaluates the model on a data generator.


1 Answers

@petezurich Thanks for your comment. Generator.reset() before model.predict_generator() and turning off the shuffle in predict_generator() fixed the problem

like image 176
Abhijit Balaji Avatar answered Oct 17 '22 10:10

Abhijit Balaji