2021-06-09 05:15 AM
I have a model with 14 float inputs in a single array and 3 array output each with a size of 4 float numbers.
However the AI_input_size is ((1*1*14)*4) when I need it to be ((1*1*14)*1) and the AI_output_size is ((1*1*3)*4)
#define AI_NN1_IN_NUM (1)
#define AI_NN1_IN { \
AI_BUFFER_OBJ_INIT(AI_BUFFER_FORMAT_FLOAT, 1, 1, 14, 1, NULL), \
}
#define AI_NN1_IN_SIZE { \
(1 * 1 * 14), \
}
#define AI_NN1_IN_1_SIZE (1 * 1 * 14)
#define AI_NN1_IN_1_SIZE_BYTES ((1 * 1 * 14) * 4)
#define AI_NN1_OUT_NUM (3)
#define AI_NN1_OUT { \
AI_BUFFER_OBJ_INIT(AI_BUFFER_FORMAT_FLOAT, 1, 1, 3, 1, NULL), \
AI_BUFFER_OBJ_INIT(AI_BUFFER_FORMAT_FLOAT, 1, 1, 3, 1, NULL), \
AI_BUFFER_OBJ_INIT(AI_BUFFER_FORMAT_FLOAT, 1, 1, 3, 1, NULL), \
}
#define AI_NN1_OUT_SIZE { \
(1 * 1 * 3), \
(1 * 1 * 3), \
(1 * 1 * 3), \
}
#define AI_NN1_OUT_1_SIZE (1 * 1 * 3)
#define AI_NN1_OUT_2_SIZE (1 * 1 * 3)
#define AI_NN1_OUT_3_SIZE (1 * 1 * 3)
#define AI_NN1_OUT_1_SIZE_BYTES ((1 * 1 * 3) * 4)
#define AI_NN1_OUT_2_SIZE_BYTES ((1 * 1 * 3) * 4)
#define AI_NN1_OUT_3_SIZE_BYTES ((1 * 1 * 3) * 4)
I'm not sure how to insert the correct values as well as output and process them. The code above is the declarations of the model's outputs & inputs. How can I change or use them to produce my desired array sizes mentioned above.
The model inserted is a keras model with 1 input (array of 14 float values) and 3 outputs (each with an array of 3 values).
Thanks in advance
Solved! Go to Solution.
2021-06-10 06:32 AM
Hi,
Sorry if I wasn't precise enough,
In the code above, in_data is the buffer I used to perform the network inference, I am just assigning values to the in_data buffer like a normal C array (using indices). Let's dig a little bit deeper into the process : In this code sample, you can see how to inject your data into the network and use the inference function "ai_network_run(...)".
Hope it's clearer ! :)
Romain
2021-06-09 07:36 AM
.
2021-06-09 07:40 AM
Hi,
You can use the size provided in this file this way:
In this example I was feeding accelerometer inputs to the network like that:
And using outputs this way:
Best regards,
Romain
2021-06-09 08:47 AM
Hi,
Thank you for your reply, but can you explain further what is buffer length and why they need to be incremented when declaring the values for the in_data?
And for multiple outputs, do you have any suggestions as to how the values could be accessed? I am quite new to STM32 so I'm not familiar with how to implement this.
Many thanks
2021-06-10 06:32 AM
Hi,
Sorry if I wasn't precise enough,
In the code above, in_data is the buffer I used to perform the network inference, I am just assigning values to the in_data buffer like a normal C array (using indices). Let's dig a little bit deeper into the process : In this code sample, you can see how to inject your data into the network and use the inference function "ai_network_run(...)".
Hope it's clearer ! :)
Romain
2021-06-11 04:14 AM
Hi,
Thank you very much for the added information, I think it makes much more sense now with your clarification and I'm currently getting float values for the outputs.
Kind regards
2021-08-11 12:41 AM
Hi,
I have the same question also. My input size as below:-
#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 size should be 32*32*1. But looking at the application template, it seems like I will need to use (32*32*1)*4. Why do we need multiplication of 4?
2021-08-11 09:25 AM
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
2021-08-11 10:01 PM
Thank you very much!