Skip to content
Machine Learning inference engine for Microcontrollers and Embedded devices
Python C C++
Branch: master
Clone or download
Latest commit 1d11bbf Jun 7, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bindings trees: Default to using float datatype Jun 7, 2019
docs
emlearn trees: Default to using float datatype Jun 7, 2019
examples trees: Default to using float datatype Jun 7, 2019
test
.appveyor.yml appveyor: Also install ffmpeg Mar 6, 2019
.gitignore
.travis.yml Travis: Build docs Mar 10, 2019
LICENSE.md
MANIFEST.in
README.md docs: Initial Sphinx setup Mar 10, 2019
TODO.md Update TODO Nov 25, 2018
emlearn.ino Run test on Arduino Nov 25, 2018
requirements.dev.txt Fix recommonmark version Mar 10, 2019
requirements.txt Only dev-dep on scikit-learn Oct 20, 2018
setup.py Release 0.9.0 Jun 7, 2019

README.md

Travis CI Build Status Appveyor Build status DOI

emlearn

Machine learning for microcontroller and embedded systems. Train in Python, then do inference on any device with a C99 compiler.

Key features

Embedded-friendly Inference

  • Portable C99 code
  • No libc required
  • No dynamic allocations
  • Support integer/fixed-point math
  • Single header file include

Convenient Training

  • Using Python with scikit-learn or Keras
  • The generated C classifier is also accessible in Python

MIT licensed

Can be used as an open source alternative to MATLAB Classification Trees, Decision Trees using MATLAB Coder for C/C++ code generation. fitctree, fitcensemble, TreeBagger, ClassificationEnsemble, CompactTreeBagger

Status

Minimally useful

Classifiers:

  • eml_trees: sklearn.RandomForestClassifier, sklearn.ExtraTreesClassifier, sklearn.DecisionTreeClassifier
  • eml_net: sklearn.MultiLayerPerceptron, Keras.Sequential with fully-connected layers
  • eml_bayes: sklearn.GaussianNaiveBayes

Feature extraction:

  • eml_audio: Melspectrogram

Tested running on AVR Atmega, ESP8266 and Linux.

Installing

Install from PyPI

pip install --user emlearn

Usage

  1. Train your model in Python
from sklearn.ensemble import RandomForestClassifier
estimator = RandomForestClassifier(n_estimators=10, max_depth=10)
estimator.fit(X_train, Y_train)
...
  1. Convert it to C code
import emlearn
cmodel = emlearn.convert(estimator, method='inline')
cmodel.save(file='sonar.h')
  1. Use the C code
#include "sonar.h"

const int32_t length = 60;
int32_t values[length] = { ... };
const int32_t predicted_class = sonar_predict(values, length):

For full example code, see examples/digits.py

Citations

If you use emlearn in an academic work, please reference it using:

@misc{emlearn,
  author       = {Jon Nordby},
  title        = {{emlearn: Machine Learning inference engine for 
                   Microcontrollers and Embedded Devices}},
  month        = mar,
  year         = 2019,
  doi          = {10.5281/zenodo.2589394},
  url          = {https://doi.org/10.5281/zenodo.2589394}
}
You can’t perform that action at this time.