如何查找冻结模型的输入和输出节点

gus*_*avz 13 inference tensorflow object-detection-api

我想optimize_for_inference.py在模型动物园的冻结模型上使用tensorflow的脚本:ssd_mobilenet_v1_coco.

如何查找/确定模型的输入和输出名称?

这是一个由tensorboard生成的图表的链接

这个问题可能会有所帮助:给定张量流模型图,如何找到输入节点和输出节点名称 (对我来说它没有)

Pet*_*den 6

我们现在已经添加了一些关于此过程的文档,包括:

https://www.tensorflow.org/mobile/prepare_models

如果您查找summarize_graph,您将看到如何找出正确的输入和输出节点的示例.

  • 最新文档似乎在这里:https://www.tensorflow.org/lite/guide/faq#how_do_i_determine_the_inputsoutputs_for_graphdef_protocol_buffer 如果他们再次移动它,他们建议使用:`bazel build tensorflow/tools/graph_transforms:summarize_graph``bazel- bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph=tensorflow_inception_graph.pb` 或 `python import_pb_to_tensorboard.py --model_dir <model path> --log_dir <log dir path>` (2认同)

小智 1

我想你可以使用下面的代码。我从这里ssd_mobilenet_v1_coco下载了冻结模型,并且能够获取输入和输出名称,如下所示

!pip install tensorflow==1.15.5

import tensorflow as tf
tf.__version__ # TF1.15.5

gf = tf.GraphDef()  
m_file = open('/content/frozen_inference_graph.pb','rb')
gf.ParseFromString(m_file.read())
 
with open('somefile.txt', 'a') as the_file:
   for n in gf.node:
       the_file.write(n.name+'\n')
 
file = open('somefile.txt','r')
data = file.readlines()
print("output name = ")
print(data[len(data)-1])
 
print("Input name = ")
file.seek ( 0 )
print(file.readline())
Run Code Online (Sandbox Code Playgroud)

输出是

output name = 
detection_classes

Input name = 
image_tensor
Run Code Online (Sandbox Code Playgroud)

请在此处查看要点。