openmv/lib/tflm
iabdalkader daf2bb30da misc: Restructure repo.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-04-13 08:28:34 +02:00
..
libtflm@73eb1aa074 misc: Restructure repo. 2025-04-13 08:28:34 +02:00
models misc: Restructure repo. 2025-04-13 08:28:34 +02:00
Makefile misc: Restructure repo. 2025-04-13 08:28:34 +02:00
README.md misc: Restructure repo. 2025-04-13 08:28:34 +02:00
tflm_backend.cc misc: Restructure repo. 2025-04-13 08:28:34 +02:00

Tensorflow Support

The OpenMV firmware supports running quantized TensorFlow Lite models using TensorFlow Lite Micro (TFLM). The firmware supports loading models stored on the filesystem to memory (on boards with SDRAM) or running internal models (embedded into the firmware) in place. To load an external TensorFlow model from the filesystem from Python, use the tf Python module. For information on embedding TensorFlow models into the firmware and loading them, please see the following sections.

Training Tensorflow models

TensorFlow Lite and Keras can be used to train and quantize models that run directly on the camera. For example, see Training Mobilenet V2 for OpenMV with Keras. Alternatively, EdgeImpulse supports OpenMV cameras and Arduino boards running OpenMV firmware. For more information on using EdgeImpulse with OpenMV cameras, please see the EdgeImpulse tutorial for OpenMV.

Embedding Tensorflow models in the firmware

TensorFlow models can be embedded into the firmware for boards that don't have SDRAM. The firmware ships with default embedded models that can be replaced. Additionally, more models can be embedded in the firmware, as many as the free flash size allows. Once you have a TensorFlow Lite (TFLite) model to replace the default model or to add to the firmware, it can be embedded in the firmware by placing the model .tflite file and its .txt labels file in src/lib/tflm/. The model file and labels file must have the same basename, for example:

models/mask_detection.txt
models/mask_detection.tflite

The labels .txt file contains model output labels arranged 1 label per line, for example:

>>cat mask_detection.txt 
mask
no_mask

After replacing/adding a Tensorflow model, rebuild the firmware to use the new model. The build system will automatically detect the models and convert them to C structs that get embedded into the firmware image. For more information on how to build the OpenMV firmware from source, see Building the Firmware From Source

Loading embedded Tensorflow models

Built-in models can be loaded with tf.load_builtin_model() function, for example the following loads the built-in person detection model:

labels, net = tf.load_builtin_model('person_detection')

For more information on how to OpenMV Tensorflow Python module, see the documentation