Conversion from h5 to Tensorflow pb file
See original GitHub issueI trained a yolov3 model (not the tiny version), and now I am trying to convert the saved yolo h5 file to Tensorflow pb, and so far I haven’t had luck. This is how I am trying to do the conversion:
import tensorflow as tf
from tensorflow.python.framework import graph_io
from tensorflow.keras.models import load_model
# Clear any previous session.
tf.keras.backend.clear_session()
def freeze_graph(graph, session, output, save_pb_dir='.', save_pb_name='yoloModel.pb', save_pb_as_text=False):
with graph.as_default():
graphdef_inf = tf.graph_util.remove_training_nodes(graph.as_graph_def())
graphdef_frozen = tf.graph_util.convert_variables_to_constants(session, graphdef_inf, output)
graph_io.write_graph(graphdef_frozen, save_pb_dir, save_pb_name, as_text=save_pb_as_text)
return graphdef_frozen
tf.keras.backend.set_learning_phase(0)
model = load_model('yoloModel.h5')
session = tf.keras.backend.get_session()
INPUT_NODE = [t.op.name for t in model.inputs]
OUTPUT_NODE = [t.op.name for t in model.outputs]
print(INPUT_NODE, OUTPUT_NODE)
frozen_graph = freeze_graph(session.graph, session, [out.op.name for out in model.outputs], save_pb_dir=save_pb_dir)
I have seen other issues where people asked the same question and seems like some of them solved their problem. But I could not really understand some of the comments since they were in Chinese.
Could anyone who succeeded in converting the file, share his/her script?
Best, Frank
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
Top Results From Across the Web
Tensorflow (.pb) format to Keras (.h5) - Stack Overflow
Complete working Code to convert a Model from Tensorflow Saved Model Format (pb) to Keras Saved Model Format (h5) is shown below:
Read more >Convert Keras '.h5' Model to TensorFlow SavedModel ...
Hello,. Is the conversion from a trained Keras model (.h5) to a TensorFlow model (either TF1 or TF2) possible/supported by TensorFlow?
Read more >How to convert model.h5 to model.pb?
There are different tools for converting hdf5 to .bp file as: 1 - convert trained Keras model to a single TensorFlow .pb file...
Read more >Can we convert a .h5 (keras) file to a .pb (TensorFlow) model ...
It is possible to convert a . h5 file generated from training in Keras to a frozen . pb model. I would like...
Read more >How to convert trained Keras model to a single TensorFlow ...
Keras to TensorFlow .pb file ... When you have trained a Keras model, it is a good practice to save it as a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
try this? https://github.com/amir-abdi/keras_to_tensorflow
@tiancailin I tried your suggestion, but I guess according to output h5 file does not have the model information?