Skip to content

saved_model to pb

Katsuya Hyodo edited this page Dec 13, 2020 · 1 revision
import tensorflow as tf
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
import numpy as np

# Load saved_model
imported = tf.saved_model.load('saved_model')
f = imported.signatures["serving_default"]

# Get frozen ConcreteFunction
frozen_func = convert_variables_to_constants_v2(f)
frozen_func.graph.as_graph_def()

layers = [op.name for op in frozen_func.graph.get_operations()]
print("-" * 50)
print("Frozen model layers: ")
for layer in layers:
    print(layer)

# Save frozen graph from frozen ConcreteFunction to hard drive
tf.io.write_graph(graph_or_graph_def=frozen_func.graph,
                    logdir='saved_model',
                    name='faceboxes.pb',
                    as_text=False)
Clone this wiki locally