Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Commit

Permalink
fix includes
Browse files Browse the repository at this point in the history
  • Loading branch information
agrimagsrl committed Nov 28, 2019
1 parent 0ccb4b6 commit 9989cdc
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
10 changes: 10 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ setup.py
micromlgen/__init__.py
micromlgen/micromlgen.py
micromlgen/micromlgen_test.py
micromlgen/templates/binary_classification.jinja
micromlgen/templates/classmap.jinja
micromlgen/templates/compute_class.jinja
micromlgen/templates/compute_decisions.jinja
micromlgen/templates/compute_kernels.bck.jinja
micromlgen/templates/compute_kernels.jinja
micromlgen/templates/compute_votes.jinja
micromlgen/templates/kernel_function.jinja
micromlgen/templates/self_test.jinja
micromlgen/templates/svm.jinja
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include micromlgen/templates/*
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,60 @@ fill that much space.
After a whole 20 minutes of thinking, the result is a Python library that takes
a SVM classifier and produces C code you can copy-paste in your project to run ML
on microcontrollers. The C code is clearly readable, so you can even see what's going on:
no black magic.
no black magic.

## Install

`pip install micromlgen`

## Use

```python
from micromlgen import port
from sklearn.svm import SVC
from sklearn.datasets import load_iris


if __name__ == '__main__':
iris = load_iris()
X = iris.data
y = iris.target
clf = SVC(kernel='linear').fit(X, y)
print(port(clf))
```

You may pass a classmap to get readable class names in the ported code

```python
from micromlgen import port
from sklearn.svm import SVC
from sklearn.datasets import load_iris


if __name__ == '__main__':
iris = load_iris()
X = iris.data
y = iris.target
clf = SVC(kernel='linear').fit(X, y)
print(port(clf, classmap={
0: 'setosa',
1: 'virginica',
2: 'versicolor'
}))
```

You can pass a test set to generate self test code

```python
from micromlgen import port
from sklearn.svm import SVC
from sklearn.datasets import load_iris


if __name__ == '__main__':
iris = load_iris()
X_train, X_test = iris.data[:-10, :], iris.data[-10:, :]
y_train, y_test = iris.target[:-10], iris.target[-10:]
clf = SVC(kernel='linear').fit(X_train, y_train)
print(port(clf, test_set=(X_test, y_test)))
```
2 changes: 1 addition & 1 deletion micromlgen/micromlgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def port(clf, test_set=None, classmap=None, **kwargs):
}
}
loader = FileSystemLoader('.')
template = Environment(loader=loader).get_template('templates/svm.jinja')
template = Environment(loader=loader).get_template('./templates/svm.jinja')
code = template.render(template_data)
code = re.sub(r'\n\s*\n', '\n', code)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
setup(
name = 'micromlgen',
packages = ['micromlgen'],
version = '0.3',
version = '0.4',
license='MIT',
description = 'Generate C code for microcontrollers from Python\'s sklearn classifiers',
author = 'Simone Salerno',
author_email = '[email protected]',
url = 'https://github.com/agrimagsrl/micromlgen',
download_url = 'https://github.com/agrimagsrl/micromlgen/archive/v_03.tar.gz',
download_url = 'https://github.com/agrimagsrl/micromlgen/archive/v_04.tar.gz',
keywords = ['ML', 'microcontrollers', 'sklearn', 'machine learning'],
install_requires=[
'jinja2',
Expand Down

0 comments on commit 9989cdc

Please sign in to comment.