How does data augmentation work in Keras?

Viewed 880

I have the following code to do data augmentation using my data in a list as input:

from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img import PIL

def augment(file_images_path, dir_save):

    datagen = ImageDataGenerator(rotation_range=40, width_shift_range=0.2, height_shift_range=0.2, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode='nearest')

    with open(file_images_path) as f:

       images_names = f.readlines()
       images_names = [x.strip() for x in images_names]
       for line in images_names:
           img=PIL.Image.open(line)             
           img=img.resize((28,28))                        
           x = img_to_array(img)                                                    
           x = x.reshape((1,) + x.shape)        
           # the .flow() command below generates batches of randomly transformed 
           #images and saves the results to the `dir_save` directory            
           i = 0            
           for batch in datagen.flow(x, batch_size=1, save_to_dir=dir_save, save_prefix='augmented', save_format='tif'):
                i += 1
                if i > 2:
                    break  # otherwise the generator would loop indefinitely

I am quite rookie in data augmentation in Keras and I want to know how many image operations does Keras perform on my images per iteration. For example, if I run this code on a list containing 14 images it will generate 126 augmented images. If I run it on a list containing 125 images, it will generate 370 augmented images. My question is: why?

1 Answers
Related