Keras中的initial_epoch是什么意思? [英] What does initial_epoch in Keras mean?

查看:1536
本文介绍了Keras中的initial_epoch是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于fitfit_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:

  1. initial_epoch的作用是什么?
  2. 何时可以使用initial_epoch?

  1. What does initial_epoch do and what is it for?
  2. When can I use initial_epoch?

  • 当我更改数据集时?
  • 当我更改学习率,优化器或损失函数时?
  • 他们两个?

推荐答案

由于在某些优化程序中,其某些内部值(例如学习率)是使用 current epoch值设置的,甚至您可能有(自定义)回调,具体取决于当前值 epochinitial_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