简体   繁体   中英

Convert a Tensorflow model in SavedModel format (.pb file) saved with tf.saved_model.save to a Keras model (.h5 file)

I'm trying to convert a Tensorflow object detection model that's saved in a SavedModel format (in a folder with .pb file, assets folder, and variables folder) to Keras.h5 for simpler inference. However, trying common StackOverflow answers to this question (eg this ) results in a ValueError: Unable to create a Keras model from this SavedModel. This SavedModel was created with tf.saved_model.save, and lacks the Keras metadata.Please save your Keras model by calling model.save or tf.keras.models.save_model. ValueError: Unable to create a Keras model from this SavedModel. This SavedModel was created with tf.saved_model.save, and lacks the Keras metadata.Please save your Keras model by calling model.save or tf.keras.models.save_model. .

The model was trained and saved using the Tensorflow Object Detection API. Is it still possible to convert it to a Keras model? If so, any suggestions?

I faced the same issues while converting YoloV5 to Tensorflow format to deploy a model. you need to use keras=True in the export command of the model. This will generate the Keras_metadata.pb file at the directory.

[https://www.tensorflow.org/api_docs/python/tf/keras/models/save_model][1]

[1]: please refer this link for adding above commands to save Tensorflow model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM