#340Non-Max Suppression (NMS)MediumComputer VisionLinear AlgebraAsked atMeta · Tesla · Apple
Non-Max Suppression (NMS)
Background
Non-Maximum Suppression is the universal de-duplication step in object detection: keep the highest-scoring box, suppress every other box that overlaps it above an IoU threshold, repeat. Without NMS your detector returns dozens of slightly-shifted boxes for the same object.
Problem statement
Implement nms(boxes, scores, iou_threshold). boxes is shape as . Return a list of indices (kept boxes), in score-descending order.
Greedy: while indices remain, pick the highest-scoring index, add it to the keep list, drop everything with to it.
Input
boxes- array shape , .scores- array length .iou_threshold-floatin .
Output
list[int]of kept indices.
Examples
Input: 3 boxes, the first two overlap heavily, third is distinct
Output: keep box 0 (highest score), suppress box 1, keep box 2
Constraints
- Tie-break by lower index on equal scores.
- Empty input -> empty list.
Notes
- vs soft-NMS. Standard NMS suppresses; soft-NMS down-weights. Soft-NMS is a follow-on; this problem isolates the canonical greedy form.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: suppress the overlapping middle box
- •Worked sample: highest score wins on identical boxes
- •Reference check: kept boxes in score-descending order