在Keras中使用earlystoping回调时如何获得最佳模型?

2024-05-11 05:59:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用基于{}和{}的{}使用Keras训练神经网络EarlyStoppingval_acc减少时立即停止训练

然而,我得到的最终模型并不是最好的模型,即具有最高val_acc的模型。但是我有一个对应于后一个纪元的模型,也就是对应于aval_acc的模型,它比最好的模型稍微低一点,这导致了提前停止

我怎样才能买到最好的

我尝试使用“保存最佳模型”并使用回拨:

ModelCheckpoint(filepath='best_model.h5', monitor='val_loss', save_best_only=True)]

但我得到了同样的结果


Tags: 模型model神经网络valmonitorkerasaccbest
2条回答

如果要保存最高精度,则应设置检查点monitor='val_acc',它将在最高精度时自动保存。最低的损失未必对应最高的准确度。您还可以设置verbose=1以查看保存的是哪个模型以及保存的原因

Keras 2.2.3中,为^{}回调引入了一个名为restore_best_weights的新参数,如果设置为True(默认为False),它将从具有最佳监控量的历元恢复权重:

restore_best_weights: whether to restore model weights from the epoch with the best value of the monitored quantity. If False, the model weights obtained at the last step of training are used.

相关问题 更多 >