diff --git a/MANIFEST b/MANIFEST index 66011b2..273c89f 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3,10 +3,12 @@ setup.cfg setup.py micromlgen/__init__.py micromlgen/micromlgen.py +micromlgen/patches.py micromlgen/platforms.py micromlgen/utils.py micromlgen/templates/classmap.jinja micromlgen/templates/testset.jinja +micromlgen/templates/pca/pca.jinja micromlgen/templates/rvm/rvm.jinja micromlgen/templates/svm/svm.jinja micromlgen/templates/svm/computations/class.jinja diff --git a/micromlgen/micromlgen.py b/micromlgen/micromlgen.py index de61091..3d4001c 100644 --- a/micromlgen/micromlgen.py +++ b/micromlgen/micromlgen.py @@ -1,6 +1,9 @@ -from skbayes.rvm_ard_models import RVC from sklearn.svm import SVC, LinearSVC, OneClassSVM from sklearn.decomposition import PCA +try: + from skbayes.rvm_ard_models import RVC +except ImportError: + from micromlgen.patches import RVC from micromlgen import platforms from micromlgen.utils import jinja diff --git a/micromlgen/patches.py b/micromlgen/patches.py new file mode 100644 index 0000000..9b113f4 --- /dev/null +++ b/micromlgen/patches.py @@ -0,0 +1,3 @@ +class RVC: + """Patch un-installed skbayes RVC classifier""" + pass \ No newline at end of file diff --git a/micromlgen/templates/classmap.jinja b/micromlgen/templates/classmap.jinja index 4d6ed46..c59e781 100644 --- a/micromlgen/templates/classmap.jinja +++ b/micromlgen/templates/classmap.jinja @@ -3,8 +3,8 @@ /** * Convert class idx to readable name */ -const char* classIdxToName(uint8_t classIdx) { - switch (classIdx) { +const char* predictLabel(float *x) { + switch (predict(x)) { {% for idx, name in classmap.items() %} case {{ idx }}: return "{{ name }}"; diff --git a/micromlgen/templates/svm/kernel/arduino.jinja b/micromlgen/templates/svm/kernel/arduino.jinja index 33ae3e4..fd66337 100644 --- a/micromlgen/templates/svm/kernel/arduino.jinja +++ b/micromlgen/templates/svm/kernel/arduino.jinja @@ -2,7 +2,7 @@ * Compute kernel between feature vector and support vector. * Kernel type: {{ kernel['type'] }} */ -float compute_kernel(float x[{{ sizes.features }}], ...) { +float compute_kernel(float *x, ...) { va_list w; va_start(w, {{ sizes.features }}); diff --git a/micromlgen/templates/svm/kernel/attiny.jinja b/micromlgen/templates/svm/kernel/attiny.jinja index a7dff92..d0063e9 100644 --- a/micromlgen/templates/svm/kernel/attiny.jinja +++ b/micromlgen/templates/svm/kernel/attiny.jinja @@ -2,7 +2,7 @@ * Compute kernel between feature vector and support vector. * Kernel type: {{ kernel['type'] }} */ -float compute_kernel(float x[{{ sizes.features }}], float w[{{ sizes.features }}]) { +float compute_kernel(float *x, float w[{{ sizes.features }}]) { va_list w; va_start(w, {{ sizes.features }}); diff --git a/setup.py b/setup.py index bd36e20..b7e7696 100644 --- a/setup.py +++ b/setup.py @@ -7,13 +7,13 @@ setup( name = 'micromlgen', packages = ['micromlgen'], - version = '1.1.0', + version = '1.1.1', license='MIT', description = 'Generate C code for microcontrollers from Python\'s sklearn classifiers', author = 'Simone Salerno', author_email = 'eloquentarduino@gmail.com', url = 'https://github.com/eloquentarduino/micromlgen', - download_url = 'https://github.com/eloquentarduino/micromlgen/archive/v_11.tar.gz', + download_url = 'https://github.com/eloquentarduino/micromlgen/archive/v_111.tar.gz', keywords = [ 'ML', 'microcontrollers',