TensorFlow解析PB模型输入输出节点名称的方法
本文介绍了在TensorFlow中查看.pb模型文件内部输入和输出节点名称的具体方法。通过加载GraphDef并遍历节点列表,可以获取模型的所有节点名称,从而确定输入和输出的具体标识。
定义输入节点名称
在TensorFlow中,可以通过定义输入节点名称来指定input_name。
with tf.name_scope('input'):
bottleneck_input = tf.placeholder_with_default(
bottleneck_tensor,
shape=[batch_size, bottleneck_tensor_size],
name='Mul')
查看PB模型节点名称
要查看.pb模型文件中的输入节点和输出节点,可以按照以下步骤操作。
import tensorflow as tf
import os
model_dir = './tmp/'
model_name = 'output_graph.pb'
def create_graph():
with tf.gfile.FastGFile(os.path.join(
model_dir, 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')
以上介绍了TensorFlow查看输入节点和输出节点名称的方法,希望对大家有所帮助。
免责声明:本文内容仅供参考,不代表本站观点。转载或引用请注明出处。









