What is the difference between these two ways of saving keras machine learning model weights?

前端 未结 2 683
我在风中等你
我在风中等你 2021-02-14 13:46

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

First way;

checkpointer = ModelCheckpoint(filepath=\"weights.hdf5\", verbose=1, save_best_only=Tru         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-02-14 14:42

    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.

提交回复
热议问题