Hagbard
Hagbard

Reputation: 3680

Find the number of epochs of a loaded Keras model

I usually load my Keras models using the load_model() method. Is it possible to obtain the number of epochs a model was trained for after loading it again?

This GitHub issue mentions the following hack:

r = model.fit(X_train,y_train,epochs=5)
n_epochs = len(r.history['loss'])

However, that's not exactly what I want as I would like to obtain the number of epochs from the loaded models.

Upvotes: 1

Views: 2877

Answers (1)

Baptiste Pouthier
Baptiste Pouthier

Reputation: 572

You cannot obtain the history after loading a model as the saved model keeps only the architecture and the weights. So you can't have the number of epochs of a loaded model. See also this SO question.

Upvotes: 3

Related Questions