title: ValueError: Input arrays should have the same number of samples as target arrays
body: <p>Using Keras DL library with Tensorflow backend, I'm attempting to extract features from the intermediate layer of VGG-16 to perform binary classification on my task of interest. </p>
  
  <p>The data set contains 1000 (500 for each class) training samples and 200 (100 for each class) test samples. I'm training a small fully connected model on top of the extracted features. On running the code, I could see that the size of the train_data is (10000,6,6,512), validation_data is (2000,6,6,512) (float32), train_labels is (1000,2) and validation_labels is (200,2) (int32). </p>
  
  <p>Here is the code:</p>
  
  <pre><code>########################load libraries#########################################
  import numpy as np
  import time
  from keras.layers import Dense, Dropout, Flatten
  from keras.models import Model
  from keras import applications
  from keras.optimizers import SGD
  from keras.preprocessing.image import ImageDataGenerator
  #########################image characteristics#################################
  img_rows=100 #dimensions of image, to be varied suiting the input requirements of the pre-trained model
  img_cols=100
  channel = 3 #RGB
  num_classes = 2
  batch_size = 10 
  nb_epoch = 10
  ###############################################################################
  ''' This code uses VGG-16 as a feature extractor'''
  
  feature_model = applications.VGG16(weights='imagenet', include_top=False, input_shape=(img_rows, img_cols, 3))
  #get the model summary
  feature_model.summary()
  #extract feature from the intermediate layer
  feature_model = Model(input=feature_model.input, output=feature_model.get_layer('block5_conv2').output) 
  #get the model summary
  feature_model.summary()
  
  #declaring image data generators
  
  train_datagen = ImageDataGenerator()
  val_datagen = ImageDataGenerator()
  
  generator = train_datagen.flow_from_directory(
          'f1_100/train',
          target_size=(img_rows, img_cols),
          batch_size=batch_size,
          class_mode=None,  
          shuffle=False)  
  
  train_data = feature_model.predict_generator(generator, 1000)
  train_labels = np.array([[1, 0]] * 500 + [[0, 1]] * 500)
  
  generator = val_datagen.flow_from_directory(
          'f1_100/test',
          target_size=(img_rows, img_cols),
          batch_size=batch_size,
          class_mode=None,
          shuffle=False)
  
  validation_data = feature_model.predict_generator(generator, 200)
  validation_labels = np.array([[1,0]] * 100 + [[0,1]] * 100)
  
  ###############################################################################
  #addding the top layers and training them on the extracted features
  from keras.models import Sequential
  
  model = Sequential()
  model.add(Flatten(input_shape=train_data.shape[1:]))
  model.add(Dense(1024, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(2, activation='softmax'))
  
  sgd = SGD(lr=0.0001, decay=1e-6, momentum=0.9, nesterov=True)
  model.compile(optimizer=sgd,
                loss='categorical_crossentropy',
                metrics=['accuracy'])
  print('-'*30)
  print('Start Training the top layers on the extracted features...')
  print('-'*30)
  
  #measure the time and train the model
  t=time.time() 
  hist = model.fit(train_data, train_labels, nb_epoch=nb_epoch, batch_size=batch_size,
                        validation_data=(validation_data, validation_labels),
                        verbose=2)
  #print the history of the trained model
  print(hist.history)
  print('Training time: %s' % (time.time()-t))
  ###############################################################################
  </code></pre>
  
  <p>However, on running the code, I'm getting the following error:</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-14-cc5b1b34cc67&gt;", line 46, in &lt;module&gt;
      verbose=2)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\models.py", line 960, in fit
      validation_steps=validation_steps)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 1581, in fit
      batch_size=batch_size)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 1426, in _standardize_user_data
      _check_array_lengths(x, y, sample_weights)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 250, in _check_array_lengths
      'and ' + str(list(set_y)[0]) + ' target samples.')
  
  ValueError: Input arrays should have the same number of samples as target arrays. Found 10000 input samples and 1000 target samples.
  </code></pre>