title: Create a mixed data generator (images,csv) in keras
body: <p>I am building a model with multiple inputs as shown in <a href="https://www.pyimagesearch.com/2019/02/04/keras-multiple-inputs-and-mixed-data/" rel="noreferrer">pyimagesearch</a>, however I can't load all images into RAM and I am trying to create a generator that uses <code>flow_from_directory</code> and get from a CSV file all the extra attributes for each image being processed.</p>
  
  <p><strong>Question:</strong> How do I get the attributes from the CSV to correspond with the images in each batch from the image generator?</p>
  
  <pre><code>def get_combined_generator(images_dir, csv_dir, split, *args):
      """
      Creates train/val generators on images and csv data.
  
      Arguments:
  
      images_dir : string
          Path to a directory with subdirectories for each class.
  
      csv_dir : string
          Path to a directory containing train/val csv files with extra attributes.
  
      split : string
          Current split being used (train, val or test)
      """
      img_width, img_height, batch_size = args
  
      datagen = ImageDataGenerator(
          rescale=1. / 255)
  
      generator = datagen.flow_from_directory(
          f'{images_dir}/{split}',
          target_size=(img_width, img_height),
          batch_size=batch_size,
          shuffle=True,
          class_mode='categorical')
  
      df = pd.read_csv(f'{csv_dir}/{split}.csv', index_col='image')
  
      def my_generator(image_gen, data):
          while True:
              i = image_gen.batch_index
              batch = image_gen.batch_size
              row = data[i * batch:(i + 1) * batch]
              images, labels = image_gen.next()
              yield [images, row], labels
  
      csv_generator = my_generator(generator, df)
  
      return csv_generator
  </code></pre>