Tiny Machine Learning (TinyML) on Raspberry Pi Pico with Tensorflow Lite Micro and Arducam Featuring Person Detection

TensorFlow Lite for Microcontrollers is designed to run machine learning models on microcontrollers and other devices with only a few kilobytes of memory.

It supports microcontroller platforms like Arduino Nano 33 BLE Sense, ESP32, STM32F746 Discovery kit, and so on. Since the release of the $4 Raspberry Pi Pico, which has gained increasing popularity among makers, Arducam has been trying to bring what’s possible on other microcontroller platforms to the Pico.

This article is a tutorial on using the machine learning framework Tensorflow Lite Micro on the Pico for Person Detection.

Getting started

See Getting Started with the Raspberry Pi Pico and the README in the pico-sdk for information on getting up and running.

Quick Pico Setup

If you are developing for Raspberry Pi Pico on the Raspberry Pi 4B, or the Raspberry Pi 400, most of the installation steps in this Getting Started guide can be skipped by running the setup script. You can get this script by doing the following:

Then run:

The script will:

  • Create a directory called pico
  • Install required dependencies
  • Download the pico-sdk, pico-examples, pico-extras, and pico-playground repositories
  • Define PICO_SDK_PATH, PICO_EXAMPLES_PATH, PICO_EXTRAS_PATH, and PICO_PLAYGROUND_PATH in your ~/.bashrc
  • Build the blink and hello_world examples in pico-examples/build/blink and pico-examples/build/hello_world
  • Download and build picotool (see Appendix B). Copy it to /usr/local/bin. • Download and build picoprobe (see Appendix A).
  • Download and compile OpenOCD (for debug support)
  • Download and install Visual Studio Code
  • Install the required Visual Studio Code extensions (see Chapter 6 for more details)
  • Configure the Raspberry Pi UART for use with Raspberry Pi Pico

Once it has run, you will need to reboot your Raspberry Pi,

Person Detection

Person Detection Diagram

Image for post
Image for post
  • Download RPI-Pico-Cam
  • Compile

Tip

If you don’t want to compile, you can use the above pre-built uf2 file, you only need to wire the hardware and download uf2 to the device.

Image for post
Image for post

Then you will create some files under RPI-Pico-Cam/tflmicro/build/examples/person_detection path

BinDescriptionperson_detection_int8.uf2This is the main program of person_detection, which can be dragged onto the RP2040 USB Mass Storage Device.person_detection_benchmark.uf2This is the benchmark program of person_detection, you can use it to test the performance of person_detection on pico.image_provider_benchmark.uf2This is the benchmark program of image_provider, you can use it to test the performance of image data acquisition.

Image for post
Image for post

Test Person Detection

AppDescriptionperson_detection_int8This is a person detection demo.

  • Hardware connection
Image for post
Image for post
  • Load and run person_detection The simplest method to load software onto a RP2040-based board is by mounting it as a USB Mass Storage Device. Doing this allows you to drag a file onto the board to program the flash. Go ahead and connect the Raspberry Pi Pico to your Raspberry Pi using a micro-USB cable, making sure that you hold down the BOOTSEL button to force it into USB Mass Storage Mode.

If you are logged in via ssh for example, you may have to mount the mass storage device manually:

If you can see the files in /mnt/pico then the USB Mass Storage Device has been mounted correctly:

Copy your person_detection_int8.uf2 onto RP2040:

View output

The person detection example outputs some information through usb, you can use minicom to view:

Image for post
Image for post

This person detection example also outputs image data and person detection results to the UART, and we provide a processing program to display them:

Tip:

You can download the Processing here or Processing for Pi.

Image for post
Image for post
Image for post
Image for post

Learning More

Camera solutions expert for embedded systems - like Raspberry Pi, NVIDIA Jetson, Arduino — from lens to sensor to driver to PCB and industrial design.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store