Thank you for the sample!
I'm not 100% sure, but I believe that the processor is missing input quantization as described at https://www.tensorflow.org/lite/performance/post_training_integer_quant#run_the_tensorflow_lite_models
Something like
Edited with corrected code based on this discussion:
# 1. Read image as 300x300x3 uint8
res_im = im.resize((300, 300))
np_res_im = np.array(res_im)
#2 Transform from input uint8 RGB [0..255] to float [-1, 1]
np_res_im = (np_res_im / 255) * 2 - 1
#3 Apply quantization based on https://www.tensorflow.org/lite/performance/post_training_integer_quant#run_the_tensorflow_lite_models
# Check if the input type is quantized, then rescale input data to uint8
if input_details['dtype'] == np.uint8:
input_scale, input_zero_point = input_details["quantization"]
np_res_im = np_res_im / input_scale + input_zero_point
np_res_im = np.expand_dims(np_res_im, axis=0).astype(input_details["dtype"])
# Quantized input [0..255] is still 300x300x3 but the quantized values are different from the original image:
print(np_res_im)
This is based on this output from the first cell:
[{'name': 'normalized_input_image_tensor',
'index': 175,
'shape': array([ 1, 300, 300, 3], dtype=int32),
'shape_signature': array([ 1, 300, 300, 3], dtype=int32),
'dtype': numpy.uint8,
'quantization': (0.0078125, 128),
'quantization_parameters': {'scales': array([0.0078125], dtype=float32),
'zero_points': array([128], dtype=int32),
'quantized_dimension': 0},
'sparsity_parameters': {}}]
The dtype is uint8 and quantization and zero-point information is available.
Thank you for the sample!
I'm not 100% sure, but I believe that the processor is missing input quantization as described at https://www.tensorflow.org/lite/performance/post_training_integer_quant#run_the_tensorflow_lite_models
Something like
Edited with corrected code based on this discussion:
This is based on this output from the first cell:
The dtype is
uint8and quantization and zero-point information is available.