重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍tensorflow中ckpt模型和pb模型如何获取节点名称,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
创新互联公司是一家专注于网站制作、成都做网站与策划设计,海伦网站建设哪家好?创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:海伦等地区。海伦做网站价格咨询:13518219792ckpt
from tensorflow.python import pywrap_tensorflow checkpoint_path = 'model.ckpt-8000' reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path) var_to_shape_map = reader.get_variable_to_shape_map() for key in var_to_shape_map: print("tensor_name: ", key)
pb
import tensorflow as tf import os model_name = './mobilenet_v2_140_inf_graph.pb' def create_graph(): with tf.gfile.FastGFile(model_name, 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) tf.import_graph_def(graph_def, name='') create_graph() tensor_name_list = [tensor.name for tensor in tf.get_default_graph().as_graph_def().node] for tensor_name in tensor_name_list: print(tensor_name,'\n')
ckpt转pb
def freeze_graph(input_checkpoint,output_graph): ''' :param input_checkpoint: :param output_graph: PB模型保存路径 :return: ''' output_node_names = "xxx" 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)) for op in graph.get_operations(): print(op.name, op.values())
以上是“tensorflow中ckpt模型和pb模型如何获取节点名称”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!