[英]Keras image augmentation: How to choose “steps per epoch” parameter and include specific augmentations during training?
I am training an image classification CNN using Keras. 我正在使用Keras训练图像分类CNN。 Using the ImageDataGenerator
function, I apply some random transformations to the training images (eg rotation, shearing, zooming). 使用ImageDataGenerator
函数,我对训练图像进行了一些随机变换(例如旋转,剪切,缩放)。 My understanding is, that these transformations are applied randomly to each image before passed to the model. 我的理解是,这些变换在传递给模型之前会随机应用于每个图像。
But some things are not clear to me: 但是有些事情我不清楚:
1) How can I make sure that specific rotations of an image (eg 90°, 180°, 270°) are ALL included while training. 1)在训练过程中,如何确定图像的所有特定旋转角度(例如90°,180°,270°)都包括在内。
2) The steps_per_epoch
parameter of model.fit_generator
should be set to the number of unique samples of the dataset divided by the batch size define in the flow_from_directory
method. 2)应该将model.fit_generator
的steps_per_epoch
参数设置为数据集的唯一样本数除以flow_from_directory
方法中定义的批量大小。 Does this still apply when using the above mentioned image augmentation methods, since they increase the number of training images? 当使用上述图像增强方法时,由于它们会增加训练图像的数量,这仍然适用吗?
Thanks, Mario 谢谢,马里奥
Some time ago I raised myself the same questions and I think a possible explanation is here: 不久前,我对自己提出了同样的问题,我认为可能的解释在这里:
Consider this example: 考虑以下示例:
aug = ImageDataGenerator(rotation_range=90, width_shift_range=0.1,
height_shift_range=0.1, shear_range=0.2,
zoom_range=0.2, horizontal_flip=True,
fill_mode="nearest")
For question 1): I specify a rotation_range=90, which means that while you flow (retrieve) the data, the generator will randomly rotate the image by a degree between 0 and 90 deg. 对于问题1):我指定了rotation_range = 90,这意味着在您流传输(检索)数据时,生成器将以0到90度之间的角度随机旋转图像。 You can not specify an exact angle cause that's what ImageDataGenerator does: generate randomly the rotation. 您无法指定ImageDataGenerator所做的确切角度原因:随机生成旋转。 It is also very important concerning your second question. 关于您的第二个问题,这也非常重要。
For question 2): Yes it still applies to the data augmentation method. 对于问题2):是的,它仍然适用于数据扩充方法。 I was also confused in the beginning. 一开始我也很困惑。 The reason is that since the image is generated randomly , for each epoch, the network sees the images all different from those in previous epoch. 原因是由于图像是随机生成的,因此对于每个时期,网络看到的图像都与前一个时期不同。 That's why the data is "augmented" - the augmentation is not done within an epoch, but throughout the entire training process. 这就是为什么数据被“扩充”的原因-扩充不是在一个时代内完成的,而是在整个训练过程中完成的。 However, I have seen other people specifying 2x value of the original steps_per_epoch. 但是,我看到其他人指定了原始steps_per_epoch的2x值。
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.