Skip to main content

nms_class_aware_float

Function nms_class_aware_float 

Source
pub fn nms_class_aware_float(iou: f32, boxes: Vec<DetectBox>) -> Vec<DetectBox>
Expand description

Class-aware NMS: only suppress boxes with the same label.

Sorts boxes by score, then greedily selects a subset of boxes in descending order of score. Unlike class-agnostic NMS, boxes are only suppressed if they have the same class label AND overlap above the IoU threshold.

ยงExample

let boxes = vec![
    DetectBox {
        bbox: BoundingBox::new(0.0, 0.0, 0.5, 0.5),
        score: 0.9,
        label: 0,
    },
    DetectBox {
        bbox: BoundingBox::new(0.1, 0.1, 0.6, 0.6),
        score: 0.8,
        label: 1,
    }, // different class
];
// Both boxes survive because they have different labels
let result = nms_class_aware_float(0.3, boxes);
assert_eq!(result.len(), 2);