获取input_array和output_array项以将模型转换为tflite形式

2024-09-28 19:25:28 发布

您现在位置:Python中文网/ 问答频道 /正文

PS.请不要将我指向converting Keras model directly to tflite,因为我的.h5文件无法直接转换为.tflite。我设法把.h5文件转换成.pb

我跟踪了thisJupyter笔记本,使用Keras进行人脸识别。然后我将模型保存到model.h5文件中,然后使用this将其转换为一个冻结的图形model.pb。在

现在我想在Android中使用我的tensorflow文件。为此,我需要TensorFlowLite,它需要我将模型转换为.tflite格式。在

为此,我尝试遵循官方的指导方针。如您所见,它需要input_arrayoutput_array数组。如何从model.pb文件中获取这些内容的详细信息?在


Tags: 文件to模型modelarraykerasps指向
1条回答
网友
1楼 · 发布于 2024-09-28 19:25:28

input arrays和{}是分别存储输入张量和输出张量的数组。在

They intend to inform the TFLiteConverter about the input and output tensors which will be used at the time of inference.

对于Keras模型,

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

input_tensor = model.layers[0].input

输出张量可能与激活函数有关。在

^{pr2}$

对于冻结图,

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 ]

相关问题 更多 >