How to control the names given to the outputs of a TF-lite model?

Viewed 22

A TF model converted to TF-lite model by the following code

converter = tf.lite.TFLiteConverter.from_saved_model("test_saved_model")
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS]

tflite_model = converter.convert()
interpreter = tf.lite.Interpreter(model_content=tflite_model)

The details of the model outputs are extracted by

print(interpreter.get_output_details())

which prints:

[{'name': 'serving_default_input1:0', 'index': 0, 'shape': array([1, 3, 3, 2], dtype=int32), 'shape_signature': array([-1, 3, 3, 2], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}, {'name': 'serving_default_input2:0', 'index': 1, 'shape': array([1, 3, 3, 4], dtype=int32), 'shape_signature': array([-1, 3, 3, 4], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}, {'name': 'PartitionedCall:2', 'index': 2, 'shape': array([1, 3, 3, 6], dtype=int32), 'shape_signature': array([-1, 3, 3, 6], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]

I would like to correlate this print to the real outputs using the name. Therefore, how to do it and how to control the names given to the outputs?

The original model:

input1 = tf.keras.layers.Input(shape=(3,3,2), name="input1")
input2 = tf.keras.layers.Input(shape=(3,3,4), name="input2")
input5 = tf.keras.layers.concatenate([input1, input2], axis=-1, name='input5')
model = tf.keras.Model(inputs=[input1, input2], outputs=[input1, input2, input5])
0 Answers
Related