Abhijit Balaji
Abhijit Balaji

Reputation: 1940

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 :)

Upvotes: 10

Views: 6928

Answers (1)

Abhijit Balaji
Abhijit Balaji

Reputation: 1940

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

Upvotes: 2

Related Questions