将冻结的模型".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?

查看:512
本文介绍了将冻结的模型".pb"文件转换为".tflite"文件所需的参数input_arrays和output_arrays是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将我的.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)

推荐答案

根据官方文档

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对象的列表.

Meaning, 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对象是必需的.

In your case, you are providing the name of the Tensor object. An actual Tensor object is required.

您可以通过以下示例来理解它:

You can understand it with this example:

x1 = tf.placeholder( dtype=tf.float32 )
x2 = tf.placeholder( dtype=tf.float32 )
y = x1 + x2

input_arrays = [ x1 , x2 ]
output_arrays = [ y ]

您可以从 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