Typefully

SavedModel or H5?

Avatar

Share

 • 

4 years ago

 • 

View on X

What format to save your model? SavedModel or H5? What are those? What's the difference? Let's see ↓
• If you have been working on machine learning or deep learning with tensorflow, you must have saved your models. • Often we see them saved as ↓
• What difference does it make? • If you have built models for simple tasks and systems, you might not have come across any complications using either. But there's a difference
• There are two formats a tensorflow model can be saved as. 1. SavedModel 2. HDF5
SavedModel • SavedModel format is the default for saving the model in Tensorflow 2.x • It is a way to serialize models. In SavedModel format model directory is saved which contains checkpoint and protobuf files. • The contents of the SavedModel format are:
• The saved_model.pb stores the actual Tensorflow program. • The variables directory contains a standard training checkpoint. • The assets directory contains files used by the TensorFlow graph.
• If you are going to be using only the tensorflow environment, SavedModel format works best. • SavedModel is also supported by Tensorflow Serving which is very useful for deployment.
H5 Format • The ".h5" is an extension that is used to save the keras model in the HDF5 standard. • The HDF5 was used to make the model to be used out of the tensorflow environment.
• It was developed as previously Keras wasn't officially a tensorflow API. • So ".h5" allowed the model to be used with other backends. • If you have any custom objects they would need to be separately defined while loading the model, which isn't the case with SavedModel.
So now that you know each format, it is likely that you'll mostly need the SavedModel. Any comments, suggestions or corrections are welcome! Thanks for reading!
Avatar

Prashant

@capeandcode

ml engineer @nagarro | python and ai