Skip to main content

PyPI version

Micro-learn is a Python library for converting machine learning models trained using scikit-learn into inference code that can run on virtually any microcontroller in real time.

Machine learning algorithms typically require heavy computing and memory resources in the training phase, far greater than what a typical constrained microcontroller can offer. However, post training, many of these algorithms boil down to simple parameters that require simple arithmetic and logical operations for inference. These can easily run on microcontrollers in real time. In a nutshell, train your ML models on a resource-abundant machine using scikit-learn and, with a single line of code, export that trained model into C++/Arduino code using micro-learn!

All the inference algorithms are optimized for microcontrollers and require least possible arithmetic computations. For example, division operations have been converted to multiplications since the latter is much more computationally efficient in microcontrollers. Note that all the algorithms are exact and not approximate. Please refer to my ACM paper for more insights.

Installation

Dependencies

  • Python (>= 3.6)
  • NumPy (>= 1.13.3)

User Installation

Use Python3 pip to install the latest micro-learn package.

pip install micro-learn

Supported Algorithms

The following scikit-learn models are supported as of now:

Supervised Learning (Classification)

  • Perceptron
  • Logistic Regression (Logit)
  • Gaussian Naive Bayes (GNB)
  • Passive-Aggressive Classifier (PA)
  • Linear Discriminant Analysis (LDA)
  • Quadratic Discriminant Analysis (QDA)
  • Support Vector Machine (SVM) (Linear Kernel)

Note that only binary-class classification is supported as of now. Support for multi-class classification coming soon!

Supervised Learning (Regression)

  • Linear Regression (LR)

Unsupervised Learning (Clustering)

  • KMeans

Unsupervised Learning (Dimensionality Reduction)

  • Principal Component Analysis (PCA)

Support for other scikit-learn models coming soon!

Usage

Train any of the supported machine learning models using scikit-learn and simply pass this trained model to micro-learn's Offload(). Example for Gaussian Naive Bayes is shown below. All other supported algorithms follow the exact same sequence. For SVM and PCA (scale-variant algorithms), an optional StandardScaler object can be passed as a second argument to Offload().

>>> from sklearn.naive_bayes import GaussianNB
>>> gnb = GaussianNB()
>>> gnb.fit(X, Y)
>>> from microlearn.offloader import Offload
>>> off = Offload(gnb) #Simply pass your trained model!
>>> off.export_to_arduino('/home/adarsh1001/gnb.ino')

And that's it! The output Arduino template will have the corresponding ML inference code along with all the trained parameters. After exporting, open the .ino file and edit the data section and the output class label section as per your need. And of course, since the Arduino programming language is a derivative of C/C++, you can directly edit the template and convert it into a generic .c or .cpp code. For a more detailed guide, you can check out my medium post on this.

Project History

I started working on embedded machine learning, both from a theoretical as well as practical perspective, in August 2019 as part of my MS. In November 2019, my paper on a related topic was accepted in ACM SAC. The work on coding a unified library for offloading trained ML models to microcontroller code (micro-learn) was started in May 2020.

Citation

If you use micro-learn in a scientific publication, please do cite my paper.

Metadata

Release files for micro-learn 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for micro-learn 0.0.4
File Size Uploaded Provenance Actions
micro-learn-0.0.4.tar.gz 7.8 kB Without provenance Details for micro-learn-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for micro-learn 0.0.4
File Interpreter ABI Platform Actions
micro_learn-0.0.4-py3-none-any.whl Python 3 none any Details for micro_learn-0.0.4-py3-none-any.whl

Total release size: 22.6 kB

Release files / micro-learn-0.0.4.tar.gz

Download URL micro-learn-0.0.4.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3c997f0da0b6f396cb2da83f9d586bc261f5a529ecbc5f8c6a670994c1fd7d8e
BLAKE2b-256 checksum
How to use checksums
905abb6817f483a8ae24449ff7eebd7d327523efe08e9379c6408a1dcfbb62aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Release files / micro_learn-0.0.4-py3-none-any.whl

Download URL micro_learn-0.0.4-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8d2f56b020c4a1c2af5f1048058b361e53c71174e72ab2132ed91b231f716bd
BLAKE2b-256 checksum
How to use checksums
4ce70e5a9682c282395dc154ea332118ef6722f84c67a824fa0010fdec1ba233
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Security for micro-learn 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page