如何查找ImageDataGenerator生成了多少张图片

12

嗨,我想问一下有关Keras ImageDataGenerator的问题。我能确定会创建多少增强图像吗?或者如何在数据增强后找到训练图像集大小。在Keras文档中,流函数的描述为:“接收numpy数据和标签数组,并生成批量的增强/规范化数据。无限循环地产生批次。”但是会生成多少图像呢?

例如,以下代码将生成多少图像?无限个吗?

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)

在这里回答了关于steps_per_epoch * batch_size的问题 https://dev59.com/8Krka4cB1Zd3GeqPfYsZ#49784152?noredirect=1#comment86584555_49784152 - Adrian
嗨,Adrain。我知道你的意思,但问题是生成器在生成过程中有多少变化。 - Benchur Wong
我已经得到了关于这个问题的提示。 - Benchur Wong
1个回答

2
您说得没错,您可以从一张图像生成无限多个数字。实际上这是正常的,考虑一下通过旋转初始图像可以生成的图像数量,它是无限的,因为对于每个旋转角度值,您都可以生成一个不同的图像。为了证实这一点,我将展示来自 Keras文档 的以下代码。
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

请注意,他们说生成器无限循环,这证实了生成了无限数量的图像。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接