Keras ImageDataGenerator中的增强 [英] Augementations in Keras ImageDataGenerator

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

问题描述

我有两个关于ImageDataGenerator的问题:

I have please two questions concerning the ImageDataGenerator:

1)是否在整个批处理中使用了相同的增强,或者每个图像都有自己的随机变换? 例如为了旋转,模块是否以相同角度旋转批处理中的所有图像,或者每个图像都获得随机旋转角度?

1) Are the same augmentations used on the whole batch or each image gets its own random transformation? e.g. for rotation, does the module rotates all the images in the batch with same angle or each image get a random rotation angle ?

2)将ImageDataGenerator.flow中的数据无限期循环(成批循环).有没有一种方法可以停止此无限循环,即仅进行n次扩增.因为我需要在每个步骤(而不是每个时代)中修改batch_size. 谢谢

2) The data in ImageDataGenerator.flow is looped over (in batches) indefinitely. Is there a way to stop this infinite loop, i.e. doing the augmentation only for n number of time. Because I need to modify the batch_size in each step (not each epoch). Thanks

推荐答案

Francois Chollet 的答案:

Answer from Francois Chollet:

1)是否在整个批处理中使用了相同的增强,或者每个图像都有自己的随机变换?例如为了旋转,模块是否以相同角度旋转批处理中的所有图像,或者每个图像都获得随机旋转角度?

1) Are the same augmentations used on the whole batch or each image gets its own random transformation? e.g. for rotation, does the module rotates all the images in the batch with same angle or each image get a random rotation angle ?

每个单个样本都有不同的唯一变换(例如,在一定范围内随机旋转).

Every single sample has a different unique transformation (e.g. a random rotation within a certain range).

2)ImageDataGenerator.flow中的数据将无限期循环(成批循环).有没有一种方法可以停止此无限循环,即仅进行n次扩增.因为我需要在每个步骤(而不是每个时代)中修改batch_size.谢谢

2) The data in ImageDataGenerator.flow is looped over (in batches) indefinitely. Is there a way to stop this infinite loop, i.e. doing the augmentation only for n number of time. Because I need to modify the batch_size in each step (not each epoch). Thanks

不清楚这是什么意思.但是,如果使用的是model.fit_generator(ImageDataGenerator.flow()),则可以指定samples_per_epoch=...,以仅从生成器中生成特定数量的样本.如果要批处理级粒度,可以执行以下操作:

Unclear what is meant here. But if you are using model.fit_generator(ImageDataGenerator.flow()) then you can specify samples_per_epoch=... to only yield a specific number of samples from the generator. If you want batch-level granularity, you could do:

for x, y in model.fit_generator(ImageDataGenerator.flow()):
  model.train_on_batch(x, y)

在这种情况下,您可以在任意数量的批次之后进行break(这是一个循环).

In that case you can just break (it's a loop) after any number of batches that you want.

这篇关于Keras ImageDataGenerator中的增强的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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