title: Keras training is slow when using ImageDataGenerator
body: <p>So I just got started using Keras, I first tried the MNIST dataset, and everything was quick 5 epoch in only few seconds (60k images). </p>
  
  <p>Now I'm trying to train a CNN on a car dataset that has around 8000 image, I used ImageDataGenerator to resize the image into the same size (128 * 128) and to get it from a dataframe that has the filename and the class name for each image, here is the part responsible for this:</p>
  
  <pre><code>datagen=ImageDataGenerator(validation_split=0.2)
  train_generator = datagen.flow_from_dataframe(dataframe=df_train, directory="cars/cars_train/cars_train/", x_col="fname", y_col="class_name", class_mode="categorical", target_size=(128,128), batch_size=32,subset="training")
  test_generator = datagen.flow_from_dataframe(dataframe=df_train, directory="cars/cars_train/cars_train/", x_col="fname", y_col="class_name", class_mode="categorical", target_size=(128,128), batch_size=32,subset="validation")
  </code></pre>
  
  <p>As you can see I'm not doing anything intensive except resizing the dataset.
  When I use <code>model.fit</code> on the ImageDataGenerator, the first epoch take around 2800 seconds to finish and the other epoch take around 60 - 70 second only (1 minute). The NN is not complicated, it's only 2 convolutional layers + one dense layer.</p>
  
  <pre><code>nb_epochs = 4
  bs = 32
  model.fit(
      train_generator,
      steps_per_epoch = train_generator.samples//bs,
      validation_data = test_generator, 
      validation_steps = test_generator.samples//bs,
      epochs = nb_epochs)
  </code></pre>
  
  <p>I would like to know if it's normal that using ImageDataGenerator, training the network is slow especially on the first epoch ? If so is there a faster more efficient way to resize images and preprocess them before training the network ? </p>
  
  <p>Btw, I'm using Google Colab, and I enabled the GPU and checked that tensorflow is using the GPU </p>
  
  <p>Here's the link for the notebook, it's quite messy, I'm sorry: <a href="https://colab.research.google.com/drive/1FqPeqIhKo_lUjhoB2jlne1HnwItOJkIW?usp=sharing" rel="nofollow noreferrer">https://colab.research.google.com/drive/1FqPeqIhKo_lUjhoB2jlne1HnwItOJkIW?usp=sharing</a></p>