How to find how many Image Generated By ImageDataGenerator

强颜欢笑 提交于 2020-07-17 05:50:49

问题


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)

回答1:


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



来源:https://stackoverflow.com/questions/48003732/how-to-find-how-many-image-generated-by-imagedatagenerator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!