cancel
Showing results for 
Search instead for 
Did you mean: 

un-understandable randomization of input data inside the generated code

HAlzo
Senior

Hello,

I am using STM32CubeMX Ver 5.5.0 with X-CUBE-AI .

In the generated code inside function MX_X_CUBE_AI_Process() I found the following code just before aiRun function

        /* ---------------------------------------- */
        /* Data generation and Pre-Process          */
        /* ---------------------------------------- */
        /* - fill the input buffer with random data */
        for (ai_size i=0;  i < AI_CNN_IN_1_SIZE; i++ ) {
 
            /* Generate random data in the range [-1, 1] */
            ai_float val = 2.0f * (ai_float)rand() / (ai_float)RAND_MAX - 1.0f;
 
            /* Convert the data if necessary */
            if (type_ == AI_BUFFER_FMT_TYPE_FLOAT) {
                ((ai_float *)in_data)[i] = val;
            } else { /* AI_BUFFER_FMT_TYPE_Q */
                /* Scale the values in the range [-2^M, 2^M] */
                val *= max_;
                /* Convert float to Qmn format */
                const ai_i32 tmp_ = AI_ROUND(val * scale_, ai_i32);
                in_data[i] =  AI_CLAMP(tmp_, -128, 127, ai_i8);
            }
        }

I can't understand why the input buffer is filled with random data instead of the original input data?

I expect that all this code need to be commented, am I right?

0 REPLIES 0