Run the TensorFlow Lite Demo Application With NPU Support on Torizon OS
Introduction
This article shows how to run a Toradex-provided TensorFlow Lite demo application that leverages the Neural Processing Unit (NPU) on Torizon OS.
The demo is based on a object detection model which detect Toradex modules on a given image. Refer to the Torizon Object Detection AI Training and Inference for Toradex Modules blog post for more details.
Prerequisites
-
Hardware Prerequisites:
- A System-on-Module (SoM) with NPU support on Torizon OS
- A compatible Carrier Board
-
Software Requirements:
- A Toradex System-on-Module with Torizon OS installed
Demonstration
Follow the instructions below to run the TensorFlow Lite demo application on Torizon OS. The demo application is provided by Toradex and is designed to showcase the performance benefits of using the NPU for Machine Learning inference tasks.
The application is available as a pre-built Docker image that you can run on your target device:
# docker run --rm \
--name "tflite-example" \
-v /dev:/dev \
-v /tmp:/tmp \
--device-cgroup-rule "c 199:0 rmw" \
torizon/tensorflow-lite-imx8:4
For i.MX 95 modules, Torizon OS must be built based on the Walnascar Yocto release. Refer to the AI, Computer Vision and Machine Learning on Toradex i.MX 95-based Modules article to set up a Walnascar Torizon Build.
# docker run --rm \
--name "tflite-example" \
-v /dev:/dev \
-v /tmp:/tmp \
--device-cgroup-rule "c 239:0 rmw" \
torizon/tensorflow-lite-examples-imx95:stable-rc
# docker run --rm \
--name "tflite-example" \
-v /dev:/dev \
-v /tmp:/tmp \
--device-cgroup-rule "c 10:119 rmw" \
torizon/tensorflow-lite-examples-sl1680:4
The preceding command runs a Docker container named tflite-example using the torizon/tensorflow-lite-<platform>:4 image. For the i.MX 95 platform, use the stable-rc tag instead. The container is configured to have access to the device files and temporary files on the host system, which is required for the TensorFlow Lite demo application to function properly and execute on the NPU.
The output of the application shows the inference times for processing a set of images using the NPU:
Images processed: 17
Mean inference time: 0.030311079586253446
Images/s: 32.99123665834442
Std deviation: 0.0001578828954934214
Additional Resources
- AI - Computer Vision - Machine Learning on Toradex Computer on Modules Documentation Overview
- AI, Computer Vision and Machine Learning on Toradex i.MX 95-based Modules
- Build TensorFlow Lite Applications With NPU Support on i.MX 8M Plus-Based Modules on Torizon OS
- Build TensorFlow Lite Applications With NPU Support on i.MX 95-Based Modules on Torizon OS
- Build TensorFlow Lite Applications With NPU Support on SL1680-Based Modules on Torizon OS
- NPU Usage with Reference Images for Yocto Project