Skip to content

Commit 74d6b21

Browse files
sayoojkkarunkartben
authored andcommitted
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 <[email protected]>
1 parent 6661952 commit 74d6b21

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

samples/modules/tflite-micro/hello_world/src/main_functions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15+
*
16+
* Copyright (c) 2025 Aerlync Labs Inc.
1517
*/
1618

1719
#include "main_functions.h"
@@ -90,7 +92,8 @@ void loop(void)
9092
float x = position * kXrange;
9193

9294
/* Quantize the input from floating-point to integer */
93-
int8_t x_quantized = x / input->params.scale + input->params.zero_point;
95+
int8_t x_quantized = (int8_t)round(x / input->params.scale)
96+
+ input->params.zero_point;
9497
/* Place the quantized input in the model's input tensor */
9598
input->data.int8[0] = x_quantized;
9699

0 commit comments

Comments
 (0)