cancel
Showing results for 
Search instead for 
Did you mean: 

Question about X-CUBE-AI

Khoo.B
Associate III

I have trained a neural network model and trying to implement it using STM32L476RG Nucleo board. I have generated an application template and the input to the neural network is 32 X 32 X 1.

I'm trying to understand below parameters in network_audio_ai.h.

#define AI_NETWORK_AUDIO_AI_IN_1_HEIGHT   (32)

#define AI_NETWORK_AUDIO_AI_IN_1_WIDTH    (32)

#define AI_NETWORK_AUDIO_AI_IN_1_CHANNEL   (1)

#define AI_NETWORK_AUDIO_AI_IN_1_SIZE    (32 * 32 * 1)

#define AI_NETWORK_AUDIO_AI_IN_1_SIZE_BYTES (AI_NETWORK_AUDIO_AI_IN_1_SIZE * 4)

The AI_NETWORK_AUDIO_IN_1_SIZE matched my trained model. My question is what is AI_NETWORK_AUDIO_AI_IN_SIZE_BYTES? Why do we need to multiply 4?

Are there any documents about this? Thank you very much!

1 ACCEPTED SOLUTION

Accepted Solutions
jean-michel.d
ST Employee

Hi,

AI_NETWORK_AUDIO_AI_IN_1_SIZE  indicates the total size of the input buffer in term of number of items/elements. AI_NETWORK_AUDIO_AI_IN_1_SIZE_BYTES indicates the associated size in bytes. I suppose in your case that the type of data for the input is float, this explains the 4 ( = sizeof(float)).

AI_NETWORK_AUDIO_AI_IN_1_SIZE_BYTES can be used to allocate or to define the input data buffer to store the input data.

If the buffer is allocated statically, you have two possibilities:

ai_float  in_data[AI_NETWORK_AUDIO_AI_IN_1_SIZE]
// or
AI_ALIGNED(4)   // to align the buffer on 4-byte boundary 
ai_unit8  in_data[AI_NETWORK_AUDIO_AI_IN_1_SIZE_BYTES];

Arrangement/layout of the data/items inside the buffer is dependent of the shape but it follows the standard C-definition for the arrays. See "C-memory layouts" section in the embedded documentation ("Embedded Inference Client API" article.

(typical location of the doc in the X-CUBE-AI pack: C:\Users\<user_name>\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\7.0.0\Documentation\index.html).

br,

Jean-Michel

View solution in original post

4 REPLIES 4
Khoo.B
Associate III

Further to my previous question, what's the actual size of the input data to the model? Is it AI_NETWORK_AUDIO_AI_IN_1_SIZE or AI_NETWORK_AUDIO_AI_IN_1_SIZE_BYTES?

Khoo.B
Associate III

Anyone that could help me on this?

jean-michel.d
ST Employee

Hi,

AI_NETWORK_AUDIO_AI_IN_1_SIZE  indicates the total size of the input buffer in term of number of items/elements. AI_NETWORK_AUDIO_AI_IN_1_SIZE_BYTES indicates the associated size in bytes. I suppose in your case that the type of data for the input is float, this explains the 4 ( = sizeof(float)).

AI_NETWORK_AUDIO_AI_IN_1_SIZE_BYTES can be used to allocate or to define the input data buffer to store the input data.

If the buffer is allocated statically, you have two possibilities:

ai_float  in_data[AI_NETWORK_AUDIO_AI_IN_1_SIZE]
// or
AI_ALIGNED(4)   // to align the buffer on 4-byte boundary 
ai_unit8  in_data[AI_NETWORK_AUDIO_AI_IN_1_SIZE_BYTES];

Arrangement/layout of the data/items inside the buffer is dependent of the shape but it follows the standard C-definition for the arrays. See "C-memory layouts" section in the embedded documentation ("Embedded Inference Client API" article.

(typical location of the doc in the X-CUBE-AI pack: C:\Users\<user_name>\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\7.0.0\Documentation\index.html).

br,

Jean-Michel

Thank you very much. May I know what is the purpose of AI_ALIGNED(4)?