获得input_array和output_array项目转换模型tflite格式

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

PS。请不要点我converting Keras model directly to tflite我的.h5文件将无法转换为直接.tflite。我总算将我.h5文件.pb

我按照this Jupyter笔记本使用Keras人脸识别。然后我救了我的模型到model.h5文件,然后将其转换为一个冷冻图形,model.pb使用this

现在我想用在我的Android文件tensorflow。为此,我需要有Tensorflow精简版,这就要求我对我的模型转换成.tflite格式。

对于这一点,我试图按照官方指南吧here。正如你可以看到有,它需要input_arrayoutput_array阵列。我如何获得我的model.pb文件的这些事情的细节?

python tensorflow tensorflow-lite
1个回答
2
投票

input arraysoutput arrays是分别存储输入和输出张量的阵列。

他们打算告知TFLiteConverter约将在推理时使用的输入和输出张量。

对于硬件模式,

输入张量是所述第一层的占位符张量。

input_tensor = model.layers[0].input

输出张量可以用活化功能涉及。

output_tensor = model.layers[ LAST_LAYER_INDEX ].output

对于冻结图,

import tensorflow as tf
gf = tf.GraphDef()   
m_file = open('model.pb','rb')
gf.ParseFromString(m_file.read())

我们得到的节点的名称,

for n in gf.node:
    print( n.name )

为了得到张量,

tensor = n.op

输入张量可以是一个占位符张量。输出张量是指运行使用session.run()张量

对于转换,我们得到,

input_array =[ input_tensor ]
output_array = [ output_tensor ]
© www.soinside.com 2019 - 2024. All rights reserved.