title: Keras binary classification: same prediction output class
body: <p>I am using Keras sequential model for image classification. My problem is to find a particular watermark present in any part of the image or not. I am using a dataset of 9000 images. Keras backend is Tensorflow.</p>
  
  <pre><code>Keras==2.0.4  
  tensorflow==1.2.1
  </code></pre>
  
  <p>While training, I am getting an accuracy of 86% and val_acc is 91%. But all the prediction result is categorizing to one category. </p>
  
  <p><a href="https://i.stack.imgur.com/LYwzx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LYwzx.jpg" alt=""></a></p>
  
  <p>The program used for training is given below.</p>
  
  <pre><code>import h5py
  import numpy as np
  import cv2
  import keras
  from keras.models import Sequential
  from keras.layers import Convolution2D
  from keras.layers import MaxPooling2D
  from keras.layers import Flatten
  from keras.layers import Dense
  from keras.layers import Activation, Dropout
  from keras.preprocessing.image import ImageDataGenerator
  from PIL import ImageFile
  
  ImageFile.LOAD_TRUNCATED_IMAGES = True
  
  classifier = Sequential()
  classifier.add(Convolution2D(32, 3, 3, input_shape = (150, 150, 3), activation = 'relu'))
  classifier.add(MaxPooling2D(pool_size = (2, 2)))
  classifier.add(Convolution2D(32, 3, 3, activation = 'relu'))
  classifier.add(MaxPooling2D(pool_size = (2, 2)))
  classifier.add(Convolution2D(64, 3, 3))
  classifier.add(Activation('relu'))
  classifier.add(MaxPooling2D(pool_size=(2, 2)))
  classifier.add(Flatten())
  classifier.add(Dense(output_dim = 64, activation = 'relu'))
  classifier.add(Dropout(0.5))
  classifier.add(Dense(output_dim = 1, activation = 'sigmoid'))
  classifier.compile(optimizer = 'rmsprop', loss = 'binary_crossentropy', metrics = ['accuracy'])
  
  
  train_datagen = ImageDataGenerator(rescale = 1./255,
                                     shear_range = 0.2,
                                     zoom_range = 0.2,
                                     horizontal_flip = True)
                                     #rotation_range=15,
                                     #zca_whitening=True)
  
  test_datagen = ImageDataGenerator(rescale = 1./255)
  
  training_set = train_datagen.flow_from_directory('train',
                                                   target_size = (150, 150),
                                                   batch_size = 32,
                                                   class_mode = 'binary')
  
  test_set = test_datagen.flow_from_directory('test',
                                              target_size = (150, 150),
                                              batch_size = 32,
                                              class_mode = 'binary')
  
  callbacks = [
    keras.callbacks.EarlyStopping(
      monitor='val_loss', patience=10, verbose=0)
    ]
  
  hist = classifier.fit_generator(training_set,
                           samples_per_epoch = 9000,
                           nb_epoch = 10,
                           validation_data = test_set,
                           nb_val_samples = 3000,
                           callbacks=callbacks)
                           # )
  </code></pre>
  
  <p><code>train</code> directory has 2 subdirectories: <code>watermark</code> and <code>nonwatermark</code>. Am I doing anything wrong? Any help will be appreciated.</p>