Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find how many Image Generated By ImageDataGenerator

Hi I want to ask you a question about Keras ImageDataGenerator. Can I determine how many augmented image will create? or how can find training image set size after augmentation.In Keras documentation flow function description is : "Takes numpy data & label arrays, and generates batches of augmented/normalized data. Yields batches indefinitely, in an infinite loop." But how many images generated ?

For example the following code how many image generates ? Infinite ?

from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
from matplotlib import pyplot
import numpy as np

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')
img=load_img('cat.1.jpg')
x=img_to_array(img)
x = x.reshape((1,) + x.shape) 
print x.shape
h=datagen.flow(x)
like image 418
hrzm Avatar asked Dec 28 '17 07:12

hrzm


People also ask

How many images are created in ImageDataGenerator?

Introducing the Dataset There are a total of 1646 unique images in the dataset. Since these are not a lot of images to create a robust neural network, it will act as a great dataset to test the potential of the ImageDataGenerator class!

What is batch size in ImageDataGenerator?

For example, if you have 1000 images in your dataset and the batch size is defined as 10. Then the "ImageDataGenerator" will produce 10 images in each iteration of the training. An iteration is defined as steps per epoch i.e. the total number of samples / batch_size.

What is Shear_range in ImageDataGenerator?

shear_range=0.2 means shear the image by 20%. zoom_range means zoom-in and zoom-out by 20%. For mirror reflection, I have given horizontal_flip=True . The most important argument of ImageDataGenerator is fill_mode . When your image shift by 20% there is some space left over.

What does flow_from_directory return?

the result is a batch_size number of images and their associated labels. Images will have the shape(batch_size, IMG_SHAPE, IMG_SHAPE, channels) and labels are shape (batch_size,1).


1 Answers

What you are saying is correct, you can generate an infinite number from one image. This is normal in fact, consider just the number of images you can generate by rotation from the intial, it is infinite, because for each value of rotation angle you can generate a different image. To confirm this I will show this code from keras documentation

for e in range(epochs):
    print('Epoch', e)
    batches = 0
    for x_batch, y_batch in datagen.flow(x_train, y_train, batch_size=32):
        model.fit(x_batch, y_batch)
        batches += 1
        if batches >= len(x_train) / 32:
            # we need to break the loop by hand because
            # the generator loops indefinitely
            break

Note that they are saying that the generator loops indifinitely, which confirms that an infinite amount of images is generated

like image 108
hola Avatar answered Sep 19 '22 16:09

hola