ML for Embedded Software Engineers: a pragmatic approach [pt.1]
May 16, 2020machinelearning embeddesystems
Last October, I met Jacob Beningo and he asked me if I was curious about Machine Learning applications for embedded systems. I had some general ideas of Machine Learning: something from my Master’s, something from my job in Zerynth and Skypersonic, something from everyone-on-the-internet-talking-about-machine-learning.
But I never had the opportunity to really get into it, so why not?
Working with embedded systems, especially IoT, I happened to hear about Machine Learning moving to the edge. It was difficult to understand, though, if there was a balance between the hype and practical use-cases.
In this article, I will report something I found helpful to start with Machine Learning as an embedded software engineer, trying to reach the point without getting lost into such an immense field. This path, not as linear as reported here, led me to the Object Classification techniques using the OpenMV Cam H7 talk I prepared for the Embedded Online Conference.
Where to start?
First things first, Jacob pointed me to the OpenMV project. I received an OpenMV Cam H7 (STM32H7-based board) to play with, and I found the whole environment well thought, well written, and well documented. The OpenMV project actually targets Machine Vision for embedded systems, and Machine Learning capabilities have been added recently exclusively to deal with some kind of Machine Vision problems.
Though not having Machine Learning as its primary focus, I definitely recommend the OpenMV Cam: it just works, and I think the Machine Learning component of the project is destined to grow. It allows you to test the examples in a few minutes, and to move on, after getting a high-level idea, into its opensource, well-organized codebase.
After playing a bit with it, I felt I needed a bit more context, and this is when a book, and a guide, both freely available, came to help me. Embedded Machine Learning Design for dummies, Arm Special Edition, and The Ultimate Guide to Machine Learning for Embedded Systems by RealityAI. They both do an excellent job highlighting the whys of Machine Learning for embedded systems and providing real-world examples. The RealityAI guide gives practical advice that makes you think they are definitely finding a purpose for these techniques on the field.
First steps into practice
Seen examples running, and understood a bit of the theory and the reasons behind them, I was ready to learn a bit more getting my hands dirty. You will have to wait for the talk to be released to precisely understand what my next step was, but I can already tell you it involved model training, conversion to fit an embedded device, and the right amount of tinkering with the firmware.
To go further, I needed more specific material related to Tensorflow Lite for microcontrollers (TF Lite µ), particular deep-learning techniques and models, and optimizations for arm cortex-m devices.
It was not available at the time, but if I had to start again with TF Lite µ, I would definitely go with Pete Warden’s screencast Introduction to TFLite for Microcontrollers.
What I can suggest next is the arm guide Machine Learning on Arm Cortex-M Microcontrollers. It is not an easy read, but it introduces numbers and a lot of concepts that, even if not grasped immediately, will come up in the future: then you will know where to look back.
For the pure Machine Learning part, I relied a lot on the Towards Data Science project: it contains both great, and not very good articles. What I recommend is to do a bit of research on the author of the post if you are not sure about the quality of the content.
One article I particularly enjoyed is Understanding binary cross-entropy/log loss: a visual explanation. I think it represents the kind of article making no sense for you to read (as an embedded software engineer just starting with ML) before having a real need. But when you have a specific, practical choice to deal with, it has the perfect balance between math and visualization to make the topic as clear as it needs to be.
It may not be the best approach scientifically speaking, but I find mixing bottom-up and top-down strategies a pragmatic way to learn something new without getting lost. Start with an example, then go with a bit of theory that allows moving to more complex cases and put new concepts in practice. Then fill the holes in your knowledge learning to ask yourself the right questions and wondering about the proper choices to make.
I also want to mention an outstanding tool that helped me a lot both during the theory and the practice: Netron is a visualizer for neural networks that will clear your mind.
I hope this makes sense to you and makes you feel less disoriented approaching something as huge as Machine Learning, which also looks far from the daily topics of an embedded software engineer.
Now read and practice. This is the end of part 1, and I promise the next part will be softer!