5

I want to get a clear image of model saving. There are hyper-parameters and model in Neural Network.

After I train the model, I want to save all to use them without retraining the model.

When I save the model as h5py file (.H5) is it save hyper-parameters also?

If yes, what is the purpose of pickle file?

sentence
  • 8,213
  • 4
  • 31
  • 40
Ind
  • 377
  • 2
  • 6
  • 16
  • What is the meaning of _what is the usage of pickle file?_ – sentence May 01 '19 at 14:29
  • I mean purpose of it. If all things can save by h5 what is the purpose of pickle file – Ind May 01 '19 at 14:32
  • 1
    Its a bit like asking _If XML exists, what is the purpose of JSON?_. Keras has both [`save(path)` and `save_weights(path)`](https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model) – Jeppe May 01 '19 at 14:36
  • @Jeppe Do you mean Pickel only save weights? – Ind May 02 '19 at 00:58
  • @Ind No. I think H5 is typically used for large numerical data, whereas pickle is general object serialization. Keras has chosen to use H5 for both storing weights, architecture, etc.. Did you read the link and the answer below? `save(path)` stores it all. `save_weights(path)` only stores the weights. Both use h5. – Jeppe May 02 '19 at 07:45

2 Answers2

8

From how-can-i-save-a-keras-model:

You can use model.save(filepath) to save a Keras model into a single HDF5 file which will contain:

  • the architecture of the model, allowing to re-create the model
  • the weights of the model
  • the training configuration (loss, optimizer)
  • the state of the optimizer, allowing to resume training exactly where you left off.

And it explicitly says:

It is not recommended to use pickle or cPickle to save a Keras model.

Why? Well, there may be a lot of reasons for that. This is a good starting point.

sentence
  • 8,213
  • 4
  • 31
  • 40
0

why don't you use keras model.save('mymodel.h5') ?

Keras docs:

It is not recommended to use pickle or cPickle to save a Keras model.

onew4y
  • 83
  • 6