None of the available options for saving models in Keras includes the training history, which is what exactly you are asking for here. To keep this history available, you have to do some trivial modifications to your training code so as to save it separately; here is a reproducible example based on the Keras MNIST example and only 3 training epochs:
hist = model.fit(x_train, y_train,
batch_size=batch_size,
epochs=3,
verbose=1,
validation_data=(x_test, y_test))
hist
is a Keras callback, and it includes a history
dictionary, which contains the metrics you are looking for:
hist.history
# result:
{'acc': [0.9234666666348775, 0.9744000000317892, 0.9805999999682109],
'loss': [0.249011807457606, 0.08651042315363884, 0.06568188704450925],
'val_acc': [0.9799, 0.9843, 0.9876],
'val_loss': [0.06219216037504375, 0.04431889447008725, 0.03649089169385843]}
i.e. the training & validation metrics (here loss & accuracy) for each one of the training epochs (here 3).
Now it is trivial to save this dictionary using Pickle, and to restore it as required:
import pickle
# save:
f = open('history.pckl', 'wb')
pickle.dump(hist.history, f)
f.close()
# retrieve:
f = open('history.pckl', 'rb')
history = pickle.load(f)
f.close()
A simple check here confirms that the original and the retrieved variables are indeed identical:
hist.history == history
# True
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…