How can we train a model on microcontrollers?
In every project presented in this book, we have discussed how to run model inference on microcontrollers and demonstrated that even a model like MobileNet v2 can be deployed on these devices. However, is it possible to train a neural network on microcontrollers?
In this recipe, we will answer this question and provide an example of training a simple neural network using backpropagation on the Arduino Nano and Raspberry Pi Pico with the CMSIS-DSP library.
The network will be trained to return the result of the following logical (exclusive OR) XOR and NOT-AND (NAND) operators:
Figure 12.1: The logical XOR and NAND operators
As you can see from the preceding image, the result of the XOR operator is 1 when the binary inputs a and b are different. On the other hand, the output of the NAND operator is 1 when at least one of the binary inputs, a or b, is 0.
Getting ready
Training an ML model using the microcontroller...