There is a make error when I want to port impulse to my STM32CubeIDE project

Hi Shawn,

I’m actually having some trouble with the Edge Impulse model from the public motion recognition project: Dashboard - Tutorial: Continuous motion recognition - Edge Impulse

I ran the code shown in (https://docs.edgeimpulse.com/docs/edge-impulse-cli/cli-data-forwarder#classifying-data-mbed-os) with the Edge Impulse model I downloaded from the public project mentioned above:

For some reason, when I’m expecting the model to return “idle” (because its lying flat on the table) it keeps returning “snake”. Is this something you experienced when you implemented the model in mbed?

image

Hi @Martin_08,

What are the warnings for lines 7, 30, and 38? Those often give you an indication of what might be wrong.

Can you paste in a static set of raw features from the test set in the project to see if that gives you what you expect? For example, from Live classification - Tutorial: Continuous motion recognition - Edge Impulse, we can copy the raw features from the first window.

Try setting the following (we comment out the raw data collection and set the static features copied from the test sample in the project):

...
while (1) {
    // fill the features array
    static float raw_features = {0.7500, 1.7100, 19.9800, 0.8800, 2.1500, 18.9100, 0.8800, 2.1500, 18.9100, 1.4400, 2.2000, 16.7000, 1.9700, 2.2900, 13.7400, 2.2600, 1.8500, 12.0300, 2.4500, 1.2800, 11.4000, 2.1700, 1.2800, 8.7300, 2.5200, 0.9300, 5.6300, 2.5200, 0.9300, 5.6300, 1.3500, 0.4500, 4.9000, 0.2000, 0.3900, 5.7600, -0.6000, 0.1600, 6.4200, 0.3900, -0.0700, 4.7000, 0.6800, -0.2900, 6.0000, 0.3000, 0.2100, 4.7400, 0.3000, 0.2100, 4.7400, 0.6600, 0.5700, 3.5600, -0.0200, 0.2700, 4.0700, -0.6400, 0.2400, 3.4600, -0.8300, 0.0100, 2.1900, 0.0500, -0.3600, 0.0900, 1.1300, -0.7300, -2.2000, 0.8500, -0.9600, -2.4900, 0.8500, -0.9600, -2.4900, 0.2300, -1.7300, -1.5900, 0.2500, -1.8700, -0.8700, 0.3500, -1.7800, -0.8700, 1.0300, -1.0600, -0.5800, 2.4700, -0.1200, -0.3300, 3.2300, -0.0800, 2.4700, 3.2300, -0.0800, 2.4700, 2.5400, -0.0600, 6.9100, 1.9300, 0.3800, 8.2800, 2.8400, 1.5000, 9.1200, 3.1900, 1.7700, 12.0100, 2.7400, 1.6600, 13.3700, 3.0500, 2.1600, 13.6300, 3.0500, 2.1600, 13.6300, 2.8500, 2.0600, 15.2600, 2.0500, 1.6500, 17.6100, 1.3400, 1.5600, 18.5900, 1.7600, 2.0800, 15.8500, 2.8400, 2.6600, 13.1900, 2.6400, 2.4900, 14.8600, 1.7500, 1.8400, 18.4100, 1.7500, 1.8400, 18.4100, 1.8600, 1.9200, 19.0600, 2.4300, 2.4300, 18.2200, 2.2900, 2.5200, 18.0800, 1.3800, 2.2500, 18.9200, 0.9400, 2.3100, 19.8100, 0.8800, 2.4800, 19.5500, 0.8800, 2.4800, 19.5500, 1.1700, 2.6800, 18.7600, 1.6200, 2.8100, 17.9200, 1.9700, 2.7800, 16.8300, 1.7800, 2.6100, 16.2500, 1.2700, 2.7900, 15.7900, 0.3800, 2.6300, 16.1800, 0.3800, 2.6300, 16.1800, 0.4400, 2.3400, 16.1900, 1.6500, 2.4200, 14.7400, 2.4800, 2.6500, 11.8700, 2.7500, 2.5900, 7.5900, 2.8600, 1.8700, 5.3600, 2.2800, 1.0300, 5.3000, 1.0200, 0.4700, 5.4200, 1.0200, 0.4700, 5.4200, 0.0000, 0.0000, 6.6700, 0.6600, -0.1900, 5.7500, 1.0500, 0.0500, 3.4900, 0.6900, -0.1100, 2.1700, 0.1900, -0.5600, 1.5500, 0.5600, -1.3800, 3.5900, 0.5600, -1.3800, 3.5900, 0.0000, -1.5600, 3.1900, -0.5700, -1.1000, 0.6100, -0.4400, -1.0800, -0.8800, -0.1500, -1.3300, -0.4000, 0.2000, -1.6000, 1.5100, -0.1400, -1.7100, 3.0900, -0.4600, -1.5600, 3.6200, -0.4600, -1.5600, 3.6200, 0.6300, -1.2000, 3.1600, 1.1000, -0.7700, 3.2500, 0.4000, -0.6100, 5.3000, 0.7900, -0.5700, 7.3400, 1.0100, -0.5800, 8.1900, 1.1300, -0.3500, 8.2400, 1.1300, -0.3500, 8.2400, 1.3500, -0.1200, 8.4800, 1.8700, 0.2500, 8.4500, 2.2600, 0.3000, 10.3600, 2.7700, 0.3100, 12.3000, 2.7400, 0.8300, 12.7300, 3.2100, 1.2100, 12.2500, 3.2100, 1.2100, 12.2500, 3.2300, 1.3500, 12.6900, 3.3700, 1.7100, 13.7400, 4.1800, 1.7900, 15.7700, 5.0400, 2.0300, 14.9700, 5.6900, 2.3500, 13.6000, 5.1000, 2.3200, 14.5000, 4.0100, 2.3800, 16.6700, 4.0100, 2.3800, 16.6700, 2.5700, 2.2100, 18.2400, 1.9600, 2.2300, 18.2900, 1.9000, 2.1600, 18.4900, 1.9900, 1.8500, 18.6100, 1.2300, 1.7900, 18.2000, 0.4000, 2.0600, 16.9600, 0.4000, 2.0600, 16.9600, 0.2700, 2.1800, 15.8300, 0.4200, 2.2800, 15.3100, 0.7600, 2.2000, 15.1400, 0.7000, 2.0000, 16.0300, 0.6500, 1.9600, 16.1400, 0.6400, 2.2500, 13.7000, 0.6400, 2.2500, 13.7000, 0.8300, 2.2100, 11.2000, 0.9000, 1.7400, 10.4600, 0.8400, 1.3700, 10.0600, 0.5600, 0.9700, 9.6300, -0.3700, 0.7700, 8.8500};
    memcpy(features, raw_features, sizeof(features));

/*
        for (size_t ix = 0; ix < EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE; ix += EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME) {
            int64_t next_tick = t.read_us() + time_between_samples_us;
            BSP_ACCELERO_AccGetXYZ(pDataXYZ);

            // copy accelerometer data into the features array
            features[ix + 0] = (float)pDataXYZ[0];
            features[ix + 1] = (float)pDataXYZ[0];
            features[ix + 2] = (float)pDataXYZ[0];

            while (t.read_us() < next_tick) {
                /* busy loop */
            }
        }
