Skip to main content
Associate
Mar 1, 2025 2:39 PM UTC
Solved

How to pass data to my model?

HI! 

I am newbie to CUBE AI. 

I m working on implementing my CNN network that takes input image of 128,128,1 (greyscale) and give an output of 3 classes {class1,class2,class3}.

i did convert and try my model to TFLITE successfully on python.

 then i went to stmcube and did put the model using X-CUBE-AI application template .

my problem is with 

 

 

 

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;
}

 

 

my input buffer is like this

 

 

#define AI_NETWORK_IN_1_FORMAT (AI_BUFFER_FORMAT_FLOAT)
#define AI_NETWORK_IN_1_HEIGHT (128)
#define AI_NETWORK_IN_1_WIDTH (128)
#define AI_NETWORK_IN_1_CHANNEL (1)
#define AI_NETWORK_IN_1_SIZE (16384)
#define AI_NETWORK_IN_1_SIZE_BYTES (65536)

 

 

i tried putting image as image [128*128] and image[128][128]

This topic has been closed for replies.
Julian E.
Julian E.Best answer
ST Technical Moderator
Mar 3, 2025 4:44 PM UTC

Hello @YahiaHedna ,

 

you are using float input, please try to change the 

int acquire_and_process_data(ai_i8* data[])

to 

int acquire_and_process_data(ai_float* data[])

then pass a float array of size 128x128=16384 to data[idx] 

 

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.

4 replies

Julian E.
Julian E.Best answer
ST Technical Moderator
Mar 3, 2025 4:44 PM UTC

Hello @YahiaHedna ,

 

you are using float input, please try to change the 

int acquire_and_process_data(ai_i8* data[])

to 

int acquire_and_process_data(ai_float* data[])

then pass a float array of size 128x128=16384 to data[idx] 

 

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.
Associate
Mar 6, 2025 6:24 PM UTC

Thank you Julian!  

I figured out the problem and I was getting that error because of the improper data passing to the input layer.

Thanks again for your time!

Associate III
Jun 25, 2025 8:31 AM UTC

1. My image data is transmitted through a serial port or USB. How can I convert this image data into the data that needs to be received by int acquire_ and_decess_data (ai_i8 * data [])?
2. Do I need to convert these image data into BMP format first, and then put it into ai_i8 * data []? However, this parameter does not provide array length data, nor do I have input parameters for length and width dimensions. How can I convert an image data into ai_i8 * data [] format?

Associate
Jun 26, 2025 9:08 AM UTC

Use netron to check the input type of your model, if its float, uint .....

Then, do change data from ai_i8 to your input type.

Finnally, if your input is 64x64, ur data should have 4096 values, that you pass to your ai_run