cancel
Showing results for 
Search instead for 
Did you mean: 

stm32cube_ai, airun(),The output data is abnormal

Sunjing
Associate II

屏幕截图(315).png

When I use a function 【int ai_run(const void *in_data, void *out_data)】to make predictions,the out_data always output【0】

No matter how I change the value of the input data, the value of the output data will not change, it will always be 0.

int ai_run(const void *in_data, void *out_data)  
{
	ai_i32 batch;

	ai_input[0].data = AI_HANDLE_PTR(in_data);
	ai_output[0].data = AI_HANDLE_PTR(out_data);

	batch = ai_network_run(network, &ai_input[0], &ai_output[0]);
	if (batch != 1) {
		ai_log_err(ai_network_get_error(network),
        "ai_network_run");
    return -1;
  }

	printf("Output1: %f\r\n", *(float*)out_data);
	
  return 0;
}

 

the picture is cube_ai  Analyzing Network information

1 REPLY 1
jean-michel.d
ST Employee

Hi Sunjing,

Code of the aiRun function is correct for a model with one input and one output. However, according the attached png (output of the analyze command), the ML model has two outputs. In your code, you check only the "label" output which can be always zero.. and the type is ai_int32 not ai_float32.

Before to modify the c-code, have your try to perform a "validate" flow (on the host or on target if you use a supported STM32 board) with the model to check if it is correctly supported.

Correct aiRun code can be:

...
static ai_int32 out_data_1[AI_NETWORK_OUT_1_SIZE];
static ai_float out_data_2[AI_NETWORK_OUT_2_SIZE];
..
int aiRun(void * in_data, ai_int32* labels, ai_float* probs)
{
...
  ai_input[0].data = AI_HANDLE_PTR(in_data);
  ai_output[0].data = AI_HANDLE_PTR(labels);
  ai_output[1].data = AI_HANDLE_PTR(prob);

  error = ai_network_run(network, &ai_input[0], &ai_output[0]);
  // check error 
  print(" label   = %d\n\r", *labels);
  print(" probs   = %f %f %f %f\n\r", *prob, *(prob+1), *(prob+2), *(prob+3));
..
}

 

br,

JM