Git Product home page Git Product logo

eloquentmicroml's Introduction

EloquentArduino library

This library contains source code and examples from the eloquentarduino blog, covering very different topics:

  • data structures
  • image / camera processing
  • print utilities
  • ...other miscellaneous

You can install this library either by cloning the repo or directly from the Arduino IDE Library Manager.

If you're interested in TinyML, I suggest you check out the EloquentTinyML library.

eloquentmicroml's People

Contributors

agrimagsrl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

eloquentmicroml's Issues

Execution time and accuracy

Hi, I really appreciate your work. I saw your ML benchmark results for different models and datasets and it is not clear for me how do you measure the execution time and accuracy. Is the execution time measured on target ? What about accuracy ? Is there any difference between online and offline computation in python ?

"Predict" function doesn't give correct output

Hi there,

I am trying to make my own "on board" color classification following this example "https://github.com/eloquentarduino/EloquentMicroML/blob/master/examples/ColorClassificationTrainingExample/ColorClassificationTrainingExample.ino" and this instruction "https://eloquentarduino.github.io/2020/03/how-to-train-a-color-classification-machine-learning-classifier-directly-on-your-arduino-board/#comment-5040745624" but for some reason, the output label of my "model" doesn't seems to work out (attached image), could you please help me spotting the problem for this ?

1

Here is the code that I have on my board (Seeeduino LoRaWAN) and the color sensor I am using is a Grove_Color_TCS34725, I also highlighted the "int label" that you defined in the "predict" command part, may you explain why you defined this int ? Because it wasn't used at all in this function.

`
#include <EloquentSVMSMO.h>
#include "Adafruit_TCS34725.h"

#define MAX_TRAINING_SAMPLES 20
#define FEATURES_DIM 3

using namespace Eloquent::ML;

int numSamples;
float X_train[MAX_TRAINING_SAMPLES][FEATURES_DIM];
int y_train[MAX_TRAINING_SAMPLES];
SVMSMO<FEATURES_DIM> classifier(linearKernel);

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

void setup() {
// Initizaling the board and color sensor
digitalWrite(38, HIGH);
Serial.begin(9600);
while (!Serial) {};
Serial.println("Color Sensor TCS34725 Connected!");

if (tcs.begin()) 
{
  Serial.println("Found sensor");
} 
else 
{
  Serial.println("No TCS34725 found ... check your connections");
  while (1); // halt!
}

classifier.setC(5);
classifier.setTol(1e-5);
classifier.setMaxIter(10000);

}

void loop() {
if (!Serial.available()) {
delay(100);
return;
}

String command = Serial.readStringUntil('\n');

if (command == "help") {
    Serial.println("Available commands:");
    Serial.println("\tfit: train the classifier on a new set of samples");
    Serial.println("\tpredict: classify a new sample");
    Serial.println("\tinspect: print X_train and y_train");
}
else if (command == "fit") {
    Serial.println("How many samples will you record? ");
    numSamples = readSerialNumber();

    for (int i = 0; i < numSamples; i++) {
        Serial.print(i + 1);
        Serial.print("/");
        Serial.print(numSamples);
        Serial.println(" Which class does the sample belongs to, 1 or -1?");
        y_train[i] = readSerialNumber() > 0 ? 1 : -1;
        Serial.print(y_train[i]);
        Serial.println(" was select");
        getFeatures(X_train[i]);
    }

    Serial.println("Training in progress ... ");
    classifier.fit(X_train, y_train, numSamples);
    Serial.println("Done");
}
else if (command == "predict") {
    int label;
    float x[FEATURES_DIM];

    getFeatures(x);
    Serial.print("Predicted label is ");
    Serial.println(classifier.predict(X_train, x));
}
else if (command == "inspect") {
    for (int i = 0; i < numSamples; i++) {
        Serial.print("[");
        Serial.print(y_train[i]);
        Serial.print("] ");

        for (int j = 0; j < FEATURES_DIM; j++) {
            Serial.print(X_train[i][j]);
            Serial.print(", ");
        }

        Serial.println();
    }
}

}

/**
*

  • @return
    */
    int readSerialNumber() {
    while (!Serial.available()) delay(1);

    return Serial.readStringUntil('\n').toInt();
    }

/**

  • Get features for new sample

  • @param x
    */
    void getFeatures(float x[FEATURES_DIM])
    {
    readColorSensor(x);

    for (int i = 0; i < FEATURES_DIM; i++) {
    Serial.print(x[i]);
    Serial.print(", ");
    }

    Serial.println();
    }

void readColorSensor(float x[3])
{
// Define RGB float
float red, green, blue;
tcs.setInterrupt(false); // turn on LED
delay(60); // takes 60ms to read
tcs.getRGB(&red, &green, &blue);
tcs.setInterrupt(true); // turn off LED

x[0] = red;
x[1] = green;
x[2] = blue;

}

`

