lightweight_openpose icon indicating copy to clipboard operation
lightweight_openpose copied to clipboard

how to get the pb model

Open weilanShi opened this issue 4 years ago • 0 comments

And there is my code to get pb model:

import tensorflow as tf #from create_tf_record import * from tensorflow.python.framework import graph_util

def freeze_graph(input_checkpoint,output_graph): output_node_names = "pre_hmap" saver = tf.train.import_meta_graph(input_checkpoint + '.meta', clear_devices=True) graph = tf.get_default_graph() # 获得默认的图 input_graph_def = graph.as_graph_def() # 返回一个序列化的图代表当前的图

with tf.Session() as sess:
    saver.restore(sess, input_checkpoint) #恢复图并得到数据
    output_graph_def = graph_util.convert_variables_to_constants(  # 模型持久化,将变量值固定
        sess=sess,
        input_graph_def=input_graph_def,# 等于:sess.graph_def
        output_node_names=output_node_names.split(','))# 如果有多个输出节点,以逗号隔开

    with tf.gfile.GFile(output_graph, "wb") as f: #保存模型
        f.write(output_graph_def.SerializeToString()) #序列化输出
    print("%d ops in the final graph." % len(output_graph_def.node)) #得到当前图有几个操作节点

input_checkpoint = "./ckpt/model.ckpt-61236" out_pb_path='pb_pre.pb' freeze_graph(input_checkpoint, out_pb_path)

As shown in the figure, I visualize the PB model, and the input node name is strange, and there are two inputs. What's wrong when converting ckpt to pb ?

Screenshot from 2020-11-18 10-19-17

weilanShi avatar Nov 18 '20 02:11 weilanShi