I want to know if it is possible and how to extract the order of the graph layers from a .tflite file, I am currently trying to extract this information directly through the Tensorflow2 API.
import tensorflow as tf
interpreter = tf.lite.Interpreter(model_path=model_path)
layer_details = interpreter.get_tensor_details()
interpreter.allocate_tensors()
for layer in layer_details:
print("\nLayer Name: {}".format(layer['name']))
print("\tIndex: {}".format(layer['index']))
print("\n\tShape: {}".format(layer['shape']))
print("\tTensor: {}".format(interpreter.get_tensor(layer['index']).shape))
print("\tTensor Type: {}".format(interpreter.get_tensor(layer['index']).dtype))
print("\tQuantisation Parameters")
print("\t\tScales: {}".format(layer['quantization_parameters']['scales'].shape))
print("\t\tScales Type: {}".format(layer['quantization_parameters']['scales'].dtype))
print("\t\tZero Points: {}".format(layer['quantization_parameters']['zero_points']))
print("\t\tQuantized Dimension: {}".format(layer['quantization_parameters']['quantized_dimension']))
Results in the output:
Layer Name: Identity_int8
Index: 0
Shape: [ 1 15]
Tensor: (1, 15)
Tensor Type: int8
Quantisation Parameters
Scales: (1,)
Scales Type: float32
Zero Points: [-128]
Quantized Dimension: 0
Layer Name: reshape_input_int8
Index: 1
Shape: [ 1 2 256]
Tensor: (1, 2, 256)
Tensor Type: int8
Quantisation Parameters
Scales: (1,)
Scales Type: float32
Zero Points: [-2]
Quantized Dimension: 0
... etc
However these layers are not in the order that they will be executed in the graph, I am not sure how the index relates to the actual graph ordering.
When inspecting "get_input_details" and "get_output_details" I find that the input and output correspond to index 20 and 21 respectively.
I have also converted the tflite file to json using the flatc compiler as such:
flatc -t schema.fbs model.tflite
The converted json model has additional information in it, such as the buffer number, but this doesn't seem to be correlated with layer order either.
Does anyone have any suggestions for what direction I should move in from here? Cheers