简体   繁体   English

Keras图像增强:如何选择“每个时期的步数”参数并在训练过程中包括特定的增强?

[英]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_generatorsteps_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.

相关问题 如何使用Keras生成器选择batch_size,steps_per_epoch和epoch - How to choose batch_size, steps_per_epoch and epoch with Keras generator fit_generator中的Keras steps_per_epoch如何工作 - How the Keras steps_per_epoch in fit_generator works 使用steps_per_epoch参数时,Keras的训练速度极慢 - Extremely slow training speed with Keras when using steps_per_epoch argument 如何在 tf.keras 训练期间获得当前时代的进度? - How to get progress of current epoch during tf.keras training? 如何在 Keras 中正确设置 steps_per_epoch 和 validation_steps? - How to properly set steps_per_epoch and validation_steps in Keras? Keras model.fit()引发关于未指定参数`steps_per_epoch`的错误 - Keras model.fit() Raises Error About Unspecified Parameter `steps_per_epoch` Keras 中 LSTM 模型训练的 epoch 中步数的重要性 - Importance of number of steps in an epoch for LSTM model training in Keras Keras 2 fit_generator UserWarning:`steps_per_epoch`与Keras 1参数`samples_per_epoch`不同 - Keras 2 fit_generator UserWarning: `steps_per_epoch` is not the same as the Keras 1 argument `samples_per_epoch` 如何在 Keras 中使用 fit_generator plot steps_per_epoch 防止损失? - How do I plot steps_per_epoch against loss using fit_generator in Keras? Keras:Plot 使用 flow_from_directory 训练数据的图像增强样本 - Keras: Plot Image augmentations samples for training data using flow_from_directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM