3

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

So, you mean I must provide the tensors itself instead if the names? Thanks very much
Yes. Provide the tensors and not their names. Also, accept the answer if it feels helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.