How dose the setting of steps_per_epoch and epochs affect the training result in Keras?

我只是一个虾纸丫 提交于 2019-12-13 05:26:51

问题


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)?


回答1:


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.



来源:https://stackoverflow.com/questions/51549588/how-dose-the-setting-of-steps-per-epoch-and-epochs-affect-the-training-result-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!