From 74d6b21cd3e5f1ae717ef5f053844e5f4e2717a6 Mon Sep 17 00:00:00 2001 From: Sayooj K Karun Date: Tue, 15 Apr 2025 15:37:13 +0530 Subject: [PATCH] samples: tflite-micro: hello_world: round off quantization Add roundoff to quantization calculation so that precision is not lost in in edge cases or when quantization error propagates through model layes. Signed-off-by: Sayooj K Karun --- .../modules/tflite-micro/hello_world/src/main_functions.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/samples/modules/tflite-micro/hello_world/src/main_functions.cpp b/samples/modules/tflite-micro/hello_world/src/main_functions.cpp index 1666e161cf9..7acb4182f2a 100644 --- a/samples/modules/tflite-micro/hello_world/src/main_functions.cpp +++ b/samples/modules/tflite-micro/hello_world/src/main_functions.cpp @@ -12,6 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * Copyright (c) 2025 Aerlync Labs Inc. */ #include "main_functions.h" @@ -90,7 +92,8 @@ void loop(void) float x = position * kXrange; /* Quantize the input from floating-point to integer */ - int8_t x_quantized = x / input->params.scale + input->params.zero_point; + int8_t x_quantized = (int8_t)round(x / input->params.scale) + + input->params.zero_point; /* Place the quantized input in the model's input tensor */ input->data.int8[0] = x_quantized;