在Keras中使用EarlyStopping回调时如何获得最佳模型? [英] How to get the best model when using EarlyStopping callback in Keras?
问题描述
我正在使用基于val_acc
和patience=0
的EarlyStopping
用Keras训练神经网络. EarlyStopping
降低后,EarlyStopping
就会停止训练.
I am training a neural network with Keras using EarlyStopping
based on val_acc
and patience=0
. EarlyStopping
stops the training as soon as val_acc
decreases.
但是,我获得的最终模型不是最佳模型,即具有最高val_acc
的模型.但是我宁愿有一个对应于后一个时期的模型,即对应于val_acc
的那个模型仅比最佳模型低一点,从而导致提早停止!
However the final model that I obtain is not the best model, namely the one with the highest val_acc
. But I rather have the model corresponding to the epoch after, namely the one corresponding to a val_acc
just a bit lower than the best one and that caused the early stopping!
我如何获得最好的?
我尝试通过回叫使用保存最佳模型:
I tried to use the save the best model using the call back:
ModelCheckpoint(filepath='best_model.h5', monitor='val_loss', save_best_only=True)]
但是我得到相同的结果.
But I get the same results.
推荐答案
如果要保存最高准确度,则应将检查点monitor='val_acc'
设置为自动保存在最高点.最低的损耗不一定与最高的精度相对应.您还可以设置verbose=1
来查看要保存的模型以及原因.
If you would like to save the highest accuracy then you should set the checkpoint monitor='val_acc'
it will automatically save on highest. Lowest loss might not necessarily correspond to highest accuracy. You can also set verbose=1
to see which model is being saved and why.
这篇关于在Keras中使用EarlyStopping回调时如何获得最佳模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!