将冻结的模型".pb"文件转换为".tflite"文件所需的参数input_arrays和output_arrays是什么? [英] What are the parameters input_arrays and output_arrays that are needed to convert a frozen model '.pb' file to a '.tflite' file?
问题描述
我需要将我的.pb
张量流模型与我的.cpkt
文件一起转换为一个tflite
模型,以使其在移动设备中运行.是否有任何简单明了的方法来找出如何找到应该用于input_arrays和output_arrays的参数的地方?
I need to convert my .pb
tensorflow model together with my .cpkt
file to a tflite
model to make it work in Mobile Devices. Is there any straight-forward way to find out how can I find what are the parameters I should use for input_arrays and output_arrays?
import tensorflow as tf
graph_def_file = "/path/to/Downloads/mobilenet_v1_1.0_224/frozen_graph.pb"
input_arrays = ["input"]
output_arrays = ["MobilenetV1/Predictions/Softmax"]
converter = tf.lite.TFLiteConverter.from_frozen_graph(
graph_def_file, input_arrays, output_arrays)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
推荐答案
根据官方文档
意思是 Meaning, 在您的情况下,您要提供 In your case, you are providing the 您可以通过以下示例来理解它: You can understand it with this example: 您可以从 answer . You can learn to find the input and output tensors from here .
Seeing your code, it seems that you know the tensor names, so you can refer this answer. 这篇关于将冻结的模型".pb"文件转换为".tflite"文件所需的参数input_arrays和output_arrays是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!input_arrays
:用于冻结图的输入张量列表.
input_arrays
: List of input tensors to freeze graph with.output_arrays
:用于冻结图的输出张量列表.output_arrays
: List of output tensors to freeze graph with.input_arrays
是输入张量的列表(主要是占位符张量). output_arrays
是将用作输出的Tensor
对象的列表. input_arrays
is the list of input tensors ( which are mostly placeholder tensors ). output_arrays
is the list of Tensor
objects which will act as outputs. Tensor
对象的name
.实际的Tensor对象是必需的. name
of the Tensor
object. An actual Tensor object is required. x1 = tf.placeholder( dtype=tf.float32 )
x2 = tf.placeholder( dtype=tf.float32 )
y = x1 + x2
input_arrays = [ x1 , x2 ]
output_arrays = [ y ]