cancel
Showing results for 
Search instead for 
Did you mean: 

run inference of array input and serial port

audi
Associate II

I'm trying to run inference of Onnx model. I tried to use the manual 'How to run locally a c-model'. in all the guides I found the input for the network is one number in my case the input is array of[1][32][101].

I want to inference the array once so I defined the array inside the code:

int main(void)
{

float arr[1][32][101] = {{
{-3.11280847, 1.20812774, 1.35149229, 2.38075948, 1.44475543, 2.02790046, 0.953049302, 0.914898038, -1.36378086, -1.10036778, -0.643827021, 0.442990154, 0.127005145, 0.347257495, 0.96026051, 2.16111732, 0.911462247, 0.0638621524, 0.420568168, -0.454940706, 0.278535783, -1.72249091, -0.0312718078, 0.677090943, 0.677178025, 3.62985706, 6.1095314, 4.71714258, 2.52096772, 1.85782039, 3.56450081, 2.33646345, 0.74150598, 3.00033593, 2.18773079, 2.3708117, 1.90530002, 0.935163617, 1.84133303, 1.83260036, 1.26168466, 1.35615361, 1.47735798,0.794498026, 1.27766323, 0.669813454, 0.333116472, 0.557521105, -1.19389999, -0.558699965, -1.95603204, -2.00413299, -2.47239089, -2.98040223, -2.32027674, -2.0002923, -1.08251679, -2.09991741, -2.71532297, -3.33602428, -2.32278252, -2.90880919, -2.90444922, -1.37102318, -0.794113994, -0.754181743, 0.625361621, 0.799631, 2.04137111, 1.83574486, -0.0563439615, 0.531437039, 0.723383665, 1.39186454, 1.05168092, -0.17144388, -0.654711246, -1.11858916, -0.172822386, -0.154968709, -0.296295762, 0.285019845, -2.4039886, -1.09768689, -1.20296073, -0.744145393, 1.30346537, 2.33224988, 5.23028278, 5.39218044, 3.68946958, 2.67011595, 3.0110352, 3.3067677, 4.13743544, 3.61871052, 4.55586672, 3.08941364, 3.9733212, 6.5281148, 6.48285151}, ..............
{-0.124370761, -0.25681743, -0.174864665, -0.303938687, -0.305616736, 0.501344144, 0.191730008, -0.595367968, 0.0195621159, -0.499377728, -0.554431796, 0.135502249, 0.209228992, -0.107157215, -0.732672453, -0.0909939408, 0.332618088, 0.435508996, 0.0886018947, 0.111686856, -0.430598021, -0.644429505, -0.320931613, -0.0142807262, 0.269327551, -0.262372524, 0.158931687, 0.581443071, 0.51328069, 0.287612945, 0.129554451, -0.421877593, 0.218516916, -0.377420992, 0.0600219555, 0.227767453, 0.189634874, 0.0224377941, -0.299934655, -0.202925697, -0.0625948235, 0.0241567139, -0.32136777, -0.077394329, -0.510343552, -0.538764656, -0.172252685, 0.183668494, 0.253921151, 0.16461505, 0.209040388, 0.337033302, -0.229932159, -0.477088958, 0.172478646, -0.339774102, 0.0769023895, 0.289961636, -0.396371871, 0.097611092, 0.12514621, 0.0945786461, 0.458191037, -0.415075034, -0.171801165, 0.207780272, 0.0687480345, -0.0288433023, 0.242168382, 0.175405174, -0.0923376009, -0.158497617, -0.427032709, -0.31170091, 0.248422459, -0.384036839, -0.146370575, 0.192516997, -0.591019452, 0.305823535, -0.218512982, -0.411096483, 0.334248573, 0.508593559, 0.00992995221, 0.13902536, -0.478877813, -0.177643746, 0.155734971, 0.272549003, 0.300172895, -0.0133117726, -0.0733290166, 0.274585783, -0.147048399, -0.131414518, 0.332703322, 0.251400143, -0.640918612, 0.0786387622, -0.115000002}
}};

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DFSDM1_Init();
MX_I2C2_Init();
MX_QUADSPI_Init();
MX_SPI3_Init();
MX_USART3_UART_Init();
MX_USB_OTG_FS_PCD_Init();
MX_CRC_Init();
/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

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];
printf("input[0] : (%d, %d, %d)\n", AI_BUFFER_SHAPE_ELEM(ai_input, AI_SHAPE_HEIGHT),
AI_BUFFER_SHAPE_ELEM(ai_input, AI_SHAPE_WIDTH),
AI_BUFFER_SHAPE_ELEM(ai_input, AI_SHAPE_CHANNEL));
printf("output[0] : (%d, %d, %d)\n", AI_BUFFER_SHAPE_ELEM(ai_output, AI_SHAPE_HEIGHT),
AI_BUFFER_SHAPE_ELEM(ai_output, AI_SHAPE_WIDTH),
AI_BUFFER_SHAPE_ELEM(ai_output, AI_SHAPE_CHANNEL));

/** @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;
// }

in_data[0] = arr;
/** @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;

 

what do I have to change in order to run array and how can I see the output and the 'printf' in the monitor serial? I tried to use minicom with no success.

thank you 

0 REPLIES 0