I have saved a keras
module as a h5py
file and am loading it from disk.
When training the model I use:
from keras.models im
Using pickle
to save the history object threw a whole host of errors. As it turns out you can instead use pickle
on H.history
instead of H
to save your history file!
Kind of annoying having to have a model and a history file saved, but whatever
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.