Welcome to the second article about running machine learning algorithms on microcontrollers.

In the previous article, we have created and trained a simple Keras model that was able to classify 3 different classes from CIFAR-10 dataset.

We looked at how to prepare that model for running on a microcontroller, quantized it and saved it to disk as a C file.

It is now time to look at how to setup the development environment and how to run inference on an actual microcontroller.

For this we will need two things to follow along. First, we will need to clone MicroMl project, which will provide us with the example code.

Second, we will need some kind of ARM development board. Example code uses ST’s Nucleo-F767ZI board. For demonstration, we will stick with the preferred choice, as we can run the example code as it is, no modifications needed.

If we do not have that specific board at hand, no need to worry! MicroML was created with customization in mind, so we will show you how to modify code so you can make it run on the development board of your choice.

One thing before we start, it is recommended to read the prerequisites section of README.md of MicroML, so you can see what you will need to get this project running on Windows or Linux.

1. Setup

We will start by cloning MicroMl repo recursively, and changing to keras_article branch.

git clone --recurse-submodules https://github.com/SkobecSlo/MicroML.git
git checkout keras_article

NOTE: MicroML pulls in whole TensorFlow library, which is around 2.5 GB big. For this step to take some time is perfectly normal.

TensorFlow setup

Before we can even compile a simple example for our target, we need to run a hello_world example that will be executed on our host machine. This is needed because makefiles written by TensorFlow team pull in several necessary repositories from third parties, which are missing by default. After compilation, these libraries can be found under tensorflow/lite/micro/tools/make/downloads. To get them, we first move inside tensorflow folder and run make:

cd MicroMl/tensorflow
sudo make -f tensorflow/lite/micro/tools/make/Makefile hello_world

#tensorflow #keras #microcontrollers #machine-learning #embedded-systems

Part 2: Creating a Simple Keras Model for Inference on Microcontrollers
3.10 GEEK