megashigger
megashigger

Reputation: 9053

What's the best way to store Keras model params and model architecture alongside of the model?

I'd like to save all the model parameters (optimizer, learning rate, batch size, etc.) and model architecture (number and types of layers) alongside of the model so that later go back analyze why some models works better.

Is there a simple way to store this metadata along with the weights?

Upvotes: 0

Views: 811

Answers (1)

Martin Thoma
Martin Thoma

Reputation: 136665

From the docs:

from keras.models import load_model

model.save('my_model.h5')  # creates a HDF5 file 'my_model.h5'
del model  # deletes the existing model

# returns a compiled model
# identical to the previous one
model = load_model('my_model.h5')

This includes the optimizer (which should include the learning rate and the batch size). Besides that, you can use

  • Using configuration scripts which are under version control (I did so for my masters thesis, see my configuration scripts)
  • Storing the training script

If you want one file, just use a container file format like .tar.

Upvotes: 2

Related Questions