What are the parameters input_arrays and output_arrays that are needed to convert a frozen model '.pb' file to a '.tflite' file?

白昼怎懂夜的黑 提交于 2019-12-24 08:07:08

问题


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)

回答1:


According to the official docs here :

input_arrays: List of input tensors to freeze graph with.

output_arrays: List of output tensors to freeze graph with.

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.

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 ]

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.



来源:https://stackoverflow.com/questions/55318440/what-are-the-parameters-input-arrays-and-output-arrays-that-are-needed-to-conver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!