TinyML Cookbook

Book description

Work through over 50 recipes to develop smart applications on Arduino Nano 33 BLE Sense and Raspberry Pi Pico using the power of machine learning

Key Features

  • Train and deploy ML models on Arduino Nano 33 BLE Sense and Raspberry Pi Pico
  • Work with different ML frameworks such as TensorFlow Lite for Microcontrollers and Edge Impulse
  • Explore cutting-edge technologies such as microTVM and Arm Ethos-U55 microNPU

Book Description

This book explores TinyML, a fast-growing field at the unique intersection of machine learning and embedded systems to make AI ubiquitous with extremely low-powered devices such as microcontrollers.

The TinyML Cookbook starts with a practical introduction to this multidisciplinary field to get you up to speed with some of the fundamentals for deploying intelligent applications on Arduino Nano 33 BLE Sense and Raspberry Pi Pico. As you progress, you’ll tackle various problems that you may encounter while prototyping microcontrollers, such as controlling the LED state with GPIO and a push-button, supplying power to microcontrollers with batteries, and more. Next, you’ll cover recipes relating to temperature, humidity, and the three “V” sensors (Voice, Vision, and Vibration) to gain the necessary skills to implement end-to-end smart applications in different scenarios. Later, you’ll learn best practices for building tiny models for memory-constrained microcontrollers. Finally, you’ll explore two of the most recent technologies, microTVM and microNPU that will help you step up your TinyML game.

By the end of this book, you’ll be well-versed with best practices and machine learning frameworks to develop ML apps easily on microcontrollers and have a clear understanding of the key aspects to consider during the development phase.

What you will learn

  • Understand the relevant microcontroller programming fundamentals
  • Work with real-world sensors such as the microphone, camera, and accelerometer
  • Run on-device machine learning with TensorFlow Lite for Microcontrollers
  • Implement an app that responds to human voice with Edge Impulse
  • Leverage transfer learning to classify indoor rooms with Arduino Nano 33 BLE Sense
  • Create a gesture-recognition app with Raspberry Pi Pico
  • Design a CIFAR-10 model for memory-constrained microcontrollers
  • Run an image classifier on a virtual Arm Ethos-U55 microNPU with microTVM

Who this book is for

This book is for machine learning developers/engineers interested in developing machine learning applications on microcontrollers through practical examples quickly. Basic familiarity with C/C++, the Python programming language, and the command-line interface (CLI) is required. However, no prior knowledge of microcontrollers is necessary.

Table of contents

  1. TinyML Cookbook
  2. Foreword
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
    4. Download the color images
    5. Conventions used
    6. Sections
      1. Getting ready
      2. How to do it…
      3. There's more…
    7. Get in touch
    8. Share Your Thoughts
  7. Chapter 1: Getting Started with TinyML
    1. Technical requirements
    2. Introducing TinyML
      1. What is TinyML?
      2. Why ML on microcontrollers?
      3. Why run ML locally?
      4. The opportunities and challenges for TinyML
      5. Deployment environments for TinyML
      6. tinyML Foundation
    3. Summary of DL
      1. Deep neural networks
      2. Convolutional neural networks
      3. Quantization
    4. Learning the difference between power and energy
      1. Voltage versus current
      2. Power versus energy
    5. Programming microcontrollers
      1. Memory architecture
      2. Peripherals
    6. Presenting Arduino Nano 33 BLE Sense and Raspberry Pi Pico
    7. Setting up Arduino Web Editor, TensorFlow, and Edge Impulse
      1. Getting ready with Arduino Web Editor
      2. Getting ready with TensorFlow
      3. Getting ready with Edge Impulse
      4. How to do it…
    8. Running a sketch on Arduino Nano and Raspberry Pi Pico
      1. Getting ready
      2. How to do it…
    9. Join us on Discord!
  8. Chapter 2: Prototyping with Microcontrollers
    1. Technical requirements
    2. Code debugging 101
      1. Getting ready
      2. How to do it...
      3. There's more
    3. Implementing an LED status indicator on the breadboard
      1. Getting ready
      2. How to do it...
    4. Controlling an external LED with the GPIO
      1. Getting ready
      2. How to do it...
    5. Turning an LED on and off with a push-button
      1. Getting ready
      2. How to do it...
    6. Using interrupts to read the push-button state
      1. Getting ready
      2. How to do it...
    7. Powering microcontrollers with batteries
      1. Getting started
      2. How to do it...
      3. There's more
  9. Chapter 3: Building a Weather Station with TensorFlow Lite for Microcontrollers
    1. Technical requirements
    2. Importing weather data from WorldWeatherOnline
      1. Getting ready
      2. How to do it…
    3. Preparing the dataset
      1. Getting ready
      2. How to do it…
    4. Training the ML model with TF
      1. Getting ready
      2. How to do it…
    5. Evaluating the model's effectiveness
      1. Getting ready
      2. How to do it…
    6. Quantizing the model with the TFLite converter
      1. Getting ready
      2. How to do it…
    7. Using the built-in temperature and humidity sensor on Arduino Nano
      1. Getting ready
      2. How to do it…
    8. Using the DHT22 sensor with the Raspberry Pi Pico
      1. Getting ready
      2. How to do it…
    9. Preparing the input features for the model inference
      1. Getting ready
      2. How to do it…
    10. On-device inference with TFLu
      1. Getting ready
      2. How to do it…
  10. Chapter 4: Voice Controlling LEDs with Edge Impulse
    1. Technical requirements
    2. Acquiring audio data with a smartphone
      1. Getting ready
      2. How to do it…
    3. Extracting MFCC features from audio samples
      1. Getting ready
      2. How to do it…
      3. There's more…
    4. Designing and training a NN model
      1. Getting ready
      2. How to do it…
    5. Tuning model performance with EON Tuner
      1. Getting ready
      2. How to do it…
    6. Live classifications with a smartphone
      1. Getting ready
      2. How to do it…
    7. Live classifications with the Arduino Nano
      1. Getting ready
      2. How to do it…
    8. Continuous inferencing on the Arduino Nano
      1. Getting ready
      2. How to do it…
    9. Building the circuit with the Raspberry Pi Pico to voice control LEDs
      1. Getting ready
      2. How to do it…
    10. Audio sampling with ADC and timer interrupts on the Raspberry Pi Pico
      1. Getting ready
      2. How to do it…
      3. There's more…
  11. Chapter 5: Indoor Scene Classification with TensorFlow Lite for Microcontrollers and the Arduino Nano
    1. Technical requirements
    2. Taking pictures with the OV7670 camera module
      1. Getting ready
      2. How to do it...
    3. Grabbing camera frames from the serial port with Python
      1. Getting ready
      2. How to do it...
    4. Converting QQVGA images from YCbCr422 to RGB888
      1. Getting ready
      2. How to do it...
    5. Building the dataset for indoor scene classification
      1. Getting ready
      2. How to do it...
    6. Transfer learning with Keras
      1. Getting ready
      2. How to do it...
    7. Preparing and testing the quantized TFLite model
      1. Getting ready
      2. How to do it...
    8. Reducing RAM usage by fusing crop, resize, rescale, and quantize
      1. Getting ready
      2. How to do it...
  12. Chapter 6: Building a Gesture-Based Interface for YouTube Playback
    1. Technical requirements
    2. Communicating with the MPU-6050 IMU through I2C
      1. Getting ready
      2. How to do it…
    3. Acquiring accelerometer data
      1. Getting ready
      2. How to do it…
    4. Building the dataset with the Edge Impulse data forwarder tool
      1. Getting ready
      2. How to do it…
    5. Designing and training the ML model
      1. Getting ready
      2. How to do it…
    6. Live classifications with the Edge Impulse data forwarder tool
      1. Getting ready
      2. How to do it…
    7. Gesture recognition on Raspberry Pi Pico with Arm Mbed OS
      1. Getting ready
      2. How to do it…
    8. Building a gesture-based interface with PyAutoGUI
      1. Getting ready
      2. How to do it…
  13. Chapter 7: Running a Tiny CIFAR-10 Model on a Virtual Platform with the Zephyr OS
    1. Technical requirements
    2. Getting started with the Zephyr OS
      1. Getting ready
      2. How to do it…
    3. Designing and training a tiny CIFAR-10 model
      1. Getting ready
      2. How to do it…
    4. Evaluating the accuracy of the TFLite model
      1. Getting ready
      2. How to do it…
    5. Converting a NumPy image to a C-byte array
      1. Getting ready
      2. How to do it…
    6. Preparing the skeleton of the TFLu project
      1. Getting ready
      2. How to do it…
    7. Building and running the TFLu application on QEMU
      1. Getting ready
      2. How to do it…
    8. Join us on Discord!
  14. Chapter 8: Toward the Next TinyML Generation with microNPU
    1. Technical requirements
    2. Setting up Arm Corstone-300 FVP
      1. Getting ready
      2. How to do it…
    3. Installing TVM with Arm Ethos-U support
      1. Getting ready
      2. How to do it…
    4. Installing the Arm toolchain and Ethos-U driver stack
      1. Getting ready
      2. How to do it…
    5. Generating C code with TVM
      1. Getting ready
      2. How to do it…
    6. Generating C-byte arrays for input, output, and labels
      1. Getting ready
      2. How to do it…
    7. Building and running the model on Ethos-U55
      1. Getting ready
      2. How to do it…
    8. Why subscribe?
  15. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: TinyML Cookbook
  • Author(s): Gian Marco Iodice
  • Release date: April 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781801814973