Skip to content

MAMKramer/TinyML-Cookbook_2E

 
 

Repository files navigation

TinyML Cookbook, Second Edition

TinyML Cookbook, Second Edition

This is the code repository for TinyML Cookbook, Second Edition, published by Packt.

Combine machine learning with microcontrollers to solve real-world problems

Author: Gian Marco Iodice
Publisher: Packt

About the book

This book is about tinyML, the technology that allows smartness in a minimally intrusive way using machine learning (ML) on low-powered devices like microcontrollers. Whether new to this field or looking to expand your ML knowledge, this improved second edition of TinyML Cookbook has something for all. Each chapter is structured to be a self-contained project to learn how to use some of the key tinyML technologies, such as Arduino, CMSIS-DSP, Edge Impulse, emlearn, Raspberry Pi Pico SDK, TensorFlow, TensorFlow Lite for Microcontrollers, and Zephyr.

This second edition includes new recipes featuring:

  • LSTM neural network to recognize music genres
  • Edge Impulse Faster-Objects-More-Objects (FOMO) algorithm for detecting objects in a scene.
  • TVM for the Arduino Nano 33 BLE Sense, Raspberry Pi Pico, and SparkFun RedBoard Artemis Nano model deployment
  • On-device learning to train models on microcontrollers
  • Emlearn to deploy scikit-learn trained models on microcontrollers.

TinyML Cookbook is a practical book with a focus on the principles. Although most of the presented projects are based on the Arduino Nano 33 BLE Sense Rev1 and Rev2 and Raspberry Pi Pico, this second edition also features the SparkFun RedBoard Artemis Nano to help you practice the learned principles on an alternative microcontroller. Therefore, by the end of this book, you will be well-versed in best practices and ML frameworks to develop ML applications easily on microcontrollers.

Who is this book for

Whether you are an enthusiast or professional with a basic familiarity with ML and an interest in developing ML applications on microcontrollers through practical examples, this book is for you. TinyML Cookbook will help you expand your knowledge of tinyML by building end-to-end projects with real-world data sensors on Arduino Nano 33 BLE Sense, Raspberry Pi Pico, and SparkFun RedBoard Artemis Nano. While familiarity with C/C++, Python programming, and command-line interface (CLI) is required, no prior knowledge of microcontrollers is necessary.

Technical requirements

For most of the chapters, with the only exception of Chapter 10, Deploying a CIFAR-10 Model for Memory-Constrained Devices with Zephyr OS on QEMU, you will need a computer (either a laptop or desktop) running Linux (preferably Ubuntu 20.04+), macOS, or Windows operating systems on an x86_64 architecture. Additionally, your computer should have a minimum of two USB ports. In Chapter 10, you will specifically require a computer running either Linux (preferably Ubuntu 20.04+) or macOS on an x86_64 architecture.

⚠️ It is worth noting that most projects can also be developed on Macs powered by Apple silicon, such as M1 or M2 chips. However, at the time of writing, there is no support for the SparkFun RedBoard Artemis Nano on Apple silicon devices.

The only software prerequisites for your computer are:

  • Python (Python 3.7+)
  • Text editor (for example, gedit on Ubuntu)
  • Media player (for example, VLC)
  • Image viewer (for example, the default app in Ubuntu or Windows 10)
  • Web browser (for example, Google Chrome)

During our tinyML journey, we will require different software tools to cover ML development and embedded programming. Thanks to Arduino, Edge Impulse, and Google, these tools will be in the cloud, browser-based, and with a free plan for our usage. You can develop projects on the Arduino Nano 33 BLE Sense and Raspberry Pi Pico directly in your web browser using the Arduino Web Editor.

⚠️ For projects involving the SparkFun RedBoard Artemis Nano, you must use the local Arduino IDE. You can find the setup instructions for developing projects on this microcontroller by following this link.

ℹ️ You may also consider using the local Arduino IDE the Arduino Nano 33 BLE Sense and Raspberry Pi Pico following the instructions provided at this link.

