title: Keras Val_acc is good but prediction for same data is poor
body: <p>I am using Keras for a CNN two class classification. While training my val_acc is above 95 percent. But when I predict result for the same validation data the acc is less than 60 percent, is that even possible? This is my Code:</p>
  
  <pre><code>from keras.preprocessing.image import ImageDataGenerator
  from keras.models import Sequential
  from keras.layers import Convolution2D, MaxPooling2D
  from keras.layers import Activation, Dropout, Flatten, Dense
  from keras import backend as K
  from keras.callbacks import TensorBoard
  from keras.preprocessing import image
  import matplotlib.pyplot as plt
  import numpy as np
  np.random.seed(1337) # for reproducibility
  %matplotlib inline
  
  img_width, img_height = 230,170
  
  train_data_dir = 'data/Train'
  validation_data_dir = 'data/Validation'
  nb_train_samples =  13044
  nb_validation_samples = 200
  epochs =14
  batch_size = 32
  
  if K.image_data_format() == 'channels_first':
      input_shape = (1, img_width, img_height)
  else:
      input_shape = (img_width, img_height, 1)
  
  model = Sequential()
  
  model.add(Convolution2D(32, (3, 3),data_format='channels_first' , input_shape=(1,230,170))) 
  convout1 = Activation('relu')
  model.add(convout1)
  convout2 = MaxPooling2D(pool_size=(2,2 ), strides= None , padding='valid', data_format='channels_first')
  model.add(convout2)
  
  model.add(Convolution2D(32, (3, 3),data_format='channels_first'))
  convout3 = Activation('relu')
  model.add(convout3)
  model.add(MaxPooling2D(pool_size=(2, 2), data_format='channels_first'))
  
  model.add(Convolution2D(64, (3, 3),data_format='channels_first'))
  convout4 = Activation('relu')
  model.add(convout4)
  convout5 = MaxPooling2D(pool_size=(2, 2), data_format='channels_first')
  model.add(convout5)
  
  model.add(Flatten())
  model.add(Dense(64))
  model.add(Activation('relu'))
  model.add(Dropout(0.5))
  model.add(Dense(1))
  model.add(Activation('sigmoid'))
  
  model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
  
  train_datagen = ImageDataGenerator(rescale=1. / 255, 
                                     shear_range=0, 
                                     zoom_range=0.2, 
                                     horizontal_flip=False, 
                                     data_format='channels_first')
  
  test_datagen = ImageDataGenerator(rescale=1. / 255, 
                                    data_format='channels_first')
  train_generator = train_datagen.flow_from_directory(
      train_data_dir,
      target_size=(img_width, img_height),
      batch_size=batch_size,
      class_mode='binary',
      color_mode= "grayscale",
      shuffle=True
  )
  validation_generator = test_datagen.flow_from_directory(
      validation_data_dir,
      target_size=(img_width, img_height),
      batch_size=batch_size,
      class_mode='binary',
      color_mode= "grayscale",
      shuffle=True
  )
  model.fit_generator(
      train_generator,
      steps_per_epoch=nb_train_samples // batch_size,
      epochs=epochs,
      validation_data=validation_generator,
      validation_steps=nb_validation_samples // batch_size,
      shuffle=True
      )
  </code></pre>
  
  <p>Epoch 37/37</p>
  
  <p>407/407[==============] - 1775s 4s/step - loss: 0.12 - acc: 0.96 - val_loss: 0.02 - val_acc: 0.99</p>
  
  <pre><code>#Prediction:
  test_data_dir='data/test'
  validgen = ImageDataGenerator(horizontal_flip=False, data_format='channels_first')
  test_gen = validgen.flow_from_directory(
           test_data_dir,
           target_size=(img_width, img_height),
           batch_size=1,
           class_mode='binary',
           shuffle=False,
           color_mode= "grayscale")
  
  preds = model.predict_generator(test_gen)
  </code></pre>
  
  <p>In the below output about 7 images belong to class 0. I tried the same for all 100 images of the class 0 validation data and only 15 images were predicted as class 0 and remaining was predicted as class 1</p>
  
  <pre><code>Found 10 images belonging to 1 classes.
  [[ 1.]
   [ 1.]
   [ 1.]
   [ 1.]
   [ 1.]
   [ 1.]
   [ 1.]
   [ 0.]
   [ 0.]
   [ 1.]]
  </code></pre>