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

2024-05-05

我想使用张量流optimize_for_inference.py来自模型动物园的冷冻模型的脚本:ssd_mobilenet_v1_coco.

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

雇用张量板生成的图的版本 https://i.stack.imgur.com/EDL2V.png

这个问题可能会有所帮助:给定一个张量流模型图,如何找到输入节点和输出节点名称 https://stackoverflow.com/questions/43517959/given-a-tensor-flow-model-graph-how-to-find-the-input-node-and-output-node-name/48209066?noredirect=1#comment83400231_48209066(对我来说没有)


我想你可以使用下面的代码。我下载了ssd_mobilenet_v1_coco冷冻模型来自here https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf1_detection_zoo.md并能够获取输入和输出名称,如下所示

!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())

输出是

output name = 
detection_classes

Input name = 
image_tensor

请检查要点在这里 https://colab.research.google.com/gist/jvishnuvardhan/bd30545d9a1a773189b6a2cf0ee569f2/untitled.ipynb.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何查找冻结模型的输入和输出节点 的相关文章

随机推荐