Keras中的initial_epoch是什么意思? [英] What does initial_epoch in Keras mean?
问题描述
对于fit
和fit_generator
方法中的initial_epoch
值,我有些困惑.这是文档:
I'm a little bit confused about initial_epoch
value in fit
and fit_generator
methods. Here is the doc:
initial_epoch :整数.开始训练的时期(用于恢复以前的训练运行).
initial_epoch: Integer. Epoch at which to start training (useful for resuming a previous training run).
我了解,如果您从头开始训练,这没有用.如果您训练了数据集并希望提高准确性或其他值(如果我错了,请纠正我),这将非常有用.但是我不确定它的真正作用.
I understand, it is not useful if you start training from scratch. It is useful if you trained your dataset and want to improve accuracy or other values (correct me if I'm wrong). But I'm not sure what it really does.
所以毕竟,我有两个问题:
So after all this, I have 2 questions:
-
initial_epoch
的作用是什么? -
何时可以使用
initial_epoch
?
- What does
initial_epoch
do and what is it for? When can I use
initial_epoch
?
- 当我更改数据集时?
- 当我更改学习率,优化器或损失函数时?
- 他们两个?
推荐答案
由于在某些优化程序中,其某些内部值(例如学习率)是使用 current epoch
值设置的,甚至您可能有(自定义)回调,具体取决于当前值 epoch
,initial_epoch
参数使您可以指定训练时从其开始的epoch
初始值.
Since in some of the optimizers, some of their internal values (e.g. learning rate) are set using the current epoch
value, or even you may have (custom) callbacks that depend on the current value of epoch
, the initial_epoch
argument let you specify the initial value of epoch
to start from when training.
如文档中所述,这在您对模型进行了某些时期训练(例如10次),然后将其保存后又现在想要加载它并继续进行另外10个时期的训练时最有用.时代相关对象(例如优化程序)的状态.因此,您将设置initial_epoch=10
(即我们已经训练了10个时期的模型)和epochs=20
(不是10,因为要达到的时期总数是20),然后一切恢复了,就好像您最初是针对模型进行了训练一次培训中有20个纪元.
As stated in the documentation, this is mostly useful when you have trained your model for some epochs, say 10, and then saved it and now you want to load it and resume the training for another 10 epochs without disrupting the state of epoch-dependent objects (e.g. optimizer). So you would set initial_epoch=10
(i.e. we have trained the model for 10 epochs) and epochs=20
(not 10, since the total number of epochs to reach is 20) and then everything resume as if you were initially trained the model for 20 epochs in one single training session.
但是,请注意,当使用Keras的内置优化器时,您无需使用
However, note that when using built-in optimizers of Keras you don't need to use initial_epoch
, since they store and update their state internally (without considering the value of current epoch) and also when saving a model the state of the optimizer will be stored as well.
这篇关于Keras中的initial_epoch是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!