cancel
Showing results for 
Search instead for 
Did you mean: 

X-Cube-AI: High accuracy on desktop validation, but not in debug

Hamanken
Visitor

I validated the AI network using the‘Validate on desktop‘ tool,and the accuracy was high.But when I debugged the AI C-program(generated by CUBE AI) with the same input data, the result have large difference with correct output values.Could you help me understand the reason for this discrepancy.The MCU is STM32G4 Series

 

the network is run in this function:

batch = ai_network_run(network, ai_input, ai_output);

I only changed this two function in app_x-cube-ai.c:

acquire_and_process_data() 
{
  float test_data[4] = {1.094757,20,1,0};
  ai_input->data = test_data;

  float inputread[4];
  for(int idx=0;idx<4;idx++)
  {
    inputread[idx] = *((float*)(ai_input->data)+idx);
  }
} 

post_process()
{
  float outputread[2] = {0};
  for(int idx=0;idx<2;idx++)
  {
    outputread[idx] = *((float*)(ai_output->data)+idx);
  }
}

Edited to apply source code formatting - please see How to insert source code for future reference.

1 REPLY 1
Julian E.
ST Employee

Hello @Hamanken

 

Could you run a validate on target to see if you get a good COS, example:

JulianE_0-1753972399052.png

In the process of using AI on a MCU you can lose accuracy at multiple steps:

  • When you quantize you obviously lose precision
  • When you convert to the C model on x86 host
  • When you run it on the Arm based MCU you could also have a different behavior due to diff with x86.

By looking at the cos with the model running on target, we can first see if this seems to come from your model or from your code.

 

Have a good day,

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.