load frozen model tensorflow code example
Example: how to freeze save_model.pb
def frozen_graph_maker(export_dir,output_graph):
with tf.Session(graph=tf.Graph()) as sess:
tf.saved_model.loader.load(sess, [tf.saved_model.tag_constants.SERVING], export_dir)
output_nodes = [n.name for n in tf.get_default_graph().as_graph_def().node]
output_graph_def = tf.graph_util.convert_variables_to_constants(
sess,
sess.graph_def,
output_nodes
)
with tf.gfile.GFile(output_graph, "wb") as f:
f.write(output_graph_def.SerializeToString())
def main():
export_dir='/dir/of/pb/and/variables'
output_graph = "frozen_graph.pb"
frozen_graph_maker(export_dir,output_graph)