The projects we will develop together require sensors and additional electronic components to build realistic tinyML prototypes and experience the complete development workflow. These components are listed at the beginning of each chapter and in the README.md file within the corresponding chapter folder on GitHub:

Chapter
2: Unleashing Your Creativity with Microcontrollers
3: Building a Weather Station with TensorFlow Lite for Microcontrollers
4: Using Edge Impulse and the Arduino Nano to Control LEDs with Voice Commands
5: Recognizing Music Genres with TensorFlow and the Raspberry Pi Pico - part1
6: Recognizing Music Genres with TensorFlow and the Raspberry Pi Pico - part2
7: Detecting objects with Edge Impulse using FOMO on the Raspberry Pi Pico
8: Classifying Desk Objects with TensorFlow and the Arduino Nano
9: Building a Gesture-Based Interface for YouTube Playback with Edge Impulse and the Raspberry Pi Pico
10: Deploying a CIFAR-10 Model for Memory-Constrained Devices with Zephyr OS on QEMU
11: Running ML models on the Arduino and Arm Ethos-U55 microNPU using Apache TVM
12: Enabling Compelling tinyML Solutions with On-Device Learning and Scikit-Learn on the Arduino Nano and Raspberry Pi Pico

Don't worry if you are an electronics beginner. You will learn more about electronic components such as LEDs, push-buttons, and resistors in the first two chapters of this book. Furthermore, we have prepared this beginner shopping list so you know precisely what to buy.

Citation

To cite TinyML Cookbook - Second Edition in publications use:

@book{iodice2023tinymlcookbook2e,
  title={TinyML Cookbook, Second Edition: Combine machine learning with microcontrollers to solve real-world problems},
  author={Gian Marco Iodice},
  year={2023},
  publisher={Packt},
  isbn = {9781837637362},
  url = {https://www.packtpub.com/product/tinyml-cookbook-second-edition/9781837637362}
}

Know more on the Discord server Coding

You can get more engaged on the discord server for more latest updates and discussions in the community at Discord

Download a free PDF Coding

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost. Simply click on the link to claim your free PDF. Free-Ebook Coding

We also provide a PDF file that has color images of the screenshots/diagrams used in this book at GraphicBundle Coding

Get to know the Author

Gian Marco Iodice is an experienced Edge and mobile computing specialist at Arm for machine learning (ML). He is also chair of the global meetups for the tinyML foundation since 2022.

He received the MSc with honors in electronic engineering from the University of Pisa (Italy), where he specialized in HW/SW co-design for embedded systems.

At Arm, he leads the engineering developments for the Arm Compute Library, which he co-created in 2017 to run ML workloads as efficiently as possible on Arm processors. Arm Compute Library, designed to deliver the best performance across Arm Cortex-A CPUs and Mali GPUs, is deployed on billions of devices worldwide – from servers to smartphones.

Gian Marco's specialization lies in optimizing algorithms for resource-constrained devices, which is crucial to bringing ML and computer vision (CV) capabilities to various devices, including mobile and IoT devices. Some of his relevant optimizations have been for the matrix multiplication routines and stereo vision algorithms on Arm Mali GPUs and Arm Cortex-A CPUs.

In 2023, he collaborated with the University of Cambridge to integrate ML functionalities on an Arm Cortex-M microcontroller powered by algae. This ground-breaking work was showcased at the tinyML EMEA Innovation Forum in Amsterdam in June of the same year.

In 2023, Gian Marco contributed to the development of the EdTech for Good Curation Framework. This framework, developed by UNICEF in collaboration with Arm and the Asian Development Bank (ADB), represents a significant step forward in the responsible use of technology in education. It enables public entities and international organizations to evaluate digital educational technologies, prioritizing learning outcomes and children's safety.

Other Related Books

About

TinyML Cookbook, 2E_Published by Packt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 76.9%
  • Jupyter Notebook 14.1%
  • C++ 7.2%
  • Python 1.3%
  • Makefile 0.5%