@@ -570,15 +570,16 @@ void dt_seg_warmup_decoder(dt_seg_context_t *ctx)
570570 .shape = has_mask_shape , .ndim = 1 };
571571
572572 int64_t masks_shape [4 ] = {1 , nm , dec_h , dec_w };
573+ // shapes must outlive outputs[] used by dt_ai_run below
574+ int64_t iou_shape [2 ] = {1 , nm };
575+ int64_t lr_shape [4 ] = {1 , nm , pm_dim , pm_dim };
573576 float iou_buf [MAX_NUM_MASKS ];
574577
575578 dt_ai_tensor_t outputs [3 ];
576579 int n_out ;
577580
578581 if (is_sam )
579582 {
580- int64_t iou_shape [2 ] = {1 , nm };
581- int64_t lr_shape [4 ] = {1 , nm , pm_dim , pm_dim };
582583 const int dec_outputs = dt_ai_get_output_count (ctx -> decoder );
583584
584585 outputs [0 ] = (dt_ai_tensor_t ){
@@ -847,14 +848,16 @@ float *dt_seg_compute_mask(dt_seg_context_t *ctx,
847848 dt_ai_tensor_t dec_outputs [3 ];
848849 int n_dec_out ;
849850 int64_t masks_shape [4 ] = {1 , nm , dec_h , dec_w };
851+ // shapes must outlive dec_outputs[] used by dt_ai_run below
852+ int64_t iou_shape [2 ] = {1 , nm };
853+ int64_t low_res_shape [4 ] = {1 , nm , pm_dim , pm_dim };
850854
851855 float iou_pred [MAX_NUM_MASKS ];
852856 float * low_res = NULL ;
853857
854858 if (is_sam )
855859 {
856860 // SAM: masks [1,N,H,W] + iou [1,N], optionally low_res [1,N,pm,pm]
857- int64_t iou_shape [2 ] = {1 , nm };
858861 const int dec_out_count = dt_ai_get_output_count (ctx -> decoder );
859862
860863 dec_outputs [0 ] = (dt_ai_tensor_t ){
@@ -875,7 +878,6 @@ float *dt_seg_compute_mask(dt_seg_context_t *ctx,
875878 g_free (masks );
876879 return NULL ;
877880 }
878- int64_t low_res_shape [4 ] = {1 , nm , pm_dim , pm_dim };
879881 dec_outputs [2 ] = (dt_ai_tensor_t ){
880882 .data = low_res , .type = DT_AI_FLOAT , .shape = low_res_shape , .ndim = 4 };
881883 n_dec_out = 3 ;
0 commit comments