eloquentarduino / micromlgen

Generate C code for microcontrollers from Python's sklearn classifiers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Template not found for Random forest

devdattakhoche opened this issue · comments

I was trying to export random forest classifier and trying to print the code.
But it is not able to find the template , which I saw is there in the folder "randomforest/randomforest.jinja"

the code I have written

from sklearn.svm import SVC
from micromlgen import port
from glob import glob
from os.path import basename
import numpy as np
from sklearn.ensemble import RandomForestClassifier

def load_features(folder):
    dataset = None
    classmap = {}
    for class_idx, filename in enumerate(glob('%s/*.csv' % folder)):
        class_name = basename(filename)[:-4]
        classmap[class_idx] = class_name
        samples = np.loadtxt(filename, dtype=float, delimiter=',')
        labels = np.ones((len(samples), 1)) * class_idx
        samples = np.hstack((samples, labels))
        dataset = samples if dataset is None else np.vstack((dataset, samples))

    return dataset, classmap
# put your samples in the dataset folder
# one class per file
# one feature vector per line, in CSV format
features, classmap = load_features('data/')
X, y = features[:, :-1], features[:, -1]
classifier = RandomForestClassifier(random_state=0,max_depth=20).fit(X, y)
c_code = port(classifier, classmap=classmap)
print(c_code)

Given output :
Template not found

Expected Output :

should have printed c code

Sorry for being late, I'm not getting email notifications from Github. Please try to install the latest version, I pushed a new one a couple days ago.

hello, I installed the latest version and still getting the same error with random forests.

As a quickfix, please download the zip from Github and extract it into your project.

Version 1.1.22 should fix the issue.

Hey @eloquentarduino , If this is done , you can close this issue