Secondly,
When I work with unoptimized model these error are not present, but ‘ei_run_classifier()’ returns ‘-5’ (i.e ‘EI_IMPULSE_DSP_ERROR’ ) still. Kindly look into it.
Hi @Ranchpal,
Can you paste here the first compilation error? Your screenshot is showing some later errors, but they are usually the consequence of the first error that the compiler is printing (usually some header files can’t be found, etc.).
Also, can you tell me how do you compile your project? What toolchain do you use?
we are still unable to implement this. Can we get private paid consultation to resolve this issue? We raised same directly through website to the sales team but not heard back yet.
Hi @Ranchpal,
I took a look at your models and generally they look fine and compile without any issues on other targets. The only issues that I see are:
You have prepared a model for fusion sensor type (EI_CLASSIFIER_SENSOR is set to EI_CLASSIFIER_SENSOR_FUSION). This type of sensor is not yet supported on all our targets (currently Arduino Nano 33 BLE and Raspberry Pi RP2040). Support for Nordic’s boards is in progress and will be released in a few weeks.
Even if you would like to run your model on other targets, the second issue is sensors axes names. Currently you are using acc_x, acc_y etc., while we are using accX, accY in our reference firmware (see one of the fusion sensor definition).
I assume you have made fully custom firmware, so it’s hard to help you without sharing your full source code.
If you need to change axis names, it is currently tricky to do it in the studio…
Here is a quick script that will help you to do that. You can export your data, run the script and import them back on your project.
Save the following code in a file called replace_axis.py:
#!/usr/bin/env python
import argparse
import os
import glob
import json
def find_and_replace(input, old_axis, new_axis):
for filename in glob.glob(os.path.join(input, '*.json')):
print(filename)
with open(filename) as file:
data = json.load(file)
for item in data['payload']['sensors']:
item['name']=item['name'].replace(old_axis, new_axis)
with open(filename, 'w') as file:
json.dump(data, file)
if __name__=="__main__":
print("Find and replace labels")
a = argparse.ArgumentParser()
a.add_argument("--input", help="input folder")
a.add_argument("--old_axis", help="old axis name")
a.add_argument("--new_axis", help="new axis name")
args = a.parse_args()
print(args)
find_and_replace(args.input, args.old_axis, args.new_axis)
#exemple: python3 replace_axis.py --input training --old_axis acc_x --new_axis accX
We implemented the ‘axis name’ but, the model is still returning the same error code (-5). Let us know how do we share the whole code for your reference.
The gist doesn’t have all of the source code. Can you upload the header files that this file includes? (More is fine too)
In the meantime, what I was looking at was IMU_BUFFER_SIZE;
What is that set to? I downloaded your model and was able to run it locally. The first step to debugging your gist is to understand how you are setting this value:
features_signal.total_length = IMU_BUFFER_SIZE;
You should be setting features_signal.total_length to 300. (Or set IMU_BUFFER_SIZE to 300, if that makes sense).
The Gist contains only the file where functions relating to edge Impulse are implemented. Is there any specific thing you are looking for ?
Yes the IMU_BUFFER_SIZE is set to 300.
This is user_imu_buffer.h file
#ifndef __USER_IMU_BUFFER_H__
#define __USER_IMU_BUFFER_H__
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "lsm6dsmtr.h"
#define NUMBER_OF_SAMPLES_TO_HOP ((uint8_t)10)
#define MAX_IMU_SAMPLES_STORED ((uint8_t)50)
#define NUMBER_OF_ELEMENTS_IN_A_SAMPLE ((uint8_t)6)
#define IMU_BUFFER_SIZE ((uint16_t)MAX_IMU_SAMPLES_STORED * NUMBER_OF_ELEMENTS_IN_A_SAMPLE) /* 50 samples. Each sample containing 6 axis data */
/** @brief A function to add sample to the buffer */
void user_imu_buffer_add_sample(lsm6dsmtr_data_t imu_sample);
/** @brief A function to remove the first 'X' number of sample from the buffer */
void user_imu_buffer_del_sample(uint16_t X);
/** @brief A function get the if the imu buffer ready to be processed */
bool is_user_imu_buffer_ready(void);
/** @brief A function to clear buffer ready to process flag */
void clr_user_imu_buffer_ready_flag(void);
/** @brief A function to get imu buffer */
void get_imu_buffer(float *p_res_buffer);
/** @brief A function to print the values in the buffer */
void print_imu_buffer(void);
This is user_ai_model.h file
#ifndef __USER_AI_MODEL_H__
#define __USER_AI_MODEL_H__
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
/* #define MAX_ELEMETS_IN_COW_STATE_BUFFER ((uint16_t)300) */
#define MAX_ELEMETS_IN_COW_STATE_BUFFER ((uint16_t)75)
/* @brief A function to get the feature data buffer */
int get_feature_data(size_t offset, size_t length, float *out_ptr) ;
/* @brief A function to run the edgeimpulse model */
/* This function takes in the 50 samples of data and return a label */
void user_ai_model_run(float *p_data, uint8_t *p_label);
/* @brief A function to add cow state to a buffer
* This buffer would be used to get mode of the states every 60secs and update the adv data */
void user_ai_model_store_cow_state(uint8_t state);
/* @brief A function to check if the state buffer is ready to calc the mode
*/
bool is_cow_state_buffer_ready_to_calc_mode(void);
/* @brief A function clear cow state buffer ready flag
*/
void user_ai_model_clr_cow_state_buffer_ready_flag(void);
/* @brief A function to calculate the mode of the cow state
*/
uint8_t user_ai_model_calc_mode(void);
#endif //__USER_AI_MODEL_H__
Since I’m running your model w/o problem on my machine, there are two possibilities:
1- I’m not invoking your model exactly the same way you are
2- There’s something going on within your device specifically that’s causing the issue
To rule out (1), I’ve pushed my test code to a fork here. I believe I’m invoking your model exactly the same way you are in your Gist, but if you can push some code to this repo and cause the -5 issue, we’ll get it fixed right away. Note, I’ve uploaded the test case as “features.txt”
For (2), here are some suggestions:
Your function “user_ai_model_run” looks like it should run deterministically. The input size is fixed, the get_data function is simple. This tells me that maybe you’re having a stack overflow or other memory corruption?
What I would do to debug this is just turn off as many interrupts, other threads, etc. Just run the classifier on gibberish and see if you get the -5 code. (input data changing shouldn’t change the error code). You’ll obviously get gibberish output too, but you shouldn’t see the error code.
If you can get that to run w/o issue, start turning things back on one at a time and see when you start seeing the -5 again