save and load keras.callbacks.History

前端 未结 3 1886
面向向阳花
面向向阳花 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:23

    You can create a class so you will have the same structure and you can access in both cases with the same code.

    import pickle
    class History_trained_model(object):
        def __init__(self, history, epoch, params):
            self.history = history
            self.epoch = epoch
            self.params = params
    
    with open(savemodel_path+'/history', 'wb') as file:
        model_history= History_trained_model(history.history, history.epoch, history.params)
        pickle.dump(model_history, file, pickle.HIGHEST_PROTOCOL)
    

    then to access it:

    with open(savemodel_path+'/history', 'rb') as file:
        history=pickle.load(file)
    
    print(history.history)
    

提交回复
热议问题