Merge pull request #2276 from kwagyeman/kwabena/add_regression_example

scripts/examples: Add regression example.
This commit is contained in:
Ibrahim Abdelkader 2024-07-13 00:50:25 +02:00 committed by GitHub
commit 0f66e53201
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,31 @@
# This work is licensed under the MIT license.
# Copyright (c) 2013-2024 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# TensorFlow Lite Regression Example
#
# This example shows off running a regression model on the OpenMV Cam.
# A regression model takes an input list of numbers and produces an
# output list of numbers. You may pass ndarrays arrays to predict()
# and you will get a list of the results back.
#
# Note: The input list of numbers must be the same size as the input
# tensor size of the model.
import ml
from ulab import numpy as np
# The model is built-in on the RT1062. On other OpenMV Cam's with limited flash space please grab
# the model from here: https://github.com/openmv/openmv/tree/master/src/lib/tflm/models and
# copy it to the OpenMV Cam's file system. E.g. model = ml.Model("force_int_quant.tflite")
model = ml.Model("force_int_quant")
print(model)
i = np.array([-3, -1, -2, 5, -2, 10, -1, 9, 0, # noqa
2, 0, 9, 1, 10, 2, -1, 3, 5, # noqa
3, 9, 3, 9, 6, 2, 6, 7, 5, # noqa
10, 6, -1, 7, 4, 7, 8, 5, 7], # noqa
dtype=np.int8).reshape(model.input_shape[0]) # noqa
print(model.predict([i])[0])
# Should print 53.78332

Binary file not shown.

View File

@ -5,3 +5,4 @@ fomo_face_detection.tflite
micro_speech.tflite
person_detect.tflite
person_detect_vela.tflite
force_int_quant.tflite

View File

@ -118,6 +118,7 @@
#define IMLIB_ENABLE_TFLM
#define IMLIB_ENABLE_TFLM_BUILTIN_FOMO_FACE_DETECTION
#define IMLIB_ENABLE_TFLM_BUILTIN_PERSON_DETECT
#define IMLIB_ENABLE_TFLM_BUILTIN_FORCE_INT_QUANT
#endif
// Enable FAST (20+ KBs).