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_array
和output_array
阵列。我如何获得我的model.pb
文件的这些事情的细节?
input arrays
和output 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 ]