cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to create and inject data from my STM32F4 ?

NBlan.1
Associate III

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

13 REPLIES 13

"But you're not sending anything? You asked how to do it without sending anything?"

Before I was sending my data from my via a FTDI with a python code. But know I don't want to send data via serial port AND i don't want to use my python code either. I want to do an inference (with code on my board) with some data that is created in my STM32.

"So what output, exactly, were you expecting?"

Line 66-68 is my desired output, and I got nothing because this print is in my function that is not used (why ? I don't know).

"So nothing to do with creating the test data?"

No, this part is fine

"Have you traced your code to see where the function should get called?"

That what I'm will do, thanks !

@NBlan.1​  "Before I was sending my data from my via a FTDI"

And was it working then?

"Line 66-68 is my desired output"

No: that's where the output is generated - I asked what you were actually getting on the terminal.

No, it's my desired output. Nothing is generated here, it's just a print.

That is where the output to the terminal is generated - that's what printf() does.

Again,  I asked what you were actually getting on the terminal.