title: Keras warning: Epoch comprised more than `samples_per_epoch` samples
body: <p>I have about 6200 training images and I  want to use the <code>flow(X, y)</code> method of the <code>keras.preprocessing.image.ImageDataGenerator</code> class to augment the small dataset in the following way:</p>
  
  <pre><code>train_datagen = ImageDataGenerator(
          rescale=1./255,
          shear_range=0.2,
          zoom_range=0.2,
          horizontal_flip=True)
  
  test_datagen = ImageDataGenerator(rescale=1./255)
  
  train_generator = train_datagen.flow(X_train , y_train)
  
  validation_generator = test_datagen.flow(X_val , y_val)
  
  history = model.fit_generator(
          train_generator,
          samples_per_epoch=1920,
          nb_epoch=10,
          verbose=1,
          validation_data=validation_generator,
          nb_val_samples=800)
  </code></pre>
  
  <p>where <code>X_train</code> / <code>y_train</code> contain about 6000 training images and labels and <code>X_val</code> / <code>y_val</code> the validation data and model is an augmented VGG16 model.</p>
  
  <p>The documentation says</p>
  
  <blockquote>
    <p>flow(X, y): Takes numpy data &amp; label arrays, and generates batches of augmented/normalized data. Yields batches indefinitely, in an infinite loop.</p>
  </blockquote>
  
  <p>For a training setup with 10 epochs, 1920 samples per epoch and a batch_size of 32 I got the following training trace:</p>
  
  <pre><code>1920/1920 [==============================] - 3525s - loss: 3.9101 - val_loss: 0.0269
  Epoch 2/10
  1920/1920 [==============================] - 3609s - loss: 1.0245 - val_loss: 0.0229
  Epoch 3/10
  1920/1920 [==============================] - 3201s - loss: 0.7620 - val_loss: 0.0161
  Epoch 4/10
  1916/1920 [============================&gt;.] - ETA: 4s - loss: 0.5978 C:\Miniconda3\envs\carnd-term1\lib\site-packages\keras\engine\training.py:1537: UserWarning: Epoch comprised more than `samples_per_epoch` samples, which might affect learning results. Set `samples_per_epoch` correctly to avoid this warning.
    warnings.warn('Epoch comprised more than 
  </code></pre>
  
  <p>Why didnt the generator generate infinite batches as the documentation says?</p>