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)
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.