diff --git a/scripts/examples/03-Machine-Learning/00-TensorFlow/tf_regression.py b/scripts/examples/03-Machine-Learning/00-TensorFlow/tf_regression.py new file mode 100644 index 000000000..70a92f41a --- /dev/null +++ b/scripts/examples/03-Machine-Learning/00-TensorFlow/tf_regression.py @@ -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 diff --git a/src/lib/tflm/models/force_int_quant.tflite b/src/lib/tflm/models/force_int_quant.tflite new file mode 100644 index 000000000..cdf258d9a Binary files /dev/null and b/src/lib/tflm/models/force_int_quant.tflite differ diff --git a/src/lib/tflm/models/index.txt b/src/lib/tflm/models/index.txt index 3b4ee2601..866f53c0e 100644 --- a/src/lib/tflm/models/index.txt +++ b/src/lib/tflm/models/index.txt @@ -5,3 +5,4 @@ fomo_face_detection.tflite micro_speech.tflite person_detect.tflite person_detect_vela.tflite +force_int_quant.tflite diff --git a/src/omv/boards/OPENMV_RT1060/imlib_config.h b/src/omv/boards/OPENMV_RT1060/imlib_config.h index eb36be078..367621d77 100644 --- a/src/omv/boards/OPENMV_RT1060/imlib_config.h +++ b/src/omv/boards/OPENMV_RT1060/imlib_config.h @@ -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).