简体   繁体   English

TensorFlow keras 模型 fit() 参数 steps_per_epoch 和训练集上的 epochs 行为

[英]TensorFlow keras model fit() parameters steps_per_epoch and epochs behavior on train set

I'm using a tf.data dataset containing my training data consisting of (lets say) 100k images.我正在使用一个 tf.data 数据集,其中包含我的训练数据,其中包含(比如说)100k 个图像。 I'm also using a tf.data dataset containing my validation set.我也在使用包含我的验证集的 tf.data 数据集。 Since an epoch of all 100k images takes quite long (in my case approximately one hour) before I get any feedback on performance on the validation set, I set the steps_per_epoch parameter in tf.keras.Model fit() to 10000 .由于所有 100k 图像的 epoch 需要很长时间(在我的情况下大约一小时)才能获得有关验证集性能的任何反馈,因此我将 tf.keras.Model fit()steps_per_epoch参数设置为10000 Using a batch size of 1 this results into having 10 validation scores when reaching 100k of images.使用 1 的批量大小会导致在达到 100k 图像时有 10 个验证分数。 In order to complete one epoch of 100k images of my entire training dataset, I set the epochs parameter to 10为了完成整个训练数据集的 10 万张图像的一个时期,我将epochs参数设置为10

However, I'm not sure if using steps_per_epoch and epochs this way has any other consequences.不过,我不知道,如果使用steps_per_epochepochs这样有什么其他后果。 Is it correct to use these parameters in order to get more frequent feedback on performance?使用这些参数以获得更频繁的性能反馈是否正确? And also a more specific question, does it use all 100k images or does it use the same first 10k images of my training set at every 'epoch'?还有一个更具体的问题,它是使用所有 100k 图像还是在每个“时期”使用我的训练集的前 10k 图像? I already dug into the TensorFlow docs and read several different stack overflow questions, but I couldn't find anything conclusive to answer my own question.我已经深入研究了TensorFlow 文档并阅读了几个不同的堆栈溢出问题,但我找不到任何结论来回答我自己的问题。 Hope you can help!希望你能帮上忙!

Tensorflow version I'm using is 2.2.0.我使用的 Tensorflow 版本是 2.2.0。

Is it correct to use these parameters in order to get more frequent feedback on performance?使用这些参数以获得更频繁的性能反馈是否正确?

Yes, it is correct to use these parameters.是的,使用这些参数是正确的。 Here is the code that i used to fit the model.这是我用来拟合模型的代码。

model.fit(
train_data,
steps_per_epoch = train_samples//batch_size,
epochs = epochs,
validation_data = test_data,
verbose = 1,
validation_steps = test_samples//batch_size)

does it use all 100k images or does it use the same first 10k images of my training set at every 'epoch'?它是使用所有 100k 图像还是在每个“时期”使用我的训练集的前 10k 图像?

It use all images in your training data.它使用训练数据中的所有图像。

For better understanding Epoch is the number times the learning algorithm will work through the entire training data set.为了更好地理解Epoch是学习算法在整个训练数据集上工作的次数。

Where as steps_per_epoch is the total number of samples in your training data set divided by the batch size.其中, steps_per_epoch是训练数据集中的样本总数除以批量大小。

For example, if you have 100000 training samples and use a batch size of 100, one epoch will be equivalent to 1000 steps_per_epoch.例如,如果您有 100000 个训练样本并使用 100 的批量大小,则一个 epoch 将相当于 1000 个 steps_per_epoch。

Note: We generally observe batch size to be the power of 2, this is because of the effective work of optimized matrix operation libraries.注意:我们通常观察批量大小为 2 的幂,这是因为优化矩阵运算库的有效工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 fit_generator中的Keras steps_per_epoch如何工作 - How the Keras steps_per_epoch in fit_generator works Keras Sequence,fit_generator和steps_per_epoch - Keras Sequence, fit_generator and steps_per_epoch Keras model.fit()引发关于未指定参数`steps_per_epoch`的错误 - Keras model.fit() Raises Error About Unspecified Parameter `steps_per_epoch` 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` 仅使用batch_size 和仅使用steps_per_epoch 的Keras model.fit 之间的区别 - Difference between Keras model.fit using only batch_size and using only steps_per_epoch Keras Model 中无限数据集的 steps_per_epoch 和 validation_steps - steps_per_epoch and validation_steps for infinite Dataset in Keras Model Keras 适合:如果我的 steps_per_epoch 小于批次数怎么办? - Keras fit: What if my steps_per_epoch is fewer than the number of batches? 如何在 Keras 中使用 fit_generator plot steps_per_epoch 防止损失? - How do I plot steps_per_epoch against loss using fit_generator in Keras? 如何在 Keras 中正确设置 steps_per_epoch 和 validation_steps? - How to properly set steps_per_epoch and validation_steps in Keras? model.fit_generator 中的 steps_per_epoch 实际上在做什么? - What is steps_per_epoch in model.fit_generator actually doing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM