cancel
Showing results for 
Search instead for 
Did you mean: 

How to infer a normal Float model when quantised on STM32CubeMX.

김경훈
Associate

안녕하세요

제목과 같이 관련돼서 문의 합니다.

입력 데이터는 아래와 같고,

Translated to EN:

Hello

I have an enquiry related to the title.

The input data is as below,

// 13 x 15

int new_data[195] = { /* fill with your sensor data */
440, 501, 743, 479, 546, 658, 596, 523, 493, 684, 855, 3, 2,
536, 605, 743, 576, 664, 791, 728, 523, 591, 799, 993, 4, 2,
536, 605, 743, 576, 664, 791, 728, 523, 591, 799, 993, 4, 2,
659, 735, 924, 707, 664, 965, 728, 651, 722, 961, 1184, 4, 2,
659, 735, 924, 707, 827, 965, 901, 651, 722, 961, 1184, 4, 2,
826, 735, 1168, 887, 827, 965, 901, 827, 901, 961, 1446, 4, 2,
826, 920, 1168, 887, 1059, 1198, 1128, 827, 901, 1192, 1446, 5, 2,
826, 920, 1480, 887, 1059, 1198, 1128, 1084, 901, 1192, 1736, 5, 2,
1067, 1174, 1480, 1130, 1395, 1507, 1407, 1084, 1151, 1519, 1736, 4, 2,
1067, 1174, 1480, 1130, 1395, 1507, 1407, 1084, 1151, 1519, 1736, 4, 2,
1413, 1510, 1765, 1443, 1395, 1790, 1663, 1437, 1480, 1778, 1950, 4, 2,
1413, 1510, 1765, 1443, 1686, 1790, 1663, 1437, 1480, 1778, 1950, 4, 2,
1711, 1510, 1996, 1730, 1686, 2009, 1663, 1714, 1746, 1778, 2113, 4, 2,
1711, 1784, 1996, 1730, 1908, 2009, 1573, 1714, 1746, 1970, 2113, 4, 2,
1711, 1784, 1703, 1682, 1908, 2009, 1573, 1921, 1746, 1970, 2242, 4, 2
};

아웃풋은 아래와 같이 0~1사이의 값이 나오게 하는 모델을 만들었습니다.

    new_data = new_data / np.max(new_data)
    new_data = new_data.reshape((new_data.shape[0], 15, 13))

    prediction = model.predict(new_data)
    print(f'prediction : {prediction}')
    print(f'Prediction: {"White Wall" if prediction >= 0.5 else "Black Wall"}')
 
그리고 STM32CubeMX의 X-CUBE-AI를 통해서 코드를 생성했습니다.
 
그런데 아래 부분들을 어떻게 채워야 할지 모르겠습니다.
답변 부탁드립니다.
 

int acquire_and_process_data(ai_i8* data[])
{
/* fill the inputs of the c-model
for (int idx=0; idx < AI_NETWORK_IN_NUM; idx++ )
{
      data[idx] = ....
}

*/
return 0;
}

int post_process(ai_i8* data[])
{
/* process the predictions
for (int idx=0; idx < AI_NETWORK_OUT_NUM; idx++ )
{
      data[idx] = ....
}

*/
return 0;
}

3 REPLIES 3
SofLit
ST Employee

Hello and welcome to the community.

Please write in English and in next time please use this button to post your code.

SofLit_0-1718011789605.png

Thank you for your understanding?

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
SofLit
ST Employee

Translation:

Title: If a general float model is quantized in STM32CubeMX, please inquire about the inference method.

Body:

hello

I have a question related to the title.

The input data is as follows,

// 13 x 15

int new_data[195] = { /* fill with your sensor data */
440, 501, 743, 479, 546, 658, 596, 523, 493, 684, 855, 3, 2,
536, 605, 743, 576, 664, 791, 728, 523, 591, 799, 993, 4, 2,
536, 605, 743, 576, 664, 791, 728, 523, 591, 799, 993, 4, 2,
659, 735, 924, 707, 664, 965, 728, 651, 722, 961, 1184, 4, 2,
659, 735, 924, 707, 827, 965, 901, 651, 722, 961, 1184, 4, 2,
826, 735, 1168, 887, 827, 965, 901, 827, 901, 961, 1446, 4, 2,
826, 920, 1168, 887, 1059, 1198, 1128, 827, 901, 1192, 1446, 5, 2,
826, 920, 1480, 887, 1059, 1198, 1128, 1084, 901, 1192, 1736, 5, 2,
1067, 1174, 1480, 1130, 1395, 1507, 1407, 1084, 1151, 1519, 1736, 4, 2,
1067, 1174, 1480, 1130, 1395, 1507, 1407, 1084, 1151, 1519, 1736, 4, 2,
1413, 1510, 1765, 1443, 1395, 1790, 1663, 1437, 1480, 1778, 1950, 4, 2,
1413, 1510, 1765, 1443, 1686, 1790, 1663, 1437, 1480, 1778, 1950, 4, 2,
1711, 1510, 1996, 1730, 1686, 2009, 1663, 1714, 1746, 1778, 2113, 4, 2,
1711, 1784, 1996, 1730, 1908, 2009, 1573, 1714, 1746, 1970, 2113, 4, 2,
1711, 1784, 1703, 1682, 1908, 2009, 1573, 1921, 1746, 1970, 2242, 4, 2
};

We created a model that outputs values ​​between 0 and 1 as shown below:

    new_data = new_data / np.max(new_data)
    new_data = new_data.reshape((new_data.shape[0], 15, 13))

    prediction = model.predict(new_data)
    print(f'prediction : {prediction}')
    print(f'Prediction: {"White Wall" if prediction >= 0.5 else "Black Wall"}')

And the code was generated through STM32CubeMX's X-CUBE-AI.

But I don't know how to fill in the parts below.
please answer my question.

int acquire_and_process_data(ai_i8* data[])
{
/* fill the inputs of the c-model
for (int idx=0; idx < AI_NETWORK_IN_NUM; idx++ )
{
      data[idx] = ....
}

*/
return 0;
}

int post_process(ai_i8* data[])
{
/* process the predictions
for (int idx=0; idx < AI_NETWORK_OUT_NUM; idx++ )
{
      data[idx] = ....
}

*/
return 0;
}

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hello,

Okay. I will use English from now.

Please reply my question.

During 2days, I have not found solution.

Please help me.

Thank you.