python - Keras ImageDataGenerator 中的增强

标签 python tensorflow keras conv-neural-network

我有两个关于 ImageDataGenerator 的问题:

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

2) ImageDataGenerator.flow 中的数据无限循环(批量)。有没有办法停止这个无限循环,即只进行 n 次扩充。因为我需要在每个步骤(而不是每个 epoch)中修改 batch_size。 谢谢

最佳答案

来自 Francois Chollet 的回答:

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) 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=... 以仅从生成器中生成特定数量的样本。如果你想要批级粒度,你可以这样做:

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

在这种情况下,您可以在任意数量的批处理之后break(这是一个循环)。

关于python - Keras ImageDataGenerator 中的增强,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40737870/

相关文章:

python - 使用 groupby 获取组中具有最大值的行

python - 用于实时 appengine 项目的基于浏览器的交互式控制台的 url 是什么?

python - 比较 Conv2D 与 Tensorflow 和 PyTorch 之间的填充

python - 如何在没有模型的情况下读取keras模型权重

python - 更改日期列中的刻度数

python - mac os 上的 cython 入门

Tensorflow:get_tensor_by_name 与 get_operation_by_name 的区别?

python - TensorFlow 上的 MLP 对训练后的所有观察结果给出相同的预测

Keras,暹罗网络,如何抽象特征?

python - 如何将训练数据分成更小的批处理来解决内存错误