I have been saving my training history in keras as follows:

history = model.fit(X_train, Y_train, epochs=700, batch_size=128,validation_data=(X_cv, Y_cv))

np.save('./history_sim#', history)


I am then trying to load the training history from the various simulations in order to print figures like loss vs. epoch, etc. as follows:

history = np.load('history_sim#.npy')


When I try to load the training history, I am receiving the following error message:

"ValueError: Unknown metric function:precision"


I am very worried that I have lost all of the training history now. Training takes several days and I am on a bit of a time crunch. Is the data lost or is there some way to get the data from the .npy file where I have saved it?

I already figured out that it works perfectly if I save/load as follows:

np.save('./history_sim#', history.history)


I will do that for the rest of the simulations, but there are already a few that were saved the first way and I do not have time to re-run them.

Thanks!

import keras_metrics

# Calculate precision for the second label.
precision = keras_metrics.precision(label=1)

# Calculate recall for the first label.
recall = keras_metrics.recall(label=0)

opt = Adam(lr=0.05, beta_1=0.9, beta_2=0.999, decay=0.0)
model.compile(loss='binary_crossentropy', optimizer=opt, metrics=[precision, recall])

• You shouldn't be saving them that way, use a logger? Apr 29, 2019 at 16:57
• Thanks for your reply, but it would be very helpful if when you say I should not do something in a certain way to also explain why not. I already figured out how to save the data in a way that I can later load it as shown in my question, I just need help getting the training data from the .npy files in which I have already saved the keras.callbacks.History object instead of the underlying dictionary. Apr 30, 2019 at 8:58
• The history property of this object is a dict with average accuracy and average loss information for each epoch, so *.pkl would be a better choice. I have asked few folks to help if possible recovering the same but I am sorry I don't have expertise on that, maybe you could share a dummy things and people can then experiment on it. Apr 30, 2019 at 9:04
• Also I hope you didn't pass the metric as a string because then we do see this error iirc.(waiting for folks to help you) Apr 30, 2019 at 9:16
• Thanks a lot, Aditya! I have also added how I pass the metrics to the question. Apr 30, 2019 at 10:49

use allow_pickle=True in np.load

>>>np.save("a.npy",his)

import numpy