*/

        // frame full? then classify
        ei_impulse_result_t result = { 0 };
...

This should give you nearly the same output found in the Studio:

  • Idle: 0.00
  • Snake: 0.00
  • Updown: 1.00
  • Wave: 0.00
  • Anomaly: -0.54

Hi Shawn,

I compiled the basic real-time inferencing sample on mbed, I’m not getting any warnings when I compile this project:

I tried changing my code to add the snippet that you suggested in your previous reply:

I am unable to compile when using the float array that you suggested because of too many elements apparently. Anyways, I hope this can help us resolve this glitch.

Thanks again for your reply.

Hi @Martin_08,

I don’t have any of the mbed boards with me to test, so you’ll have to bear with me.

What IDE are you using? It looks like the old mbed compiler, which is being deprecated in favor of the Keil mbed Studio (standalone or cloud-based).

Could you try the following on the new https://studio.keil.arm.com/?

  1. File > Import Project. Import GitHub - edgeimpulse/example-standalone-inferencing-mbed: Builds and runs an exported impulse locally (Mbed OS)
  2. Clone and download the C++ library from Dashboard - Tutorial: Continuous motion recognition - Edge Impulse
  3. Copy in the “edge-impulse-sdk”, “tflite-model”, and “model-parameters” folders into your project.
  4. Copy static features from that project to the features[] array as shown in this example: On your Mbed-enabled development board - Edge Impulse Documentation
  5. Build project (it should compile and download a .bin file).
  6. Upload the .bin to your board and see if you get the same inference output that matches the one from the project

I was able to build the project, but I can’t do the last step at this point. I did not see any errors and only one relevant warning about a to-be deprecated function. Let me know if this part works for you!

Hi Shawn,

I did all the steps you suggested.

Swapping to the ARM Keil Studio IDE resulted in my mbed-os library being updated to version 6.15.1.

I copied the raw features from one of the samples from the tutorial:

The output is as expected:

That being said, the code examples for the standalone inferencing and the data forwarder example (which shows an example of real-time accelerometer inferencing) are very different:

Since the Library I downloaded from Edge Impulse seems to work fine, there must be something in my main.cpp file which results in “snake” being incorrectly detected so often.

Maybe I’m missing a delay (but the delays I’ve added over the course of my debugging haven’t seen to fix the problems yet)?

The following is the “main.cpp” I am using for real-time inference (using accelerometer data). It is identical to the code used in the “Data Forwarding” example, with the addition of the model I downloaded from Edge Impulse (which seems to work fine).

Hi Shawn,

Update, it works now. The error was in the accelerometer values I was passing.

When I used the Edge Impulse Daemon to upload data directly from my board, I noticed that the values being displayed on the graphs were 100 times smaller than the raw output values the built-in accelerometer usually puts out. In the image below, the Z-axis value of 10 was equivalent to my accelerometer outputting 1000.

As soon as I modified my code to divide all the raw accelerometer values by 100, the rest of my code worked:

2 Likes

Hi @Martin_08,

Apologies for the delay in getting back to this issue. I’m glad you were able to find the error to get it working!