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](https://user-images.githubusercontent.com/65896600/90960199-4c0c5b80-e4a0-11ea-8a91-4452c6d0099b.jpg)
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();
}
}
}
/**
*
/**
-
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;
}
`