8

I am trying to figure out some of the hyperparamters used for training some old keras models I have. They were saved as .h5 files. When using model.summary(), I get the model architecture, but no additional metadata about the model.

When I open this .h5 file in notepad++, most of the file is not human readable, but there are bits that I can understand, for instance;

{"loss_weights": null, "metrics": ["accuracy"], "sample_weight_mode": null, "optimizer_config": {"config": {"decay": 0.0, "momentum": 0.8999999761581421, "nesterov": false, "lr": 9.999999747378752e-05}, "class_name": "SGD"}, "loss": "binary_crossentropy"}

which is not present in the output printed by model.summary().

Is there a way to make these files human readable or to get a more expanded summary that includes version information and training parameters?

Mark
  • 419
  • 4
  • 13
  • which hyperparameters do you want to see? – Dr. Snoopy Dec 31 '18 at 16:18
  • @Matias I'd like to see everything I can, excluding specific weights and biases. I'd like to reproduce the old model, so it helps to know how it was trained. – Mark Dec 31 '18 at 17:50
  • 1
    The thing is that weights and biases are not hyper-parameters, so it will be useful to see exactly what you expect. The H5 file usually has all the information about the model, including the configuration. – Dr. Snoopy Dec 31 '18 at 17:58

3 Answers3

12

I think what you want is the model configuration, you can get these with:

model.get_config()

It returns a "human readable" JSON string that describes the configuration of the model. You can use this to reconstruct the model and train it again, or to make changes.

Dr. Snoopy
  • 55,122
  • 7
  • 121
  • 140
9

If you want to know the hyperparams of the layers (no of layers, no of neurons in each layer, and activation function used in each layer), you can do:

model.get_config()

To find out loss function used in training, do:

model.loss

Additionally, if you want to know the Optimizer used in the training, do:

model.optimizer

And finally, in order to find out the learning rate used while training, do:

from keras import backend as K
K.eval(m.optimizer.lr)

PS: Examples provided above use keras v2.3.1.

Usman Ahmad
  • 376
  • 4
  • 13
2

Configuration - model.get_config()

Optimizer config - model.optimizer.get_config()

Training Config model.history.params (this will be empty, if model is saved and reloaded)

Loss Fuction - model.loss

frier
  • 46
  • 3