I am trying to extract intermediate outputs from a quantized TFLite model using the TFLite interpreter. The goal is to verify that the model's intermediate outputs match the mathematically expected values( tensorflow version 2.6.2 , python version 3.6.8)
Steps I followed:
- Loaded a quantized TFLite model using
tf.lite.Interpreter
. - Set the model input using:
interpreter.set_tensor(input_index, quantized_input)
- Invoked the interpreter:
interpreter.invoke()
- Retrieved op details:
op_details = interpreter._get_ops_details()
- For each layer, fetched the output tensor index:
out_tensor_index = op_details[i]["outputs"][0]
- Got the tensor values:
output = interpreter.get_tensor(out_tensor_index)
Saved the output of each layer as .npy files for further analysis.
Issue:
The output values obtained from interpreter.get_tensor()
do not match the mathematically calculated (expected) values, even after considering quantization parameters (e.g., scale and zero-point).
Questions:
- Is this the correct approach to extract intermediate layer outputs from a quantized TFLite model?
- Are there any limitations with using
interpreter._get_ops_details()
andget_tensor()
on quantized models?
Any help is welcome, let me know if more info is needed
A == B
would be False, butnumpy.allclose(A, B)
would be True? Or do you mean that they are completely different?