title: Keras model.evaluate_generator results nearly twice real accuracy?
body: <h2>UPDATE: see new section below.</h2>
  
  <p>When I run model.evaluate_generator it gives me results of 92%. But if I run model.predict_classes on every test image and count the correct classification vs incorrect classification, I get 49%...</p>
  
  <p>Clearly something is wrong. Am I misunderstanding the evaluate_generator results, or am I not doing predict_classes right?</p>
  
  <p>Here is the model.evaluate_generator call (it gets 92%):</p>
  
  <pre><code>print("test_generator from Directory");
  test_generator = test_datagen.flow_from_directory( 
  test_dir, 
  target_size=(200, 200), 
  batch_size=20, 
  class_mode='categorical') 
  
  # finally evaluate this model on the test data 
  results = model.evaluate_generator( 
  test_generator, 
  steps=1) 
  
  print('Final test accuracy:', (results[1]*100.0))
  </code></pre>
  
  <p>For the comparison, I test every file and compare to the correct classification (this gets 49%):</p>
  
  <pre><code>  img_path = os.path.join(bol, file)
    print(img_path)
    image = load_img(img_path, target_size=(200, 200)) 
    image = img_to_array(image) 
    image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
    image = preprocess_input(image)
    # classify the image 
    print("classifying image...") 
    y_hat = model.predict_classes(image) 
    print(y_hat[0])
    idtype = newdict[y_hat[0]]  #this part is to match predicted class with true class
    destpath = os.path.join(bol, idtype, file)      
    print(idtype)
    if idtype == cat[1]:
      correct = correct + 1
    count = count + 1
    factor = correct / count
    print(str(count) + " - " + str(correct) + " = " + str(factor))
  </code></pre>
  
  <p>The full code is here: <a href="https://s3.eu-west-2.amazonaws.com/klondon/food_6_VGG_aug_plus_id.py.txt" rel="nofollow noreferrer">https://s3.eu-west-2.amazonaws.com/klondon/food_6_VGG_aug_plus_id.py.txt</a></p>
  
  <h2>EDIT:</h2>
  
  <p>With the help of Matias Valdenegro in the comments, I have fixed some bugs with my code. It now uses 'Softmax' output and categorical cross-entropy loss. Full code here: <a href="https://s3.eu-west-2.amazonaws.com/klondon/food_6_VGG_aug_plus_id_cat.py.txt" rel="nofollow noreferrer">https://s3.eu-west-2.amazonaws.com/klondon/food_6_VGG_aug_plus_id_cat.py.txt</a></p>
  
  <p>However - The core issue remains. There is a huge difference between the results from evaluate_generator (now 71%) and a manual test of the same images using predict_classes (53%).</p>
  
  <p>Are there other issues with my code? </p>
  
  <h2>EDIT 2:</h2>
  
  <p>I have tried setting shuffle=False and batch_size = 1 for testing, but the issue remains. evaluate_generator still returns ~70% while predict_classes is ~50%</p>
  
  <h2>EDIT 3:</h2>
  
  <p>Fixed code here: <a href="https://s3.eu-west-2.amazonaws.com/klondon/food_6_VGG_aug_plus_id_fix.py.txt" rel="nofollow noreferrer">https://s3.eu-west-2.amazonaws.com/klondon/food_6_VGG_aug_plus_id_fix.py.txt</a></p>
  
  <p>Issue was: I shouldn't use preprocess_input in predict_classes unless that is used in training and validation also. Also, I should use image /=255 to match the training &amp; validation images. </p>