Keras:如何以最低的观测指标值停止训练? [英] Keras: How to stop training with the lowest observed metric value?

查看:510
本文介绍了Keras:如何以最低的观测指标值停止训练?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Keras,我想在返回最佳(大多数情况下:最低)观测指标(例如val_loss)的时代停止训练.在忍耐耗尽"之后,我不想使用网络的状态.

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".

我该怎么做?

推荐答案

好吧....您无法真正以最佳准确性停止",因为您需要知道将来的值来确定是否会有更好的结果.值!

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!

但是您可以使用另一个回调 ModelCheckpoint 来在每个时期后保存模型.

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

您可以传递参数save_best_only,因此仅在监视值(在您的情况下为'val_loss')比上次保存的模型好时才保存模型.

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.

训练后,您可以加载保存的模型:keras.models.load_model(filepath)

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

如果在加载这样保存的模型时遇到问题,则可以尝试在回调中使用save_weights_only=True.然后用model.load_weights(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).

这篇关于Keras:如何以最低的观测指标值停止训练?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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