问题描述
我使用MobileNet_v1_1.0_224张量流模型进行对象检测。 现在,我需要将自定义的冻结图形(.pb文件)转换为tflite扩展名,以便可以将模型用于移动设备。
有人可以帮助我在此张量板图中识别输入和输出名称吗? 我需要它们用作输入和输出参数,以将冻结的图形(.pb文件)转换为tensorflow lite(.tflite)文件
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
2楼
您正在寻找工具。
运行summarize_graph --in_graph=your_graph.pb
,它将输出。
如果您使用tensorflow/tensorflow
则可以在带有devel
标签的任何tensorflow/tensorflow
图像上找到tensorflow/tensorflow
。
例如:
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