unable to publish C code using microMLgen

Used MicroMLgen to generate c file to convert a Wifi scan result into a feature vector for classification.
Came across the following error:

  • Traceback (most recent call last):
    File "C:\Users\parth\Documents\Arduino\Wifi-Indoor positioning\feature-generator.py", line 10, in
    X, y, classmap, converter_code = port_wifi_indoor_positioning(samples)
    File "C:\Python37\lib\site-packages\micromlgen\wifiindoorpositioning.py", line 60, in port_wifi_indoor_positioning
    classmap = get_classmap(samples)
    File "C:\Python37\lib\site-packages\micromlgen\wifiindoorpositioning.py", line 21, in get_classmap
    locations = list(parse_samples(samples, parser))
    File "C:\Python37\lib\site-packages\micromlgen\wifiindoorpositioning.py", line 7, in parse_samples
    for line in samples.split('\n'):
    AttributeError: 'dict' object has no attribute 'split'

error while generating c code

Hi there,

This error keeps displaying while generating C code

TemplateNotFound Traceback (most recent call last)
in
1 ocs = OneClassSVM(kernel='rbf', nu=0.5, gamma=0.1)
2 ocs.fit(df)
----> 3 print(port(ocs))

\lib\site-packages\jinja2\loaders.py in get_source(self, environment, template)
195
196 return contents, filename, uptodate
--> 197 raise TemplateNotFound(template)
198
199 def list_templates(self):

TemplateNotFound: svm/svm.jinja

Could you help me?

example ends with error message

I tried to run the tasks in "The Ultimate Guide to Wifi..", but ended up with the following message when I came to the most interesting part of it (Generating the features converter):

C:\Users\adria\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/adria/PycharmProjects/IoT_localization/ArduinoLocalization.py
Traceback (most recent call last):
File "C:/Users/adria/PycharmProjects/IoT_localization/ArduinoLocalization.py", line 10, in
x, y, classmap, converter_code = port_wifi_indoor_positioning(samples)
File "C:\Users\adria\AppData\Local\Programs\Python\Python37-32\lib\site-packages\micromlgen\wifiindoorpositioning.py", line 68, in port_wifi_indoor_positioning
'networkmap': networkmap
File "C:\Users\adria\AppData\Local\Programs\Python\Python37-32\lib\site-packages\micromlgen\utils.py", line 49, in jinja
template = Environment(loader=loader).get_template(template_file)
File "C:\Users\adria\AppData\Local\Programs\Python\Python37-32\lib\site-packages\jinja2\environment.py", line 883, in get_template
return self._load_template(name, self.make_globals(globals))
File "C:\Users\adria\AppData\Local\Programs\Python\Python37-32\lib\site-packages\jinja2\environment.py", line 857, in _load_template
template = self.loader.load(self, name, globals)
File "C:\Users\adria\AppData\Local\Programs\Python\Python37-32\lib\site-packages\jinja2\loaders.py", line 115, in load
source, filename, uptodate = self.get_source(environment, name)
File "C:\Users\adria\AppData\Local\Programs\Python\Python37-32\lib\site-packages\jinja2\loaders.py", line 197, in get_source
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: wifiindoorpositioning/wifiindoorpositioning.jinja

Process finished with exit code 1

most likely, my installation has an issue… Thank you for an idea, what the reason of this problem could be. Best, Adrian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.