如何确定Keras中增强图像的数量? [英] How to determine amount of augmented images in Keras?

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

问题描述

我正在使用Keras 2.0.0,我想在GPU上训练带有大量参数的深度模型. 由于数据很大,因此必须使用ImageDataGenerator.老实说,我想滥用ImageDataGenerator,即我不想执行任何扩充操作.我只想将训练图像成批放置(并重新缩放),因此可以将它们输入model.fit_generator.

我改写了此处中的代码,并根据我的数据进行了一些小的更改(即将二进制分类更改为分类.但这与该问题无关,应在此处进行讨论). 我有15000张火车图像,并且我要执行的唯一增强"操作是按train_datagen = ImageDataGenerator(rescale=1./255)将比例缩放为[0,1]. 创建完我的"train_generator"之后:

train_generator = train_datagen.flow_from_directory(
    train_data_dir,
    target_size=(img_width, img_height),
    batch_size=batch_size,
    class_mode='categorical',
    shuffle = True,
    seed = 1337,
    save_to_dir = save_data_dir)

我使用model.fit_generator()拟合模型.

我将纪元数设置为:epochs = 1 并将batch_size更改为:batch_size = 60

我希望在存储我的扩展(即调整大小)图像的目录中看到的内容:每个时期15.000个重新缩放的图像,即只有一个时期:15.000个重新缩放的图像.但是,奇怪的是,有15.250张图像.

有这么多图像的原因吗? 我可以控制放大图像的数量吗?

类似的问题:

模型fit_generator不能按预期提取数据样本(分别在stackoverflow: Keras-在fit_generator()中如何使用批次和纪元?)

将数据生成器用于大型数据集(例如ImageNet)的具体示例

感谢您的帮助.

解决方案

如果您的要求是在训练时传输数据,则以下链接对您很有用,其中作者为imageDataGenerator编写并很好地解释了脚本.您可以在其上添加更多功能,例如重新缩放等,并完全控制数据生成.

https://stanford. edu/〜shervine/blog/keras如何即时生成数据

I am working with Keras 2.0.0 and I'd like to train a deep model with a huge amount of parameters on a GPU. As my data are big, I have to use the ImageDataGenerator. To be honest, I want to abuse the ImageDataGenerator in that sense, that I don't want to perform any augmentations. I just want to put my training images into batches (and rescale them), so I can feed them to model.fit_generator.

I adapted the code from here and did some small changes according to my data (i.e. changing binary classification to categorical. But this doesn't matter for this problem which should be discussed here). I have 15000 train images and the only 'augmentation' I want to perform, is rescaling to scope [0,1] by train_datagen = ImageDataGenerator(rescale=1./255). After creating my 'train_generator' :

train_generator = train_datagen.flow_from_directory(
    train_data_dir,
    target_size=(img_width, img_height),
    batch_size=batch_size,
    class_mode='categorical',
    shuffle = True,
    seed = 1337,
    save_to_dir = save_data_dir)

I fit the model by using model.fit_generator().

I set amount of epochs to: epochs = 1 And batch_size to: batch_size = 60

What I expect to see in the directory where my augmented (i.e. resized) images are stored: 15.000 rescaled images per epoch, i.e. with only one epoch: 15.000 rescaled images. But, mysteriously, there are 15.250 images.

Is there a reason for this amount of images? Do I have the power to control the amount of augmented images?

Similar problems:

Model fit_generator not pulling data samples as expected (respectively at stackoverflow: Keras - How are batches and epochs used in fit_generator()?)

A concrete example for using data generator for large datasets such as ImageNet

I appreciate your help.

解决方案

If your requirement is to flow the data, while training, the following link will be useful for you, where author has written and explained the script for imageDataGenerator very nicely. You can add further functionality to it like rescaling and others with full control on the data-generation.

https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly

这篇关于如何确定Keras中增强图像的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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