save and load keras.callbacks.History

前端 未结 3 1824
面向向阳花
面向向阳花 2021-02-08 03:13

I\'m training a deep neural net using Keras and looking for a way to save and later load the history object which is of keras.callbacks.History type. Here\'s the se

3条回答
  •  天涯浪人
    2021-02-08 03:30

    history_model_1 is a callback object. It contains all sorts of data and isn't serializable.

    However, it contains a dictionnary with all the values that you actually want to save (cf your comment) :

    import json
    # Get the dictionary containing each metric and the loss for each epoch
    history_dict = history_model_1.history
    # Save it under the form of a json file
    json.dump(history_dict, open(your_history_path, 'w'))
    

    You can now access the value of the loss at the 50th epoch like this :

    print(history_dict['loss'][49])
    

    Reload it with

    history_dict = json.load(open(your_history_path, 'r'))
    

    I hope this helps.

提交回复
热议问题