问题描述
我正在使用预先训练的VGG-16模型进行图像分类.我要添加自定义的最后一层,因为我的分类类别数是10.我正在训练200个时代的模型.
I am using pre-trained VGG-16 model for image classification. I am adding custom last layer as the number of my classification classes are 10. I am training the model for 200 epochs.
我的问题是:如果我在某个时期随机停止(通过关闭python窗口)培训,有什么办法,比如说时期否. 50,然后从那里继续?我已经阅读过有关保存和重新加载模型的信息,但是我的理解是,该模型仅适用于我们的自定义模型,而不适用于像VGG-16这样的预训练模型.
My question is: is there any way if I randomly stop (by closing python window) the training at some epoch, let's say epoch no. 50 and resume from there? I have read about saving and reloading model but my understanding is that works for our custom models only instead of pre-trained models like VGG-16.
推荐答案
您可以使用 ModelCheckpoint
回调以定期保存模型.要使用它,请将callbacks
参数传递给fit
方法:
You can use ModelCheckpoint
callback to save your model regularly. To use it, pass a callbacks
parameter to the fit
method:
from keras.callbacks import ModelCheckpoint
checkpointer = ModelCheckpoint(filepath='model-{epoch:02d}.hdf5', ...)
model.fit(..., callbacks=[checkpointer])
然后,稍后您可以加载最后保存的模型.有关此回调的更多自定义信息,请查看文档.
Then, later you can load the last saved model. For more customization of this callback take a look at the documentation.
这篇关于停止并重新开始VGG-16的培训的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!