步骤_per_epoch和纪元的设置如何影响Keras的训练结果? [英] How dose the setting of steps_per_epoch and epochs affect the training result in Keras?
问题描述
我的生成器总是从我的数据集中随机产生两个图像,然后我使用这两个样本来计算损失.假设我设置了steps_per_epoch=40
和epochs=5
,如果设置了steps_per_epoch=5
和epochs=40
(我在优化程序中使用Adam)有什么区别?
epochs
参数(也称为迭代)是指整个训练数据的通过次数. steps_per_epoch
参数是指一个时期内生成的批处理数.因此,我们有steps_per_epoch = n_samples / batch_size
.
例如,如果我们有1000个训练样本并将批次大小设置为10,则我们有steps_per_epoch = 1000 / 10 = 100
.可以设置epochs
,而与批处理大小或steps_per_epoch
的值无关.
没有适用于所有方案的批处理大小的确定值.通常,非常大的批处理量会减慢训练过程(即模型收敛到解决方案需要更多时间),非常小的批处理量可能并不能很好地利用可用资源(例如GPU和CPU) .通常的值包括32、64、128、256、512(2的幂可以帮助更快地分配GPU内存).另外,这是关于SO的答案,该问题与该问题有关,其中包括对相关书籍和论文的引用.或查看此问题及其在Cross Validated上的答案,以获取更完整的批量大小定义. /p>
My generator always yields two images from my dataset randomly and then I calculate the loss using this two samples. Say I set steps_per_epoch=40
and epochs=5
, what's the difference if I set steps_per_epoch=5
and epochs=40
(I use Adam for my optimizer)?
The epochs
argument (also called iteration) refers to the number of full passes over the whole training data. The steps_per_epoch
argument refers to the number of batches generated during one epoch. Therefore we have steps_per_epoch = n_samples / batch_size
.
For example, if we have 1000 training samples and we set batch-size to 10 then we have steps_per_epoch = 1000 / 10 = 100
. The epochs
can be set regardless of the value of batch-size or steps_per_epoch
.
There is no definite value of batch-size that works for all the scenarios. Usually, a very large batch-size slows down the training process (i.e. it takes more time for the model to converge to a solution) and a very small batch-size may not be a good use of available resources (i.e. GPU and CPU). The usual values include 32, 64, 128, 256, 512 (powers of 2 helps with faster GPU memory allocations). Also, here is an answer on SO that concerns this issue which includes citations of relevant books and papers. Or take a look at this question and its answers on Cross Validated for a more complete definition of batch-size.
这篇关于步骤_per_epoch和纪元的设置如何影响Keras的训练结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!