How can I get the a keras models' history after loading it from a file in Python?

Unfortunately it seems that Keras hasn't implemented the possibility of loading the history directly from a loaded model. Instead you have to set it up in advance. This is how I solved it using CSVLogger (it's actually very convenient storing the entire training history in a separate file. This way you can always come back later and plot whatever history you want instead of being dependent on a variable you can easily lose stored in the RAM):

First we have to set up the logger before initiating the training.

from keras.callbacks import CSVLogger

csv_logger = CSVLogger('training.log', separator=',', append=False)
model.fit(X_train, Y_train, callbacks=[csv_logger])

The entire log history will now be stored in the file 'training.log' (the same information you would get, by in your case, calling H.history). When the training is finished, the next step would simply be to load the data stored in this file. You can do that with pandas read_csv:

import pandas as pd
log_data = pd.read_csv('training.log', sep=',', engine='python')

From heron you can treat the data stored in csv_logger just as you would by loading it from K.history.

More information in Keras callbacks docs.

Tags:

Python

Keras