Keras: How to find the number of epochs a model was trained for?

Created on 19 Feb 2016  路  6Comments  路  Source: keras-team/keras

Given a trained Keras model, is there a way to check how many epochs were used to train it? For example, print model.nb_epoch.
When training a model, say, 20 epochs at a time this will help figure out how many total epochs it has been trained on.

Most helpful comment

you can save the length of your model's history when training it.

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

All 6 comments

I guess you're attempting to perform some sort of gridsearch to find the optimum training parameters to use?

As far as I am aware, there is nothing about the fitting of the NN stored in the saved models. You'd have to do this manually.

Okay, thanks. I guess I'll have to track it manually.

Any thoughts on adding model.nb_epoch to the class?

Any thoughts on adding model.nb_epoch to the class?

The number of "epochs" a model was trained for only makes sense in a few situations. It assume you use "epochs", but what if you train with randomly generated batches out of a data generator? What if you use several datasets? What if you use pre-training? etc.

So: no, we won't do that. A model is just a state.

That makes sense. Thanks for the response @fchollet!

I could still see situations where it would be helpful to see stats on the number of epochs from a model:

  1. In case you decide to stop training, save your temporary model and continue later, continue the epoch counter at the total number of epochs during which the model was previously trained.
  2. For equivalent model setups where callbacks like ReduceLnRate or EarlyStopping were used, the number of epochs could be an indicator of how early the model stopped training.

you can save the length of your model's history when training it.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zygmuntz picture zygmuntz  路  3Comments

braingineer picture braingineer  路  3Comments

anjishnu picture anjishnu  路  3Comments

Imorton-zd picture Imorton-zd  路  3Comments

NancyZxll picture NancyZxll  路  3Comments