@@ -708,12 +708,11 @@ fn postprocess_segment(
708708 let ( output0, shape0) = & outputs[ 0 ] ;
709709 let ( output1, shape1) = & outputs[ 1 ] ;
710710
711- // output0: [1, 4 + nc + 32 , 8400]
712- // output1: [1, 32 , 160, 160] (protos)
711+ // output0: [1, 4 + nc + nm , 8400]
712+ // output1: [1, nm , 160, 160] (protos)
713713
714- // 1. Process Detections
715- // Standard segmentation models use 32 mask prototypes
716- let num_masks = 32 ;
714+ // Derive nm from the protos tensor so non-default prototype counts work correctly.
715+ let num_masks = if shape1. len ( ) == 4 { shape1[ 1 ] } else { 32 } ;
717716 let expected_features = 4 + names. len ( ) + num_masks;
718717
719718 // Manual shape check
@@ -799,7 +798,6 @@ fn postprocess_segment(
799798 let keep_indices = nms_per_class ( & nms_candidates, config. iou_threshold ) ;
800799 let num_kept = keep_indices. len ( ) . min ( config. max_det ) ;
801800
802- // 2. Extract Box Results
803801 let mut boxes_data = Array2 :: zeros ( ( num_kept, 6 ) ) ;
804802 let mut mask_coeffs = Array2 :: zeros ( ( num_kept, num_masks) ) ;
805803
@@ -822,7 +820,6 @@ fn postprocess_segment(
822820
823821 results. boxes = Some ( Boxes :: new ( boxes_data. clone ( ) , preprocess. orig_shape ) ) ;
824822
825- // 3. Process Masks
826823 // Protos: [1, 32, 160, 160] -> [32, 25600]
827824 // Validate protos shape before indexing to prevent panic
828825 if shape1. len ( ) < 4 {
0 commit comments