Skip to main content
Associate
October 5, 2026
Question

Incorrect predictions if using embedded client API to run inference

Hello,

I’m working with a NUCLEO-N657X0-Q board and trying to run inference using the ST Edge AI embedded client API. The STM32CubeIDE project I’m using was generated with CubeAI Studio. Input, output, weights and activations buffers are preallocated. Here are the advanced settings I used in CubeAI Studio:

 

Even though the validation with CubeAI Studio was successful, I edited the app_x-cube-ai.c file in order to validate my samples again so that I know I’m feeding data into the network and obtaining the outputs correctly. This is were I noticed that the prediction of every single sample is incorrect. Since I got over 98% accuracy with CubeAI Studio, I assume I’m doing something wrong in my code. Unfortunately, I can’t really figure out what it is.

 

I only made a few minor changes to the app_x-cube-ai.c template. I’m basically interacting with the network like follows:


static float* input_states_ptr;
static float* input_currents_ptr;
static float* output_states_ptr;

static stai_ptr stai_input[STAI_NETWORK_IN_NUM];
static stai_ptr stai_output[STAI_NETWORK_OUT_NUM];

stai_network_get_inputs(network_context, stai_input, &in_length);

stai_network_get_outputs(network_context, stai_output, &out_length);


input_states_ptr = (float*)stai_input[0];
input_currents_ptr = (float*)stai_input[1];
output_states_ptr = (float*)stai_output[0];

// writing sample values into input buffers
input_states_ptr[0] = in_states[i][0];
input_states_ptr[1] = in_states[i][1];
input_states_ptr[2] = in_states[i][2];
input_states_ptr[3] = in_states[i][3];

input_currents_ptr[0] = in_currents[i][0];
input_currents_ptr[1] = in_currents[i][1];
input_currents_ptr[2] = in_currents[i][2];

aiRun();

//comparing output of network (stai_output) with samples (out_states)
if(compare_float(output_states_ptr[0], out_states[i][0]) &&
compare_float(output_states_ptr[1], out_states[i][1]) &&
compare_float(output_states_ptr[2], out_states[i][2]) &&
compare_float(output_states_ptr[3], out_states[i][3])){
pass++;
}

Please also see the whole app_x-cube-ai.c in the attachments. I also noticed that stai_input and stai_output contain the same addresses. This means if I assign a value to “input_states_ptr[0]” also “output_states_ptr[0]” changes. This is ok, but I would have expected the output_states to be correct after the aiRun() function is finished.

 

The model has 2 inputs (4x float32 and 3x float32) and one output (4x float32). I also attached the stai_network.h for further information about the network.

 

I would be very grateful if you could tell me where I’m making the mistake. Thank you!

Best regards,

Stefan