我有两个关于 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/