这两种节省keras机器学习模型权重的方法有什么区别? [英] What is the difference between these two ways of saving keras machine learning model weights?

查看:175
本文介绍了这两种节省keras机器学习模型权重的方法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了两种减轻keras模型权重的方法.

I saw two ways of saving the weights of a keras model.

第一种方式;

checkpointer = ModelCheckpoint(filepath="weights.hdf5", verbose=1, save_best_only=True)
model.fit(x_train, y_train,
                    nb_epoch=number_of_epoch,
                    batch_size=128,
                    verbose=1,
                    validation_data=(x_test, y_test),
                    callbacks=[reduce_lr, checkpointer],
                    shuffle=True)

第二种方式;

model.save_weights("model_weights.h5")

两种方式有什么区别?加载weights.hdf5model_weights.h5之间的预测性能有何不同?

What is the difference between the two ways? Any difference in prediction performance between loading weights.hdf5 and model_weights.h5?

推荐答案

不,在性能方面没有区别.这只是保存模型的方式的两种不同方式,尤其是何时保存.每当您要保存模型时,使用model.save_weights都需要特别调用此函数,例如训练或部分训练完成后.如果您仍在开发模型,则使用ModelCheckpoint更为方便.通过这种方式,keras可以在每个训练时期之后保存模型的检查点,以便您可以还原不同的模型;或者您可以设置save_best_only=True,以使keras仅在性能提高后才覆盖最新的检查点,从而以性能最佳的模型结束.

No, there is no difference performance-wise. These are just two different ways of how and especially when the model shall be saved. Using model.save_weights requires to especially call this function whenever you want to save the model, e.g. after the training or parts of the training are done. Using ModelCheckpoint is much more convenient if you are still developing a model. Using this way, keras can save a checkpoint of your model after each training epoch, so that you can restore the different models; or you can set save_best_only=True so that keras will overwrite the latest checkpoint only if the performance has improved, so that you end with the best performing model.

总结一下:这只是做两种不同事情的两种不同方式.这取决于您的用例和需求,什么才是最好的.

To summarize it: these are just two different ways of doing two different things. It depends on your use case and needs, what's the best.

这篇关于这两种节省keras机器学习模型权重的方法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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