Best viewed on desktop for optimal interactive experience
Overview
Non-Maximum Suppression (NMS) is a critical post-processing step in object detection that removes duplicate detections for the same object. When a detector like YOLO, Faster R-CNN, or SSD processes an image, it often produces multiple overlapping bounding boxes for a single object. NMS filters these redundant predictions, keeping only the most confident detection.
While standard "greedy" NMS uses a hard threshold—completely removing any box with high overlap—this can accidentally eliminate valid detections of nearby objects. Soft-NMS addresses this by gradually reducing confidence scores instead of removing boxes outright, preserving detections for objects standing close together.
Key Concepts
Intersection over Union (IoU)
The ratio of overlap area to total union area between two boxes. IoU = 1 means identical boxes; IoU = 0 means no overlap.
Confidence Score
Each detection has a confidence score (0-1) indicating how certain the model is about the presence and classification of an object.
Greedy Selection
NMS is greedy—it always picks the highest-confidence box first, then removes competitors. This order matters!
Hard Threshold Problem
Standard NMS uses a binary decision: IoU ≥ threshold means removal. This cliff effect can eliminate valid nearby objects.
Score Decay
Soft-NMS replaces removal with decay—overlapping boxes have their scores reduced proportionally to overlap, not set to zero.
Class-Specific Suppression
NMS is typically applied per-class, so a 'person' box won't suppress a 'car' box even if they overlap significantly.
The standard NMS algorithm is deceptively simple but has important implications:
NMS Step-by-Step Animation
Non-Maximum Suppression (NMS)
Watch the greedy algorithm remove duplicate detections step by step
IoU Threshold:50%
Step 1 of 14Sort by Confidence
95%88%82%79%71%65%
Kept
Suppressed
Comparing
Remaining
Sort by Confidence
Sort all detection boxes by confidence score (descending)
0
Kept
0
Suppressed
#095%
#188%
#282%
#379%
#471%
#565%
Key Insight: NMS is greedy — it always keeps the highest-confidence box first, then removes overlapping boxes. This can accidentally suppress valid detections of nearby objects!
How It Works
1
Sort by Confidence
Arrange all detections in descending order by confidence score. The most confident prediction will be processed first.
2
Select Maximum
Take the highest-confidence remaining box as a 'keeper'. This box is guaranteed to survive.
3
Compute Overlap
Calculate IoU between the keeper and every remaining box. High IoU indicates potential duplicates.
4
Suppress Overlapping
Remove any box with IoU ≥ threshold (typically 0.5). These are considered duplicates of the keeper.
5
Repeat
Continue with the remaining boxes until none are left. Each iteration picks one keeper.
Standard NMS works well for isolated objects, but struggles with crowded scenes. Consider two people standing close together—their detection boxes will naturally overlap. If IoU exceeds the threshold, the lower-confidence detection is completely removed, even though it represents a valid, separate person.
Hard NMS vs Soft-NMS Comparison
Hard NMS vs Soft-NMS
Compare how different suppression strategies handle overlapping detections
IoU Threshold (Nt):0.50
σ (Gaussian):0.5
Score Decay Functions
IoU with highest-confidence boxScore multiplier00.250.50.75100.51NtHard NMSSoft (Gaussian)Soft (Linear)
Example: Two People Standing Close Together
Detection
Original
IoU
Hard NMS
Soft (Gaussian)
Soft (Linear)
Person 1 (highest)
0.92
—
0.92 ✓
0.92 ✓
0.92 ✓
Person 2 (valid!)(nearby object)
0.85
0.29
0.85
0.72✓ Kept
0.85✓ Kept
Duplicate
0.78
0.83
0.00
0.20
0.13
Hard NMS
KeptREMOVED
Valid detection lost due to binary decision
Soft-NMS (Gaussian)
0.920.72Reduced
Score decays smoothly with overlap
Soft-NMS (Linear)
0.920.85Reduced
Linear penalty above threshold
Hard NMS
si = 0 if IoU ≥ Nt
Soft-NMS (Gaussian)
si = si × e−IoU²/σ
Soft-NMS (Linear)
si = si × (1 − IoU) if IoU ≥ Nt
Key Insight: Soft-NMS preserves nearby valid detections by decaying scores instead of removing boxes entirely. This is especially useful for crowded scenes with overlapping objects!
Different detection scenarios call for different suppression strategies:
NMS Variants Comparison
NMS Variants Comparison
Different algorithms for different detection challenges
Greedy NMS
Original algorithm. Simple and fast, but uses hard threshold.
s_i = 0 if IoU(M, b_i) ≥ N_t
Best for: General object detection with well-separated objects
Advantages
+Very fast (O(n log n))
+Simple to implement
+Well-understood behavior
Limitations
−Hard threshold problem
−May suppress valid detections
−Sensitive to IoU threshold
Choose the Right NMS for Your Scenario
Performance Characteristics
Algorithm
Speed
Accuracy
Crowded Scenes
GPU-Friendly
Greedy NMS
●●●●●
●●●○○
●●○○○
●●●○○
Soft-NMS
●●●○○
●●●●○
●●●●○
●●●○○
DIoU-NMS
●●●○○
●●●●○
●●●○○
●●●○○
Weighted NMS
●●○○○
●●●●●
●●●●○
●●○○○
Matrix NMS
●●●●●
●●●○○
●●●○○
●●●●●
Practical Advice: Start with Greedy NMS for baseline. Switch to Soft-NMS for crowded scenes. Use Matrix NMS when speed is critical. Consider DIoU-NMS for occluded objects.