2022-07-19 05:10 AM
Hello all,
Is it possible to create, inject data and perform the inference with just my STM32F4-DISCO without any connection with my PC (of course I must beforhand flash my model into my board). And how would you do it, I tried to integrate the code from "How to run locally a c-model" in my file but it doesn't seems to work. I thanks you in advance !
The code :
int ai_network_***(void)
{
ai_u8 activations[AI_NETWORK_DATA_ACTIVATIONS_SIZE];
ai_u8 in_data[AI_NETWORK_IN_1_SIZE_BYTES];
ai_u8 out_data[AI_NETWORK_OUT_1_SIZE_BYTES];
/* AI buffer IO handlers */
ai_buffer *ai_input;
ai_buffer *ai_output;
ai_handle network = AI_HANDLE_NULL;
ai_error err;
ai_network_report report;
/** @brief Initialize network */
const ai_handle acts[] = { activations };
err = ai_network_create_and_init(&network, acts, NULL);
if (err.type != AI_ERROR_NONE) {
printf("ai init_and_create error\n");
return -1;
}
/** @brief {optional} for debug/log purpose */
if (ai_network_get_report(network, &report) != true) {
printf("ai get report error\n");
return -1;
}
printf("Model name : %s\n", report.model_name);
printf("Model signature : %s\n", report.model_signature);
ai_input = &report.inputs[0];
ai_output = &report.outputs[0];
/** @brief Fill input buffer with random values */
srand(1);
for (int i = 0; i < AI_NETWORK_IN_1_SIZE; i++) {
in_data[i] = rand() % 0xFFFF;
}
/** @brief Normalize, convert and/or quantize inputs if necessary... */
/** @brief Perform inference */
ai_i32 n_batch;
/** @brief Create the AI buffer IO handlers
* @note ai_inuput/ai_output are already initilaized after the
* ai_network_get_report() call. This is just here to illustrate
* the case where get_report() is not called.
*/
ai_input = ai_network_inputs_get(network, NULL);
ai_output = ai_network_outputs_get(network, NULL);
/** @brief Set input/output buffer addresses */
ai_input[0].data = AI_HANDLE_PTR(in_data);
ai_output[0].data = AI_HANDLE_PTR(out_data);
/** @brief Perform the inference */
n_batch = ai_network_run(network, &ai_input[0], &ai_output[0]);
if (n_batch != 1) {
err = ai_network_get_error(network);
printf("ai run error %d, %d\n", err.type, err.code);
return -1;
}
/** @brief Post-process the output results/predictions */
printf("Inference output..\n");
for (int i = 0; i < AI_NETWORK_OUT_1_SIZE; i++) {
printf("%d,", out_data[i]);
}
printf("\n");
return 0;
}
Regards,
Numa
2022-07-19 05:58 AM
Sure.
Instead of reading from real sensors, and/or a serial port, read the data from Flash instead.
2022-07-19 06:38 AM
Hello,
Thank you for your response. Isn't it what I am doing with the function ai_network_*** ? :
==> Creating my data lines 35-37
==> Set buffer addresses lines 54-55
==> Perform the inference line 58
Regards,
Numa
2022-07-19 06:57 AM
@NBlan.1 "it doesn't seems to work"
What does that mean?
2022-07-19 07:00 AM
Not sure that feeding random data into your model is going to give any useful results?
You're effectively just testing its handling of noise.
What is line 43 supposed to do?
Should that be a function call?
/** @brief Perform inference */
ai_i32 n_batch;
2022-07-19 07:14 AM
Hello,
Feeding random data to my model is a viable solution, it is used in the examples provided by ST.
ai_i32 is the type of data and n_batch is the variable that I'm calling line 58.
Regards,
Numa
2022-07-19 07:26 AM
Hello,
Regards,
Numa
2022-07-19 07:40 AM
so it's just the comment that's wrong?
2022-07-19 07:42 AM
It seems like it, it was in the original example.
2022-07-19 07:45 AM
@NBlan.1 "I was expecting that input was send to my board"
But you're not sending anything? You asked how to do it without sending anything?
"receive an output on my the terminal."
So what output, exactly, were you expecting?
And what did you actually get?
"I can't call my function, it's never used"
So nothing to do with creating the test data?
Have you traced your code to see where the function should get called?