如何识别张贴图中的输入和输出名称,如本帖附带的图片中的这个?

问题描述 投票:1回答:2

我使用MobileNet_v1_1.0_224张量流模型进行对象检测。现在,我有我需要转换为tflite扩展名的自定义冻结图(.pb文件),以便我可以将我的模型用于移动设备。

有人可以帮我识别这个张量板图中的输入和输出名称吗?我需要它们用作输入和输出参数来将我的冻结图形(.pb文件)转换为tensorflow lite(.tflite)文件

graph from tensorboard

same graph

python tensorflow deep-learning tensorboard tensorflow-lite
2个回答
1
投票

您可以使用此代码:

import tensorflow as tf
gf = tf.GraphDef()   
m_file = open('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 ("\noutput name = ")
print (data[len(data)-1])

print ("Input name = ")
file.seek ( 0 )
print (file.readline())

在我的情况下,我有

output name: SemanticPredictions
input name: ImageTensor

0
投票

您正在寻找summarize_graph工具。运行summarize_graph --in_graph=your_graph.pb,它将输出。如果您使用docker,您可以使用tensorflow/tensorflow标记在任何devel图像上找到summarize_graph。例如:

wget http://download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_1.0_224.tgz
tar xvf mobilenet_v1_1.0_224.tgz
docker run --rm -it -v $PWD:/data tensorflow/tensorflow:1.10.1-devel-py3

# Inside docker
cd /tensorflow
bazel build tensorflow/tools/graph_transforms:summarize_graph # This may take a while, use --jobs 4
./bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph=/data/mobilenet_v1_1.0_224_frozen.pb

输出将是:

Found 1 possible inputs: (name=input, type=float(1), shape=[?,224,224,3]) 
No variables spotted.
Found 1 possible outputs: (name=MobilenetV1/Predictions/Reshape_1, op=Reshape) 
Found 4254891 (4.25M) const parameters, 0 (0) variable parameters, and 0 control_edges
Op types used: 138 Const, 138 Identity, 27 FusedBatchNorm, 27 Relu6, 15 Conv2D, 13 DepthwiseConv2dNative, 2 Reshape, 1 AvgPool, 1 BiasAdd, 1 Placeholder, 1 Shape, 1 Softmax, 1 Squeeze
To use with tensorflow/tools/benchmark:benchmark_model try these arguments:
bazel run tensorflow/tools/benchmark:benchmark_model -- --graph=/data/mobilenet_v1_1.0_224_frozen.pb --show_flops --input_layer=input --input_layer_type=float --input_layer_shape=-1,224,224,3 --output_layer=MobilenetV1/Predictions/Reshape_1
© www.soinside.com 2019 - 2024. All rights reserved.