0
$\begingroup$

Is there any way to know the number of images generated by the ImageDataGenerator class and loading data using flow_from_directory method? I searched everywhere for the same but couldn't find anything useful.

Also, if I use image_dataset_from_directory fuction, I have to include data augmentation layers as a part of the model. In that case, how many images are generated?

My ImageDataGenerator code:

train_datagen = ImageDataGenerator(rescale=1./255,
                                   horizontal_flip=True,
                                   zoom_range=0.2,
                                   shear_range=0.2,
                                   rotation_range=15,
                                   fill_mode='nearest')

My code with data augmentation as a part of the model:

data_aug = Sequential([
                         layers.experimental.preprocessing.Rescaling(1./255),
                         layers.experimental.preprocessing.RandomFlip('horizontal'),
                         layers.experimental.preprocessing.RandomZoom(0.2,0.2),
                         layers.experimental.preprocessing.RandomRotation(0.06)
])



# in the model:

input_layer = layers.Input(shape=(150, 150, 3))
x = data_aug(input_layer)
$\endgroup$

1 Answer 1

2
$\begingroup$

In one epoch - It's the number of images in your Directory or the DataFrame
In case of a custom Generator. It will be batch_size * steps_per_epoch

You may check this with any of these approaches -

  • Check the shape of prediction on train model.predict(traindata).shape
  • Save the images into a dir by using save_to_dir='/content/train_data'
  • Write a callback for batch_end
  • Get the steps_per_epoch in the training print statement i.e.
    125/125 [==============================] - 50s 392ms/step - loss: 0.6637 - accuracy: 0.6000
$\endgroup$
1
  • $\begingroup$ Thanks for the info. Is this the same when "image_dataset_from_directory" is used? $\endgroup$ Mar 15, 2021 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.