Convert Keras '.h5' Model to TensorFlow SavedModel (saved_model.pb)


Is the conversion from a trained Keras model (.h5) to a TensorFlow model (either TF1 or TF2) possible/supported by TensorFlow?


you can try to read Keras model (.h5) and rewrite as SavedModel (saved_model.pb)


Any resources that might help me with the exact steps?

# Here is an example from

from keras.models import load_model'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')

Read more: Model saving & serialization APIs


adding up to the discussion, this links can help you have a deeper understand if you want:

I’d go over these tutorials (they are short), they will give you a good understanding.

1 Like

You can convert the model by freezing variables, this is possible with TF <2.0. Above TF 2.0 may give you an error.

1 Like