Pico prediction is inaccurate

Question/Issue:
Prediction using Pico is inaccurate
Project ID:
175000
Context/Use case:
Why the prediction for the 3 labels is giving 0 result?

Starting inferencing in 2 seconds…
Sampling…
Predictions (DSP: 0 ms., Classification: 1 ms., Anomaly: 0 ms.):
NONE: 0.00000
OFF: 0.00000
ON: 0.00000

This is my code

/* Includes ---------------------------------------------------------------- */
#include <stdio.h>
#include "pico/stdlib.h"
#include "ei_run_classifier.h"
#include "hardware/gpio.h"
#include "hardware/adc.h"
#include "pico/cyw43_arch.h"

#define FREQUENCY_HZ        50
#define INTERVAL_MS         (1000 / (FREQUENCY_HZ + 1))

/* Constant defines -------------------------------------------------------- */
#define CONVERT_G_TO_MS2    9.80665f
#define G0 1.65f
#define NSAMP 10
 
char ssid[] = "";
char pass[] = "";

/* Private variables ------------------------------------------------------- */
static bool debug_nn = false; // Set this to true to see e.g. features generated from the raw signal
 
const float conversion_factor = 3.3f / (1 << 12);
 
 
float readAxisAccelation (int adc_n) {
    adc_select_input(adc_n);
    unsigned int axis_raw = 0;
    for (int i=0;i<NSAMP;i++){
        axis_raw = axis_raw + adc_read();
        sleep_ms(1);
    }
    axis_raw = axis_raw/NSAMP;
    float axis_g = (axis_raw*conversion_factor)-G0;
    return axis_g;
}
 
int main()
{
    stdio_init_all();
    
    if (cyw43_arch_init_with_country(CYW43_COUNTRY_UK)) {
        printf("failed to initialise\n");
        return 1;
    }

    printf("initialised\n");

    cyw43_arch_enable_sta_mode();
    if (cyw43_arch_wifi_connect_timeout_ms(ssid, pass, CYW43_AUTH_WPA2_AES_PSK, 10000)) {
        printf("failed to connect\n");
        return 1;
    }

    printf("connected\n");


    adc_init();
    adc_gpio_init(28);
    

    while (true){
         
        ei_printf("\nStarting inferencing in 2 seconds...\n");
        sleep_ms(2000);
        cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
        ei_printf("Sampling...\n");

        // Allocate a buffer here for the values we'll read from the IMU
        float buffer[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE] = { 0 };

        for (size_t ix = 0; ix < EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE; ix += EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME) {
            // Determine the next tick (and then sleep later)
            uint64_t next_tick = ei_read_timer_us() + (EI_CLASSIFIER_INTERVAL_MS * 1000);
             
            buffer[ix] = readAxisAccelation (2);
 
            buffer[ix + 0] *= CONVERT_G_TO_MS2;


 
            sleep_us(next_tick - ei_read_timer_us());
        }
 
        // Turn the raw buffer in a signal which we can the classify
        signal_t signal;
        int err = numpy::signal_from_buffer(buffer, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, &signal);
        if (err != 0) {
            ei_printf("Failed to create signal from buffer (%d)\n", err);
            return 1;
        }

        // Run the classifier
        ei_impulse_result_t result = { 0 };
 
        err = run_classifier(&signal, &result, debug_nn);
        if (err != EI_IMPULSE_OK) {
            ei_printf("ERR: Failed to run classifier (%d)\n", err);
            return 1;
        }
 
        // print the predictions
        ei_printf("Predictions ");

        ei_printf("(DSP: %d ms., Classification: %d ms., Anomaly: %d ms.)",
            result.timing.dsp, result.timing.classification, result.timing.anomaly);
        ei_printf(": \n");
        for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
            ei_printf("    %s: %.5f\n", result.classification[ix].label, result.classification[ix].value);
        }

        #if EI_CLASSIFIER_HAS_ANOMALY == 1
            ei_printf("    anomaly score: %.3f\n", result.anomaly);
        #endif
        cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);

        //sleep_ms(INTERVAL_MS);
    }


return 0;
}

This is my feature data, it should give me result “OFF”.

-6.0521, -6.2180, -6.2101, -5.2067, -6.1943, -6.2259, -5.9098, -6.2259, -6.2654, -6.2654, -6.0916, -6.2259, -6.1074, -6.2496, -6.2654, -6.2338, -6.2338, -6.2733, -6.2259, -6.2417, -6.0916, -6.2496, -6.0758, -6.1943, -6.2022, -6.2338, -6.2338, -6.2101, -6.5893, 2.7258, 5.5938, 5.5464, 4.7484, 5.5859, 5.6175, -5.0882, -6.0916, -6.2496, -5.6649, -6.2575, -6.1469, -4.4640, -2.7890, -6.6130, -6.2338, -6.2180, -6.0995, -6.2496, -6.2338, -6.2417, -6.2575, -6.2417, -6.2733, -6.2417, -7.4268, 5.6175, 5.5859, 4.6220, 5.3252, -0.2686, -6.2338, -5.5306, -6.2022, -6.1943, -6.0363, -6.2417, -6.0600, -5.5464, -6.2417, -6.2180, -4.9301, -6.2022, -6.1943, -5.8861, -6.2022, -6.2101, -6.2022, -6.0521, -6.2417, -5.6254, -6.2417, -6.2417, -6.2575, -6.2338, -6.2338, -6.2338, -6.2575, -6.2180, -6.2575, -6.2575, -6.2180, -6.2575, -6.2259, -6.2496, -6.2417, -6.2259, -5.7676, -6.2259, -6.2259, -5.3331, -6.1943, -6.2180, -6.0284, -6.2101, -6.2101, -5.3884, -6.2338, -6.1390, -5.0961, -6.2180, -6.0600, -5.9968, -6.1943, -6.2259, -6.2338, -6.2259, -6.2417, -6.1548, -6.2654, -6.2496, -6.2417, -6.1232, -6.2575, -6.2259, -6.2496, -6.1548, -6.2338, -6.2338, -6.0600, -6.2575, -6.2259, -6.2417, -6.2417, -6.2180, -5.5938, -6.2338, -6.2417, -5.2699, -6.2259, -6.2180, -5.8466, -6.2180, -6.2338, -5.9494, -6.2338, -6.2101, -5.4832, -6.2180, -6.2417, -6.2180, -6.2180, -6.1864, -6.0442, -6.2338, -6.2259, -6.1311, -6.2496, -6.2733, -6.2575, -6.2338, -6.2338, -6.2417, -6.2654, -6.2259, -6.1469, -6.2180, -6.1864, -6.2180, -6.2259, -6.2259

Hi @fd18,

Fortunately this doesn’t appear to be an issue with your hardware,

Take a look in your project here:
Impulse Design > Classifier
None, on and off should all be separated clearly.

Also see:
Model Testing > Results
None, on and off should all be separated clearly. On and Off should not be clustered together.

Have a look through this guide to see some examples of movements to try for gestures, and see how the data is presented in this project. it should give you a good feel for the data collection:

Once on and off are clearly separated, you will need a lot more data collected for your project to get better results.

Best

Eoin