Machine learning for microcontrollers and embedded systems
Project description
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
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.DecisionTreeClassifiereml_net: sklearn.MultiLayerPerceptron, Keras.Sequential with fully-connected layerseml_bayes: sklearn.GaussianNaiveBayes
Feature extraction:
eml_audio: Melspectrogram
Tested running on AVR Atmega, ESP8266, Linux and Windows. Mac OS should also work fine, please file a bug report if it does not.
Installing
Install from PyPI
pip install --user emlearn
Usage
- Train your model in Python
from sklearn.ensemble import RandomForestClassifier
estimator = RandomForestClassifier(n_estimators=10, max_depth=10)
estimator.fit(X_train, Y_train)
...
- Convert it to C code
import emlearn
cmodel = emlearn.convert(estimator, method='inline')
cmodel.save(file='sonar.h')
- 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
Contributors
Jon Nordby
Mark Cooke
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}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file emlearn-0.10.1.tar.gz.
File metadata
- Download URL: emlearn-0.10.1.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa0344f188ecf038c1f6356f2aa54c4deb6f1f2c46951f960f9ebcca73459682
|
|
| MD5 |
e157531b9289afc4ca3ed7b014c3d13c
|
|
| BLAKE2b-256 |
01188f05dbf9240d0d3cee5470456fa5c370858914b9f7885373c506d0cff398
|