title: Keras: flow_from_directory saving too many images during fit_generator call
body: <p>I have the following train/validation code:</p>
  
  
  
  <pre class="lang-python prettyprint-override"><code># we create two instances with the same arguments
  image_data_gen_args         = dict(rotation_range=90.0, rescale=1/255.0)
  mask_data_gen_args          = dict(rotation_range=90.0, rescale=1/255.0)
  train_image_datagen         = ImageDataGenerator(**image_data_gen_args)
  train_mask_datagen          = ImageDataGenerator(**mask_data_gen_args)
  validation_image_datagen    = ImageDataGenerator()
  validation_mask_datagen     = ImageDataGenerator(**mask_data_gen_args)
  
  # Provide the same seed flow methods
  seed = 1
  
  train_image_generator = train_image_datagen.flow_from_directory(
      abs_parent_train_images_path,
      class_mode=None,
      seed=seed,
      follow_links=True, # we symlinked the images to a temp directory
      batch_size=1,
      shuffle=True,
      target_size=(image_size, image_size))
  
  train_mask_generator = train_mask_datagen.flow_from_directory(
      abs_parent_train_masks_path,
      class_mode=None,
      seed=seed,
      batch_size=1,
      shuffle=True,
      target_size=(image_size, image_size),
      color_mode="grayscale",
      save_to_dir=abs_parent_train_masks_path)
  
  validation_image_generator = validation_image_datagen.flow_from_directory(
      abs_parent_test_images_path,
      class_mode=None,
      seed=seed,
      follow_links=True,  # we symlinked the images to a temp directory
      batch_size=1,
      shuffle=True,
      target_size=(image_size, image_size))
  
  validation_mask_generator = validation_mask_datagen.flow_from_directory(
      abs_parent_test_masks_path,
      class_mode=None,
      seed=seed,
      batch_size=1,
      shuffle=True,
      target_size=(image_size, image_size),
      color_mode="grayscale",
      save_to_dir=abs_parent_test_masks_path)
  
  # combine generators into one which yields image and masks
  train_generator         = itertools.izip(train_image_generator, train_mask_generator)
  validation_generator    = itertools.izip(validation_image_generator, validation_mask_generator)
  
  # test generators' saving
  for idx, pair in enumerate(validation_generator):
      print(idx)
      print('iterating')
      if idx &gt;= 0:
          break
  
  modeler.model.fit_generator(generator=train_generator,
                              steps_per_epoch=1,
                              validation_data=validation_generator,
                              validation_steps=1,
                              epochs=1,
                              callbacks=callbacks_list,
                              verbose=1)
  </code></pre>
  
  <p>The four train/validation directories either have 1 image or mask in the required <code>directory/subdirectory/image</code> organization for <code>flow_from_directory</code>.  So directory structure is believed not to be the issue.  This further confirmed by kera's printouts during training:</p>
  
  <pre class="lang-python prettyprint-override"><code>Found 1 images belonging to 1 classes.
  Found 1 images belonging to 1 classes.
  Found 1 images belonging to 1 classes.
  Found 1 images belonging to 1 classes.
  </code></pre>
  
  <p>I've noticed that <code>fit_generator</code> saves more than one image per train run.
  Since, <strong>epochs, steps_per_epoch, validation_steps and number of images/masks (for train/validation) all equal 1</strong>, I would have expected exactly <strong>one</strong> image to be saved during the call to <code>fit_generator</code>.  However, the number seems to be <strong>9</strong> (same image but each possessing a different rotation).</p>
  
  <p>Interestingly this seems to be a result of <code>fit_generator</code> and not the <code>ImageDataGenerator</code> class, since I can breakpoint just after the <code>for</code> loop iterating over <code>validation_generator</code> and find exactly one image saved per iteration of the <code>for</code> loop (as expected).</p>
  
  <p>Is there something that I'm doing wrong?
  Is this expected behavior (and why)?</p>
  
  <p>Thanks!</p>