Deploying MobileNet on Microcontrollers

Training and deploying MobileNet models to microcontroller hardware just got a lot easier.

Squeezing the MobileNet lemon (📷: Eloquent Arduino)

It might seem that all the excitement in the machine learning world is focused on the new generation of large language models (LLMs). But before we got excited about LLMs, we were all excited by embedded machine learning — what’s called tinyML — and it just became a lot easier to deploy MobileNet models onto really tiny hardware.

These models are small, and can be parameterized to meet the resource constraints in low-latency, and low-power environments. Useful for object detection, classification, or even for image segmentation, MobileNet models are amongst the most popular, and heavily used, in the tinyML world. I use them extensively in my own projects, and they were my go to model when I did the early benchmarking work on the new generation of accelerator hardware.

But deploying a models to microcontrollers using a big framework, like TensorFlow Lite for Microcontrollers, involves a lot of dependencies. Just getting your firmware to build can be challenging. But deploying MobileNetV1 onto tiny hardware just got a lot easier thanks to Simone Salerno.

Salerno has built a framework that allows you to train a MobileNet model on your laptop using Keras and Tensorflow in Python, and then afterwards, you can export the trained model as native C++ code that you can include inside your microcontroller firmware.

This is a fully self-contained, statically allocated class that implements the MobileNet variation of choice. It doesn't required external runtimes to run, doesn't require a TENSOR_ARENA_SIZE to be defined beforehand, doesn't throw cryptic errors during compilation nor execution. It is written as plain C++ and doesn't contain any vendor-specific optimizations at the moment (e.g. CMSIS for ARM Cortex chipsets). They will be added in future versions, if demand supports the effort.

To use the trained model inside the Arduino environment, or anywhere else, you need to just include the generated class. That's it. No dependencies, no complications.

More information can be found in Salerno's blog post, including a full end-to-end walkthrough on how to train and deploy a model. The source code for the framework can be found on GitHub.

Alasdair Allan
Scientist, author, hacker, maker, and journalist. Building, breaking, and writing. For hire. You can reach me at 📫 alasdair@babilim.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles