• Stars
    star
    244
  • Rank 165,885 (Top 4 %)
  • Language
    Jupyter Notebook
  • Created over 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Notes on Machine Learning on edge for embedded/sensor/IoT uses

Machine learning on embedded devices

Focused primarily on running inference/prediction/feed-forward part on a microcontroller (or small embedded device). Training phase can run on a standard computer/server, using existing tools as much as possible.

Background

What and when to use machine learning

The defaults right now are to do conventional signal processing (no learning) in sensor, and stream raw data to the cloud for storage and processing. Machine learning happens in the cloud. If gateways are used, they mostly forward communication (no data processing).

On-edge processing valueable when

  • Local response needed. Autonomy
  • Adaptable response needed. Over time, in context.
  • Low/predictable latency needed
  • Sending raw sensor data has privacy implications. Audio, video.
  • Unreliable connection
  • High bandwidth sensor input. Audio, video, accelerometer/IMU, current sensor, radiowaves.
  • Low bandwidth algorithm output
  • Events of interest are rare
  • Low energy usage needed
  • Full/raw sensor data is not valuable to store
  • Sensor system should be low cost

Example usecases

  • Predictive maintenance, using audio/vibration data
  • Activitity detection for people, using audio/accelerometer data. Assistive tech, medical
  • Appliance disaggregation, using aggregated power consumption data. "Non-Intrusive Load Monitoring" (NILM)
  • Anomaly/change detection for predictive maintenance, using audio/vibration data, or electrical data
  • Gesture recognition as human input device, using accelerometer/gyro data.
  • Speech/command recognition as human input device, using microphone. Keyword/Wake-word detection
  • Battery saving in wireless sensors. Normally sending day/week aggregates, on event/anomaly detection send data immediately
  • Health status of animals via activity detected using accelerometer
  • Monitoring eating activity using accelerometer 1
  • Environmental monitoring, using microphone to detect unwanted activity like cutting down trees
  • Adaptive signalling and routing for wireless transmission in Wireless Sensor networks
  • Electronic nose using arrays of MEMS detectors
  • Material identification using reflecive spectrometer 1

More notes on Applications

Motivation

  • Why the Future of Machine Learning is Tiny (devices) Tiny Computers are Already Cheap and Everywhere. Energy is the Limiting Factor.We Capture Much More Sensor Data Than We Use.
  • embedded.com: Bringing machine learning to the edge Predictions are much lower bandwidth than the raw sensor data (e.g. video) It allows for local adaptation in the AI logic (L-DNN) It achieves lower latency between observed event and action resulting from AI logic "the most important question is what is the least amount accuracy and computation complexity we can do while still delivering the business value?" Top mistake: "Continuing with the top down approach โ€˜letโ€™s make it perform the task first and then squeeze it on device` instead of switching to bottom up โ€˜letโ€™s make it run on device and fulfill all hardware constraints first, and then tune it for the task at handโ€™."
  • How to run deep learning model on microcontroller with CMSIS-NN. Why run deep learning model on a microcontroller? Sensitive data gets to the cloud, photos, and audio recordings. The company who sells this may charge a service fee to use its service and even worse sell your private data. It won't work without the network connection to the server. Data traveling back and forth between the device and server introduces lag. Require network and wireless hardware components on the circuit design which increase the cost. It might waste bandwidth sending useless data.

State of the Art in 2019

Of ML inference on general-purpose microcontrollers.

TODO: update for 2023
  • Deep models have efficient implementations for ARM Cortex-M. Ex: CNN and RNN in CMSIS-NN, FC in uTensor
  • Some implementations available for non-neural models that can be used. Ex: SVM,RF,AdaBoost in sklearn-porter
  • A few special-designed ML algorithms made. Ex: ProtoNN, Bonsai
  • Basic tools available for converting Tensorflow models
  • Keyword-spotting/wake-word on audio well established. Used in commercial products (Alexa etc)
  • Human activity detecton on accelerometers.
  • Computer vision is actively developed
  • Lots of research and many announcements of low-power co-processors, but little on market yet

Limitations

  • Neural models lacking for non-ARM micros. ESP8266/ESP32
  • Non-neural models missing inference engines designed for microcontrollers
  • "Small DNN" work mostly on computer vision for mobile phones (model size 1000x of uC)
  • Few/no pretrained models available. Transfer learning little explored?
  • Very little documentation of entire development process. From planning, data aquisition, model design
  • Best practices underdocumented (or underdeveloped?)

Ways of advancing, make contributions

  • Faster inference. Power saving, or bigger problems.
  • Smaller models. Cheaper MCU, or bigger problems.
  • Better accuracy on a problem. Better user experience, new usecases
  • Solve a concrete usecase. Easier to deploy similar usecases
  • Comparison between approaches. Microcontroller, ML model
  • Libraries or tools. Lower time to market, enable more developers

Learning material

Books

Articles

Tools

Open-source

  • emlearn. Inference engine for microcontrollers. Supports converting scikit-learn models to plain C code. No dynamic allocations. No runtime needed.
  • TensorFlow Lite for Microcontrollers. Supports neural network models made with TensorFlow (including Keras). Can run on wide range of platforms. Since November 2018. Supports ARM Cortex M, RISC-V, ESP32/Xtensa and Linux/MacOS host. Requires a runtime.
  • nnom - Fixed-point neural network compiler for microcontrollers. Supports wide range of networks. Outputs plain C code. Can use CMSIS-NN on ARM Cortex M.
  • Embedded Learning Library by Microsoft. Set of C++ libraries for machine learning on embedded platforms. Includes code for kNN, RandomForest etc. Also has some node-based dataflow system in place it seems. JavaScript and Python bindings.
  • ONNC project has a backend for ARM Cortex M (using CMSIS-NN) and a C backend. Allows to convert an ONNX models to run on devices.
  • nn4mc_cpp. Neural Networks for Microcontrollers. Supports Keras natively. Provides instructions for PyTorch et.c via ONNX. Documentation for using from Python is lacking, as well as the type of networks supported. Does not seem maintained since 2020.
  • sklearn-porter. Can compile DecisionTreeClassifier and SVC models to C. Uses dynamic memory. Not optimized for use on embedded devices.
  • microTVM. Depends only on the C standard library, and runs bare metal such as STM32 and NRF52 microcontrollers. Is under development. Which models are supported on microcontrollers not specified.

Proprietary

  • X-CUBE-AI for STM32

Models

A range of Machine Learning models are useful in an embedded devices setting. Classical methods are used when the amount of data is quite small, and neural networks for large datasets and complex inputs.

Below are notes on the various models in the context of embedded Machine Learning, including model size and compute-time optimization.

More topics

More Repositories

1

machinehearing

Machine Learning applied to sound
Jupyter Notebook
238
star
2

ESC-CNN-microcontroller

Environmental Sound Classification on Microcontrollers using Convolutional Neural Networks
Jupyter Notebook
95
star
3

projects

Small projects not worthy of dedicated repositories
Jupyter Notebook
42
star
4

idda-knitting-machine

Developing a 3d-printable circular knitting machine
C++
32
star
5

sndflo

Visual programming SuperCollider using Flowhub
SuperCollider
29
star
6

CuraServer

3d-printing slicing server based on Cura, HTTP API
Python
24
star
7

tapecore

Digitally fabricatable machines using low-friction tape for sliding surfaces
Jupyter Notebook
15
star
8

datascience-master

Journal/notes/log of my Masters in Data Science degree
Jupyter Notebook
15
star
9

agree

Introspectable Contracts Programming for JavaScript
CoffeeScript
13
star
10

brewing-audio-event-detection

Tracking beer/wine using Audio Event Detection with Machine Learning
Jupyter Notebook
13
star
11

chrome-webstore-deploy

Python script to automate deploy of Chrome apps/extensions to Chrome Web Store
Python
12
star
12

ipld-image

Images expressed as Interplanetary Linked Data
CoffeeScript
11
star
13

protoflo

Experimental Flowhub-compatible Python FBP runtime
Python
11
star
14

finito

Introspectable, language agnostic, finite state machines
CoffeeScript
8
star
15

javafbp-android

Android components and examples for JavaFBP
Java
8
star
16

UnlockOslo

Software-defined door control
Jupyter Notebook
8
star
17

javafbp-runtime

FBP runtime protocol implementation for JavaFBP
Java
7
star
18

acm2019-compress

Hardware compression for memory
Jupyter Notebook
6
star
19

embayes

Naive Bayes machine-learning classifiers for embedded systems
Python
5
star
20

synchrony

Synchrony: how peoples behavior tend to syncronize
CoffeeScript
3
star
21

declarec

C/C++ definitions generated from json/yaml declarations
CoffeeScript
2
star
22

birddetect

Detecting birdsong using machine learning
Jupyter Notebook
2
star
23

hangdrum

Electronic percussive instrument using capacitive touch (firmware)
C++
2
star
24

deploymentkit

Deploy to any platform with a single package description format
Python
2
star
25

MyEx.AI

Build an Articifial Intelligence of your ex-partner using their online data
JavaScript
2
star
26

micropython-npyfile

Numpy .npy file support for MicroPython - read/write/streaming
Python
1
star
27

gitorious-mrq-monitor

Irc bot monitoring Gitorious merge requests
HTML
1
star
28

fosdem2017-iot-msgflo

Arduino
1
star
29

openl3-hear

OpenL3 for HEAR2021
Python
1
star
30

random

Random thoughts
1
star
31

INF230

Python
1
star
32

penrosediagram

Some music stuffs
HTML
1
star
33

noflo-rpi-testapp

Testing application for NoFlo+node.js on RPi
CoffeeScript
1
star
34

microfridge

Fridge firmware based on MicroFlo
CoffeeScript
1
star
35

bike-sharing-oslo

Project in introduction to Data Science
Jupyter Notebook
1
star
36

gegl-server

An image processing server using GEGL
JavaScript
1
star
37

babl

Personal fork of http://gegl.org/babl
C
1
star