你怎么能像这张 post 所附图片中的张量板图那样识别输入和输出名称?

How can you identify Input and Output name in tensorboard graph like this one in the pictures attached to this post?

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

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

graph from tensorboard

same graph

您正在寻找 summarize_graph 工具。 运行 summarize_graph --in_graph=your_graph.pb 就会输出。 如果您使用 docker,您可以在任何带有 devel 标签的 tensorflow/tensorflow 图像上找到 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

您可以使用此代码:

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