Keras: How to stop training with the lowest observed metric value?

折月煮酒 提交于 2019-12-13 09:47:20

问题


With Keras, I would like to stop the training at the epoch which returns the best (in most cases: lowest) observed metric (such as val_loss for example). I would not like to use the state of the network after the patience "ran out".

How can I do that?


回答1:


Well.... you can't really "stop" at the best accuracy, because you need to know the future values to decide if there will be better values!

But you can use another callback, the ModelCheckpoint, to save your model after each epoch.

You can pass the argument save_best_only so the model will only be saved when the monitored value (in your case 'val_loss') is better than the last saved model.

After training, you can load the saved model: keras.models.load_model(filepath)

If you have problems loading a saved model like that, you can try to use save_weights_only=True in the callback. And then you'd load the weights with model.load_weights(filepath).



来源:https://stackoverflow.com/questions/48460755/keras-how-to-stop-training-with-the-lowest-observed-metric-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!