I am trying to do train accelerometer sensor data using edge impulse.
In edge impulse studio, all work well. I export the STM32cube.AI package file. Then I integrate that package in STMcubeIDE.After this process, I made simple code which just got accelerometer data, and this data processed by edge impulse sample API but I don’t get aspected output. So I need your help to get the best result in my project.
Project detail:- Make a Demo of accelerometer with detecting a minimum three types of movement for example right-left, up-down, Zick-zack.
Board - stm32l476 discovery
Sensor - lis2dw12
This is my code , every time I filled features named buffer with my accelerometer raw data which collecting in real time, this raw data got 100% accurate answer in edge impulse studio but in code that data don’t give proper answer ?
If you give any other detail about my project then I will give you , just solve my problem.
Do you always have same classification results or random ones?
Your model is probably overfitting as you have little data and training on 1500 cycles.
I would suggest adding more training samples, around 3 minutes for each movement, and then retrain on 100 cycles.
@Rink, are you sure the data in the buffer is correct? You’re memsetting the features array to 0, then doing a single reading, so I assume get_feature_data will mostly retrieve zeros?
If everything is set up right you’ll get the features printed on the UART. Could you share those?
See, i Called “lis2dw12_read_data_single()” function after memset() ok,
this function is to get data from the sensor and fills the buffer and I also see the buffer is filled or not.
Thanks for reply ,And yes I checked results on edge impulse studio with same raw data , studio get 100% right ans but code not , N i also prefer you base code which you given in you website . now what can i do .
Ok Sir ,
If you need my CubeIDE file then I will give you my project files…but this demo is very important for me .
After some changes , Right now my code give me same ans as studio , but this works only on static buffer , if i give real time sensor data on this buffer then its can’t provide right ans .
@Rink, I thought I had a L476 laying around, but I didn’t Anyway, this is a demo on the DISCO-L475VG in STM32CubeIDE:
Includes
/* Includes ------------------------------------------------------------------*/
#include <edge-impulse-sdk/classifier/ei_run_classifier.h>
#include "main.h"
#include "stm32l475e_iot01_accelero.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
using namespace ei;
/* USER CODE END Includes */
Code
/* USER CODE BEGIN 2 */
ACCELERO_StatusTypeDef s = BSP_ACCELERO_Init();
ei_printf("Accelerometer init result %d\n", s);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
float features[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE] = { 0 };
for (size_t ix = 0; ix < EI_CLASSIFIER_RAW_SAMPLE_COUNT; ix++) {
uint64_t next_tick = ei_read_timer_us() + (EI_CLASSIFIER_INTERVAL_MS * 1000);
int16_t accel_data[3] = { 0 };
BSP_ACCELERO_AccGetXYZ(accel_data);
features[(ix * EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME) + 0] = static_cast<float>(accel_data[0]) / 100.0f;
features[(ix * EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME) + 1] = static_cast<float>(accel_data[1]) / 100.0f;
features[(ix * EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME) + 2] = static_cast<float>(accel_data[2]) / 100.0f;
// busy-loop until next tick
while (ei_read_timer_us() < next_tick);
}
ei_impulse_result_t result;
signal_t signal;
numpy::signal_from_buffer(features, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, &signal);
EI_IMPULSE_ERROR res = run_classifier(&signal, &result, false);
ei_printf("run_classifier returned: %d\n", res);
ei_printf("Predictions (DSP: %d ms., Classification: %d ms., Anomaly: %d ms.): \n",
result.timing.dsp, result.timing.classification, result.timing.anomaly);
// print the predictions
ei_printf("[");
for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
ei_printf("%.5f", result.classification[ix].value);
#if EI_CLASSIFIER_HAS_ANOMALY == 1
ei_printf(", ");
#else
if (ix != EI_CLASSIFIER_LABEL_COUNT - 1) {
ei_printf(", ");
}
#endif
}
#if EI_CLASSIFIER_HAS_ANOMALY == 1
ei_printf("%.3f", result.anomaly);
#endif
ei_printf("]\n\n\n");
}
/* USER CODE END 3 */
Hey , Sir
I was thinking , Can I use a standard C++ file on My setup(stm32L4 + lis2dw12)?
Because this is just for testing purposes, Our company final goal is that edge impulse use in a Nordic microcontroller. So How can I use Standard C++ library . Please give me some details or sample code something , I also try your Mbed OS code which is given in GitHub , but still there is so many linking error I got .
@Rink you can but if the model does not work properly on the STM32Cube.AI export it won’t work in the normal C++ export either. Given that your results are always the same I’m still suspecting the buffer to not be filled correctly.
sir , I Checked my buffer fill with proper data or not , even I also print it.
See this in picture , I printed my buffer data and result … my data continues changes but result cant , and this time I used c++ library instead of Cube-AI.