← AI Terminology
NMS - Non-Maximum Suppression
Non-Maximum Suppression is a post-processing algorithm used in object detection to eliminate duplicate bounding box predictions — keeping only the highest-confidence detection for each object by suppressing all lower-confidence boxes that significantly overlap with it (IoU above a threshold).
It is applied after any detection model that produces multiple candidate boxes per object.
It is applied after any detection model that produces multiple candidate boxes per object.
Why It Matters in AI
Object detectors like YOLO and Faster R-CNN generate hundreds to thousands of candidate bounding boxes per image. Without NMS, every object would have multiple overlapping detections at slightly different positions. NMS selects the best box per object by: sorting candidates by confidence, keeping the highest-confidence box, and removing all others with IoU > threshold. It is a critical post-processing step without which detection outputs are unusable.
Key Points
| Aspect | Description |
|---|---|
| Soft NMS | Instead of hard removal, decay confidence of overlapping boxes — handles dense crowds better |
| Algorithm | Sort by confidence → keep highest → remove boxes with IoU > threshold → repeat for remaining |
| Batched NMS | torchvision.ops.batched_nms — efficient GPU implementation for multi-class detection |
| IoU threshold | Typically 0.45–0.65 — lower = more aggressive suppression (fewer boxes); higher = more retained |
| Class-aware NMS | NMS applied per class — boxes of different classes at same location are not suppressed together |
| Confidence threshold | Pre-filter: remove all boxes below minimum confidence (e.g. 0.25) before NMS |
Simple Analogy
A talent show judges' elimination round: dozens of singers (detections) audition for one role (object position). Instead of accepting all of them, the show keeps the highest-scoring singer and eliminates all other singers who are too similar (high IoU) — ensuring each role is filled by exactly one performer.
Common Usage Examples
torchvision.ops.nms(boxes, scores, iou_threshold=0.5)— PyTorch NMS returns kept indicestorchvision.ops.batched_nms(boxes, scores, idxs, iou_threshold=0.45)— per-class NMS- YOLOv8 inference: NMS automatically applied post-detection; controllable via
iou=0.45, conf=0.25 - Soft-NMS:
scores[i] *= (1 - iou(box_i, best_box)) ** 2— penalise instead of remove - DETR: eliminates NMS entirely via learned set-prediction — models predict exactly N boxes with bipartite matching
Summary
In short: Non-Maximum Suppression eliminates duplicate object detections by keeping only the highest-confidence box when multiple boxes heavily overlap — an essential post-processing step for all bounding-box detection models.