Skip to main content

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
  • C classifier accessible in Python using pybind11

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: Random Forests, ExtraTrees
  • eml_net: MultiLayerPerceptron
  • eml_bayes: 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 and emlearn.ino

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

emlearn-0.3.1.tar.gz (23.8 kB view details)

Uploaded Source

File details

Details for the file emlearn-0.3.1.tar.gz.

File metadata

  • Download URL: emlearn-0.3.1.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.0 CPython/3.6.3

File hashes

Hashes for emlearn-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b2552398e776dac4cf20943862de680201f74393fe383611fbef9cd60f013e2f
MD5 7ea19e57c8d8cb4c468202df6af4172a
BLAKE2b-256 de0281000da0e679274d4f599a1622fcf8d0b4a6752201f3f80b3c4bec33e239

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page