joonb14 / tflitedetection Goto Github PK
View Code? Open in Web Editor NEWTensorFlow Lite Object Detection Python Implementation
TensorFlow Lite Object Detection Python Implementation
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.