2424#include "app_fuseprogramming.h"
2525#include "stm32_lcd_ex.h"
2626#include "app_postprocess.h"
27- #include "ll_aton_runtime.h"
27+ #include "ll_aton_rt_user_api.h"
28+ LL_ATON_DECLARE_NAMED_NN_INSTANCE_AND_INTERFACE (Default );
2829#include "app_camerapipeline.h"
2930#include "main.h"
3031#include <stdio.h>
@@ -92,14 +93,14 @@ const uint32_t colors[NUMBER_COLORS] = {
9293};
9394
9495#if POSTPROCESS_TYPE == POSTPROCESS_ISEG_YOLO_V8_UI
95- yolov8_seg_pp_static_param_t pp_params ;
96+ iseg_yolov8_pp_static_param_t pp_params ;
9697#else
97- #error "PostProcessing type not supported"
98+ #error "PostProcessing type not supported"
9899#endif
99100
100101volatile int32_t cameraFrameReceived ;
101102uint8_t * nn_in ;
102- iseg_postprocess_out_t pp_output ;
103+ iseg_pp_out_t pp_output ;
103104
104105#define ALIGN_TO_16 (value ) (((value) + 15) & ~15)
105106
@@ -128,13 +129,14 @@ static uint8_t screen_buffer[LCD_FG_WIDTH * LCD_FG_HEIGHT * 2];
128129static void SystemClock_Config (void );
129130static void NPURam_enable (void );
130131static void NPUCache_config (void );
131- static void Display_NetworkOutput (iseg_postprocess_out_t * p_postprocess , uint32_t inference_ms );
132+ static void Display_NetworkOutput (iseg_pp_out_t * p_postprocess , uint32_t inference_ms );
132133static void Display_init (void );
133134static void Security_Config (void );
134135static void set_clk_sleep_mode (void );
135136static void IAC_Config (void );
136137static void Display_WelcomeScreen (void );
137138static void Hardware_init (void );
139+ static void Run_Inference (void );
138140static void NeuralNetwork_init (uint32_t * nnin_length , float32_t * nn_out [], int * number_output , int32_t nn_out_len []);
139141
140142
@@ -154,11 +156,10 @@ int main(void)
154156 int number_output = 0 ;
155157 float32_t * nn_out [MAX_NUMBER_OUTPUT ];
156158 int32_t nn_out_len [MAX_NUMBER_OUTPUT ];
157- LL_ATON_DECLARE_NAMED_NN_INSTANCE_AND_INTERFACE (Default );
158159 NeuralNetwork_init (& nn_in_len , nn_out , & number_output , nn_out_len );
159160
160161 /*** Post Processing Init ***************************************************/
161- app_postprocess_init (& pp_params );
162+ app_postprocess_init (& pp_params , & NN_Instance_Default );
162163
163164 /*** Camera Init ************************************************************/
164165 CameraPipeline_Init ((uint32_t * [2 ]) {& lcd_bg_area .XSize , & lcd_fg_area .XSize }, (uint32_t * [2 ]) {& lcd_bg_area .YSize , & lcd_fg_area .YSize }, & pitch_nn );
@@ -203,7 +204,7 @@ int main(void)
203204
204205 ts [0 ] = HAL_GetTick ();
205206 /* run ATON inference */
206- LL_ATON_RT_Main ( & NN_Instance_Default );
207+ Run_Inference ( );
207208 ts [1 ] = HAL_GetTick ();
208209
209210 int32_t ret = app_postprocess_run ((void * * ) nn_out , number_output , & pp_output , & pp_params );
@@ -262,10 +263,27 @@ static void Hardware_init(void)
262263
263264}
264265
266+ static void Run_Inference (void ) {
267+ LL_ATON_RT_RetValues_t ll_aton_rt_ret ;
268+
269+ do
270+ {
271+ ll_aton_rt_ret = LL_ATON_RT_RunEpochBlock (& NN_Instance_Default );
272+
273+ /* Wait for next event */
274+ if (ll_aton_rt_ret == LL_ATON_RT_WFE )
275+ {
276+ LL_ATON_OSAL_WFE ();
277+ }
278+ } while (ll_aton_rt_ret != LL_ATON_RT_DONE );
279+
280+ LL_ATON_RT_Reset_Network (& NN_Instance_Default );
281+ }
282+
265283static void NeuralNetwork_init (uint32_t * nnin_length , float32_t * nn_out [], int * number_output , int32_t nn_out_len [])
266284{
267- const LL_Buffer_InfoTypeDef * nn_in_info = LL_ATON_Input_Buffers_Info_Default ( );
268- const LL_Buffer_InfoTypeDef * nn_out_info = LL_ATON_Output_Buffers_Info_Default ( );
285+ const LL_Buffer_InfoTypeDef * nn_in_info = LL_ATON_Input_Buffers_Info ( & NN_Instance_Default );
286+ const LL_Buffer_InfoTypeDef * nn_out_info = LL_ATON_Output_Buffers_Info ( & NN_Instance_Default );
269287
270288 // Get the input buffer address
271289 nn_in = (uint8_t * ) LL_Buffer_addr_start (& nn_in_info [0 ]);
@@ -285,6 +303,9 @@ static void NeuralNetwork_init(uint32_t *nnin_length, float32_t *nn_out[], int *
285303 }
286304
287305 * nnin_length = LL_Buffer_len (& nn_in_info [0 ]);
306+
307+ LL_ATON_RT_RuntimeInit ();
308+ LL_ATON_RT_Init_Network (& NN_Instance_Default );
288309}
289310
290311static void NPURam_enable (void )
@@ -386,11 +407,14 @@ void IAC_IRQHandler(void)
386407* @param p_postprocess pointer to postprocessing output
387408* @param inference_ms inference time in ms
388409*/
389- static void Display_NetworkOutput (iseg_postprocess_out_t * p_postprocess , uint32_t inference_ms )
410+ static void Display_NetworkOutput (iseg_pp_out_t * p_postprocess , uint32_t inference_ms )
390411{
391-
392- iseg_postprocess_outBuffer_t * rois = p_postprocess -> pOutBuff ;
412+ iseg_pp_outBuffer_t * rois = p_postprocess -> pOutBuff ;
393413 uint32_t nb_rois = p_postprocess -> nb_detect ;
414+ uint32_t x0 [AI_YOLOV8_SEG_PP_MAX_BOXES_LIMIT ];
415+ uint32_t y0 [AI_YOLOV8_SEG_PP_MAX_BOXES_LIMIT ];
416+ uint32_t width [AI_YOLOV8_SEG_PP_MAX_BOXES_LIMIT ];
417+ uint32_t height [AI_YOLOV8_SEG_PP_MAX_BOXES_LIMIT ];
394418 int ret ;
395419
396420 __disable_irq ();
@@ -402,35 +426,37 @@ static void Display_NetworkOutput(iseg_postprocess_out_t *p_postprocess, uint32_
402426 UTIL_LCD_FillRect (0 , 0 , lcd_fg_area .XSize , lcd_fg_area .YSize , UTIL_LCD_COLOR_TRANSPARENT ); /* Clear previous boxes */
403427 for (int32_t i = 0 ; i < nb_rois ; i ++ )
404428 {
405- /* Display mask */
429+ /* Box dimensions */
430+ x0 [i ] = (uint32_t ) ((rois [i ].x_center - rois [i ].width / 2 ) * ((float32_t ) lcd_bg_area .XSize )) + lcd_bg_area .X0 ;
431+ y0 [i ] = (uint32_t ) ((rois [i ].y_center - rois [i ].height / 2 ) * ((float32_t ) lcd_bg_area .YSize )) + lcd_bg_area .Y0 ;
432+ width [i ] = (uint32_t ) (rois [i ].width * ((float32_t ) lcd_bg_area .XSize ));
433+ height [i ] = (uint32_t ) (rois [i ].height * ((float32_t ) lcd_bg_area .YSize ));
434+ /* Clamp box to image dimensions */
435+ x0 [i ] = x0 [i ] < lcd_bg_area .X0 + lcd_bg_area .XSize ? x0 [i ] : lcd_bg_area .X0 + lcd_bg_area .XSize - 1 ;
436+ y0 [i ] = y0 [i ] < lcd_bg_area .Y0 + lcd_bg_area .YSize ? y0 [i ] : lcd_bg_area .Y0 + lcd_bg_area .YSize - 1 ;
437+ width [i ] = ((x0 [i ] + width [i ]) < lcd_bg_area .X0 + lcd_bg_area .XSize ) ? width [i ] : (lcd_bg_area .X0 + lcd_bg_area .XSize - x0 [i ] - 1 );
438+ height [i ] = ((y0 [i ] + height [i ]) < lcd_bg_area .Y0 + lcd_bg_area .YSize ) ? height [i ] : (lcd_bg_area .Y0 + lcd_bg_area .YSize - y0 [i ] - 1 );
439+ /* Display mask bounded by the corresponding box */
406440 for (int x = 0 ; x < AI_YOLOV8_SEG_PP_MASK_SIZE ; x ++ )
407- {
408441 for (int y = 0 ; y < AI_YOLOV8_SEG_PP_MASK_SIZE ; y ++ )
409- {
410- if (rois [i ].pMask [y * AI_YOLOV8_SEG_PP_MASK_SIZE + x ] > 0.1f )
442+ if ((rois [i ].pMask [y * AI_YOLOV8_SEG_PP_MASK_SIZE + x ]) && (AI_YOLOV8_SEG_PP_CONF_THRESHOLD <= rois [i ].conf ) &&
443+ (lcd_bg_area .X0 + x * lcd_bg_area .XSize / AI_YOLOV8_SEG_PP_MASK_SIZE < x0 [i ] + width [i ]) &&
444+ (lcd_bg_area .Y0 + y * lcd_bg_area .YSize / AI_YOLOV8_SEG_PP_MASK_SIZE < y0 [i ] + height [i ]) &&
445+ (x0 [i ] < lcd_bg_area .X0 + (x + 1 ) * lcd_bg_area .XSize / AI_YOLOV8_SEG_PP_MASK_SIZE + 1 ) &&
446+ (y0 [i ] < lcd_bg_area .Y0 + (y + 1 ) * lcd_bg_area .YSize / AI_YOLOV8_SEG_PP_MASK_SIZE + 1 ))
411447 UTIL_LCD_FillRect ((uint32_t ) x * lcd_bg_area .XSize / AI_YOLOV8_SEG_PP_MASK_SIZE ,
412448 (uint32_t ) y * lcd_bg_area .YSize / AI_YOLOV8_SEG_PP_MASK_SIZE ,
413449 (uint32_t ) lcd_bg_area .XSize / AI_YOLOV8_SEG_PP_MASK_SIZE + 1 ,
414450 (uint32_t ) lcd_bg_area .YSize / AI_YOLOV8_SEG_PP_MASK_SIZE + 1 ,
415- colors [i % NUMBER_COLORS ] & 0x40ffffff );
416- }
417- }
451+ colors [rois [i ].class_index % NUMBER_COLORS ] & 0x40ffffff );
418452 }
419453 for (int32_t i = 0 ; i < nb_rois ; i ++ )
420- {
421- /* Display box */
422- uint32_t x0 = (uint32_t ) ((rois [i ].x_center - rois [i ].width / 2 ) * ((float32_t ) lcd_bg_area .XSize ));
423- uint32_t y0 = (uint32_t ) ((rois [i ].y_center - rois [i ].height / 2 ) * ((float32_t ) lcd_bg_area .YSize ));
424- uint32_t width = (uint32_t ) (rois [i ].width * ((float32_t ) lcd_bg_area .XSize ));
425- uint32_t height = (uint32_t ) (rois [i ].height * ((float32_t ) lcd_bg_area .YSize ));
426- /* Draw boxes without going outside of the image */
427- x0 = x0 < lcd_bg_area .XSize ? x0 : lcd_bg_area .XSize - 1 ;
428- y0 = y0 < lcd_bg_area .YSize ? y0 : lcd_bg_area .YSize - 1 ;
429- width = ((x0 + width ) < lcd_bg_area .XSize ) ? width : (lcd_bg_area .XSize - x0 - 1 );
430- height = ((y0 + height ) < lcd_bg_area .YSize ) ? height : (lcd_bg_area .YSize - y0 - 1 );
431- UTIL_LCD_DrawRect (x0 , y0 , width , height , colors [i % NUMBER_COLORS ]);
432- UTIL_LCDEx_PrintfAt (x0 , y0 , LEFT_MODE , classes_table [rois [i ].class_index ]);
433- }
454+ if (AI_YOLOV8_SEG_PP_CONF_THRESHOLD <= rois [i ].conf )
455+ {
456+ /* Display boxes */
457+ UTIL_LCD_DrawRect (x0 [i ], y0 [i ], width [i ], height [i ], colors [rois [i ].class_index % NUMBER_COLORS ]);
458+ UTIL_LCDEx_PrintfAt (x0 [i ], y0 [i ], LEFT_MODE , classes_table [rois [i ].class_index ]);
459+ }
434460
435461 UTIL_LCD_SetBackColor (0x40000000 );
436462 UTIL_LCDEx_PrintfAt (0 , LINE (0 ), CENTER_MODE , "Objects %u" , nb_rois );
0 commit comments