Showing results for 
Search instead for 
Did you mean: 

STM32CubeAI Application template: Change input type



I'm new to C and STM32 deployment. I am developing a ML model that I would like to run on a STM32F446RE board. I'm using STM32CubeIDE 1.14.0 and X-Cube-AI 8.1.0. I followed the first steps to add the model, Analyze and Validate on desktop and on target.

After that, I'd like to develop my own application to calculate inferences with real-time data. So I used "ApplicationTemplate" when I added X-Cube-AI to the project. I saw that I needed to complete the acquire_and_process_data function to be able to add my own data:


int acquire_and_process_data(ai_i8* data[])
  /* fill the inputs of the c-model
  for (int idx=0; idx < AI_NETWORK_IN_NUM; idx++ )
      data[idx] = ....

  return 0;


The problem is that my data is of type float but I need data of type int8_t. How do I get float input?

Also, I haven't found any documentation or an example of how to complete the template, does anyone have an example?

Thanks in advance!


ST Employee

Hello @Elo and welcome to ST Community,

In order to perform the inference the model needs to be quantized to be able to run it on your embedded platform but if your model supports floats as input you can change this function parameter to float .

this is mentioned in the UM2526 as follows :

"The code generator quantizes weights and bias, and associated activations from floating point to 8-bit precision.
These are mapped on the optimized and specialized C implementation for the supported kernels (refer to [7]).
Otherwise, the floating-point version of the operator is used and float-to-8-bit and 8-bit-to-float convert operators
are automatically inserted. The objective of this technique is to reduce the model size while also improving the
CPU and hardware accelerator latency (including power consumption aspects) with little degradation in model
accuracy "

you can refer to this post which have similar context . this github example showcases the use of cube IA with float input data.


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.
Associate II

Further to the above, is there a way to set the input and output types generated by CubeMX to ai_float? I have quantized my model with ONNX and used the nodes_to_exclude option to keep the model's input and output types as floats (and this is correctly maps through to CubeMX's C-graph of the model). However, every time I perform code generation in CubeMX it overwrites the io buffer types in app_x-cube-ai.c with ai_i8.