How can I know the number of the training images after data augmentation in Keras?

1,669 views
Skip to first unread message

Nad

unread,
Sep 13, 2018, 5:47:45 AM9/13/18
to Keras-users
Hello..

I am using data augmentation in my CNN model, and I would like to know the number of the training images after augmentation.

Is there a way to calculate the number of training images after augmentation in Keras?

Thanks

Sergey O.

unread,
Sep 13, 2018, 6:12:29 AM9/13/18
to Nad, Keras-users
Assuming you are using Keras' "ImageDataGenerator" it generates batches with real-time data augmentation. In other words, it will generate (number of images in your training set) * ( number of epochs specified during fit).
Message has been deleted

Nad

unread,
Sep 13, 2018, 7:38:47 AM9/13/18
to Keras-users
Thank you so much for replying.. I noticed that when I change  ImageDataGenerator arguments the results of the CNN model is changed. So, I would like to know how does the data augmentation affect the results??? Does the number of the images after augmentation affect the results?!!

Each on of the following ImageDataGenerator method gives different results:

1- 
train_datagen = ImageDataGenerator(
      rescale=1./255,
      rotation_range=20,
      width_shift_range=0.2,
      height_shift_range=0.2,
      horizontal_flip=True,
      fill_mode='nearest')

validation_datagen = ImageDataGenerator(rescale=1./255)

---

2- 
train_datagen = ImageDataGenerator(
rotation_range=15,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.5,
horizontal_flip=True,
fill_mode='nearest')

validation_datagen = ImageDataGenerator()
-- 

3- 
train_datagen = ImageDataGenerator(
      rescale=1./255,
      rotation_range=20,
      width_shift_range=0.2,
      height_shift_range=0.2,
      horizontal_flip=True,
      fill_mode='nearest')

validation_datagen = ImageDataGenerator()

Sergey O.

unread,
Sep 13, 2018, 8:46:01 AM9/13/18
to Nad, Keras-users
Yes, different arguments will give different results. Even with the same arguments, each time you run, you should get different results. The generator randomly samples from the range specified.

Depending on your problem, you may want to modify which augmentations and their ranges are sampled. The idea is to make the NN robust, so that if it later sees a slightly rotated, or scaled, or horizontally flipped version of your image it would still be able to classify it correctly.

By number of images, I'm guessing you mean number of epochs? If so, that should also effect the results. The more images, the better!

Both training and image generation is a stocastic process. This is important to prevent over fitting, making NN robust and also to prevent your optimizer from getting stuck in a local minimum. 

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/3c5b6217-ba65-4471-afa6-62d00cfc218a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nad

unread,
Sep 13, 2018, 11:46:59 AM9/13/18
to Keras-users
Thank you so much for this info.
Reply all
Reply to author
Forward
0 new messages