Keras的EarlyStopping是否可以保存最佳模型? [英] Does EarlyStopping in Keras save the best model?

查看:538
本文介绍了Keras的EarlyStopping是否可以保存最佳模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用类似的东西时:

callbacks = [
    EarlyStopping(patience=15, monitor='val_loss', min_delta=0, mode='min'),
    ModelCheckpoint('best-weights.h5', monitor='val_loss', save_best_only=True, save_weights_only=True)
]

model.fit(..., callbacks=callbacks)

y_pred = model.predict(x_test)

我使用训练期间计算出的最佳权重进行预测还是model正在使用最后的权重(可能不是最佳权重)?

am I doing the prediction with the best weights calculated during training or model is using the last weights (which may not be the best ones)?

那么,以上是安全的方法吗?即使在训练后立即进行预测,也应该将best-weights.h5加载到模型中吗?

So, is the above a safe approach or should I load best-weights.h5 into the model even if the predictions are done right after training?

推荐答案

EarlyStopping回调本身不会保存任何内容(您可以查看其源代码仔细检查它

EarlyStopping callback doesn't save anything on its own (you can double check it looking at its source code https://github.com/keras-team/keras/blob/master/keras/callbacks.py#L458). Thus your code saves the last model that achieved the best result on dev set before the training was stopped by the early stopping callback. I would say that, if you are saving only the best model according to dev, it is not useful to have also an early stopping callback (unless you don't want to save time and your are sure enough you are not going to find any better model if you continue the training)

这篇关于Keras的EarlyStopping是否可以保存最佳模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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