如何查找ImageDataGenerator生成的图像数量 [英] How to find how many Image Generated By ImageDataGenerator

查看:696
本文介绍了如何查找ImageDataGenerator生成的图像数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问你一个关于Keras ImageDataGenerator的问题。我可以确定将创建多少张增强图像吗?在Keras文档中,流程函数描述为:获取numpy数据和标签数组,并生成一批增强/归一化的数据。无限期无限次地产生批次。但是生成了多少图像?

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)


推荐答案

您所说的是正确的,您可以从一张图像生成无限个数字。实际上,这是正常现象,仅考虑可通过初始旋转生成的图像数量是无限的,因为对于每个旋转角度值,您都可以生成不同的图像。为了确认这一点,我将显示 keras文档

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

这篇关于如何查找ImageDataGenerator生成的图像数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