YOLOv8 Non-Maximum Suppression, or NMS, is a post-processing step used to remove redundant overlapping bounding boxes from object detection predictions. A detector may initially produce several boxes around the same object. NMS compares their confidence scores and overlap, keeps the strongest detection, and suppresses weaker overlapping boxes. Current Ultralytics prediction settings expose parameters such as conf, iou, and agnostic_nms to control this behavior during inference.
NMS is important because raw detector output can contain many candidate detections. Without suppression, the same person, vehicle, or other object could appear several times in the final prediction results. Properly configured NMS helps reduce duplicate detections while attempting to preserve separate objects that happen to be close together.
Introduction to YOLOv8 Non-Maximum Suppression
YOLOv8 performs object detection by generating candidate bounding boxes together with class information and confidence scores. Before these predictions are returned to the user, they usually pass through post-processing that removes weak or redundant detections.
One of the most important parts of this post-processing is Non-Maximum Suppression.
A simplified prediction flow is:
Input Image
↓
YOLOv8 Network
↓
Candidate Bounding Boxes
↓
Confidence Filtering
↓
Non-Maximum Suppression
↓
Final Detections
Suppose the detector sees one car but initially produces four highly overlapping boxes around it:
Box A → confidence 0.94
Box B → confidence 0.88
Box C → confidence 0.71
Box D → confidence 0.60
These boxes may all correspond to the same physical car. NMS evaluates the overlap between them and typically keeps the strongest relevant detection while removing redundant alternatives. Ultralytics documents its NMS utility as filtering overlapping bounding boxes based on confidence and IoU thresholds.
The goal is not simply to remove boxes. The goal is to produce a cleaner set of final detections that better represents the number of actual objects in the image.
What Is Non-Maximum Suppression in YOLOv8?
Non-Maximum Suppression is an algorithm used after the model generates candidate predictions.
It generally performs three major tasks:
1. Remove weak predictions
2. Compare overlapping boxes
3. Keep stronger detections and suppress redundant ones
Current Ultralytics implements NMS as a dedicated utility for filtering predictions using confidence and IoU thresholds.
The word maximum refers to keeping the detection with the strongest score among overlapping candidates, while suppression refers to removing competing boxes that overlap too heavily.
Why Multiple Bounding Boxes Appear
Object detectors often generate many candidate predictions before post-processing.
For one object, the raw output might conceptually include:
Car:
Box 1 → 0.96
Box 2 → 0.90
Box 3 → 0.84
Box 4 → 0.65
The boxes may have slightly different:
center positions
widths
heights
confidence scores
This happens because the network evaluates many possible object locations and predictions.
The raw output is therefore not necessarily intended to be the final set of visible boxes.
Purpose of NMS in Object Detection
The purpose of NMS is to transform many overlapping candidate predictions into a smaller, cleaner set.
For example:
Before NMS:
Object 1
├── Box A 0.95
├── Box B 0.89
├── Box C 0.77
└── Box D 0.64
After NMS:
Object 1
└── Box A 0.95
This reduces:
- duplicate detections,
- repeated boxes around one object,
- unnecessary prediction clutter.
NMS also helps ensure that downstream applications such as object counting, tracking, or alert systems do not mistakenly treat several overlapping predictions as separate objects.
How YOLOv8 Non-Maximum Suppression Works
The basic NMS process combines confidence filtering with overlap comparison.
Ultralytics’ NMS implementation accepts a confidence threshold and IoU threshold and returns filtered detections after suppression.
A simplified process looks like:
Candidate Predictions
↓
Remove Low Confidence Boxes
↓
Sort Remaining Boxes by Score
↓
Keep Highest Confidence Box
↓
Calculate IoU with Other Boxes
↓
Suppress Excessively Overlapping Boxes
↓
Repeat
This continues until the remaining candidates have been processed.
Filtering Predictions by Confidence Score
Before expensive overlap comparisons are applied, low-confidence predictions can be removed.
Suppose predictions are:
Box A → 0.93
Box B → 0.81
Box C → 0.29
Box D → 0.08
If:
conf=0.25
then Box D is below the threshold and can be discarded.
Ultralytics exposes conf as a prediction setting that determines the minimum confidence required for a detection to be retained.
This reduces the number of boxes that need further processing.
Comparing Bounding Boxes with IoU
After confidence filtering, NMS compares box overlap using Intersection over Union, commonly abbreviated as IoU.
The formula is:
IoU =
Area of Intersection
────────────────────
Area of Union
If two boxes almost completely overlap, IoU may be high:
IoU = 0.85
If they only overlap slightly:
IoU = 0.20
The configured NMS IoU threshold determines how much overlap is allowed before a weaker box is suppressed. Current Ultralytics NMS exposes an iou_thres parameter for this purpose.
Keeping the Best Bounding Box
NMS typically starts with the highest-confidence box.
Suppose:
Box A → confidence 0.94
Box B → confidence 0.86
and:
IoU(A, B) = 0.80
If the NMS threshold is:
iou=0.70
the overlap exceeds the threshold.
Conceptually:
Keep Box A
Suppress Box B
because Box A has the stronger confidence score.
This process is repeated with remaining boxes until the final detection list is produced.
YOLOv8 NMS and IoU Threshold
The NMS IoU threshold controls how tolerant the algorithm is toward overlapping boxes.
Current Ultralytics prediction configuration exposes iou for this behavior.
This setting should not be confused with the IoU thresholds used when calculating metrics such as mAP50 or mAP50-95 during validation. The NMS IoU threshold is specifically related to deciding whether overlapping predictions should be suppressed.
How IoU Controls Box Suppression
Suppose:
Box A vs Box B IoU = 0.65
If:
iou=0.50
then the overlap is above the threshold, making suppression more likely.
If:
iou=0.80
then the same two boxes may both remain because their 0.65 overlap is below the threshold.
Therefore:
Lower NMS IoU
→ stronger suppression
Higher NMS IoU
→ more overlapping boxes retained
Effect of a Low IoU Threshold
A low threshold makes NMS more aggressive.
For example:
iou=0.30
means boxes do not need to overlap very heavily before a weaker one can be removed.
Possible advantages include:
- fewer duplicate boxes,
- cleaner predictions.
Possible disadvantages include:
- separate nearby objects may be suppressed,
- crowded scenes may lose valid detections.
Consider two people standing close together. Their boxes may overlap significantly. An overly aggressive IoU threshold can mistakenly treat them as duplicates.
Effect of a High IoU Threshold
A higher threshold allows boxes to overlap more before suppression occurs.
For example:
iou=0.80
requires a high level of overlap before a weaker detection is removed.
Advantages can include:
- preserving close objects,
- reducing accidental suppression in crowded scenes.
Disadvantages can include:
- duplicate detections remaining,
- several boxes appearing around one object.
The correct value depends on how closely objects appear in the target dataset.
YOLOv8 NMS and Confidence Threshold
The confidence threshold and NMS IoU threshold work together, but they control different stages of prediction filtering.
Current Ultralytics Predict mode exposes conf and iou independently.
A useful distinction is:
conf
→ Is this prediction strong enough to consider?
iou
→ Is this prediction too similar to another box?
Removing Low-Confidence Predictions
Suppose the detector produces:
person 0.91
person 0.74
person 0.31
person 0.12
With:
conf=0.25
the final candidate set before NMS might include:
0.91
0.74
0.31
while:
0.12
is removed.
Increasing the confidence threshold can reduce low-quality detections.
Balancing Precision and Recall
Confidence affects the precision-recall balance.
In general:
Higher confidence threshold
→ fewer detections
→ usually fewer false positives
→ precision may improve
→ recall may decrease
while:
Lower confidence threshold
→ more detections
→ recall may improve
→ false positives may increase
→ precision may decrease
NMS then processes the retained predictions to remove excessive overlap.
Therefore, confidence tuning and NMS IoU tuning should be treated as separate but related adjustments.
How to Configure NMS in YOLOv8
Ultralytics allows the main NMS-related inference parameters to be configured through the command line or Python API.
The most important controls are:
conf
iou
agnostic_nms
max_det
classes
Current prediction configuration documents these settings for inference.
Set NMS Parameters Using the YOLO CLI
A simple command is:
yolo detect predict model=best.pt source=image.jpg conf=0.25 iou=0.70
This sets:
confidence threshold = 0.25
NMS IoU threshold = 0.70
You can also enable class-agnostic NMS:
yolo detect predict model=best.pt source=image.jpg conf=0.25 iou=0.70 agnostic_nms=True
Current Ultralytics Predict mode supports agnostic_nms as an inference argument.
Configure NMS in Python
Using Python:
from ultralytics import YOLO
model = YOLO("best.pt")
results = model.predict(
source="image.jpg",
conf=0.25,
iou=0.70
)
For class-agnostic NMS:
results = model.predict(
source="image.jpg",
conf=0.25,
iou=0.70,
agnostic_nms=True
)
The same prediction arguments are available through the Python API.
Adjust Confidence and IoU Thresholds
A useful tuning workflow is:
Baseline:
conf=0.25
iou=0.70
If too many weak detections remain:
increase conf
For example:
conf=0.40
If duplicate boxes remain:
reduce iou moderately
For example:
iou=0.60
If legitimate crowded objects are being removed:
increase iou
For example:
iou=0.80
Always test these changes on representative validation or deployment images.
Class-Aware vs Class-Agnostic NMS
NMS can consider class identity when suppressing boxes.
Ultralytics supports both class-aware and class-agnostic behavior through its NMS implementation and agnostic_nms prediction setting.
How Class-Aware NMS Works
In class-aware NMS, overlapping boxes from different predicted classes are treated separately.
Suppose one location contains:
Box A → car 0.90
Box B → truck 0.86
Even if the boxes overlap heavily, class-aware NMS can preserve them as belonging to different categories.
Conceptually:
Same class
→ compare for suppression
Different class
→ processed separately
This is useful when different object classes can genuinely overlap.
When to Use Class-Agnostic NMS
Class-agnostic NMS ignores class identity when comparing overlap.
Enable it with:
agnostic_nms=True
Then heavily overlapping boxes can compete even if their predicted class IDs differ. Ultralytics documents this option as class-agnostic NMS.
This may be useful when:
- several classes represent mutually exclusive object types,
- one physical object frequently receives duplicate predictions from multiple classes,
- you only want one detection at a location.
However, it can be harmful if different classes legitimately overlap.
For example:
person inside car region
or:
helmet overlapping person
may require class-aware behavior.
NMS for Overlapping and Crowded Objects
Crowded scenes are one of the hardest cases for standard NMS.
If multiple legitimate objects overlap heavily, the algorithm must distinguish between:
duplicate predictions
and:
different real objects located very close together
The same IoU threshold cannot perfectly solve every case.
Challenges with Close Objects
Imagine five people standing close together.
Their boxes may look like:
Person A box
overlaps Person B box
Person B box
overlaps Person C box
A low NMS IoU threshold can cause valid detections to be removed because they look too similar geometrically.
This is especially common with:
- dense crowds,
- grouped animals,
- parked vehicles,
- fruit clusters,
- shelf products,
- cells or small objects in scientific imagery.
Preventing Valid Detections from Being Removed
If valid nearby objects are being suppressed, try increasing the NMS IoU threshold.
For example:
iou=0.50
may be too aggressive.
Testing:
iou=0.70
or:
iou=0.80
may allow more nearby boxes to survive.
However, increasing the value too far can reintroduce duplicate detections.
The correct value therefore depends on real object density.
Tuning NMS for Crowded Scenes
A useful crowded-scene experiment is:
Run A:
conf=0.25
iou=0.50
Run B:
conf=0.25
iou=0.70
Run C:
conf=0.25
iou=0.80
Then compare:
missed objects
duplicate boxes
precision
recall
object counts
Do not evaluate only visually easy images.
Include the densest scenes in your test set because those are where NMS differences become most visible.
How NMS Affects YOLOv8 Performance
NMS primarily affects post-processing rather than changing the learned model weights.
The underlying network output remains the same. What changes is which candidate boxes are returned after filtering.
Ultralytics’ detection predictor uses NMS during post-processing of model outputs.
Impact on False Positives
Increasing confidence filtering can reduce false positives.
More aggressive NMS can also eliminate redundant boxes that might otherwise look like multiple false detections.
However, NMS cannot fix every false positive.
If the model confidently detects background objects incorrectly, improving the dataset or retraining may be necessary.
Impact on Duplicate Detections
Duplicate detections are the main problem NMS is designed to reduce.
For example:
Without effective suppression:
car 0.95
car 0.89
car 0.81
around one real car.
After proper NMS:
car 0.95
remains.
If duplicates continue to appear, the IoU threshold may be too permissive or predictions may not overlap enough to be considered duplicates.
Impact on Inference Speed
NMS adds post-processing work after model inference.
The cost depends partly on how many candidate detections survive confidence filtering.
If thousands of candidates need overlap comparison, post-processing becomes more expensive.
Ultralytics’ NMS utility includes controls such as confidence filtering and maximum detection counts to keep post-processing manageable.
For most standard detection workloads, the neural network itself remains the major computational component, but NMS cost can become noticeable with large numbers of candidate boxes.
Common YOLOv8 NMS Problems
NMS problems are usually visible as either too many boxes or too few valid detections.
Before changing parameters, inspect whether the issue is really caused by NMS or by poor model predictions.
Duplicate Bounding Boxes Remain
If several boxes remain around one object, possible causes include:
- IoU threshold too high,
- boxes do not overlap enough,
- class-aware NMS sees different classes,
- confidence threshold is too low,
- model produces unstable localization.
Possible tests include:
lower iou
increase conf
enable agnostic_nms
but only when appropriate for the dataset.
Valid Objects Are Suppressed
If nearby real objects disappear, NMS may be too aggressive.
Possible cause:
iou threshold too low
For example:
iou=0.30
may suppress boxes that belong to separate objects.
Try a higher value and evaluate crowded-scene recall.
Too Many False Positives
NMS mainly handles overlap, so false positives caused by incorrect object recognition may require more than NMS tuning.
Useful actions include:
increase conf moderately
add difficult negative images
fix missing labels
improve class definitions
retrain model
Do not continuously increase NMS suppression if false detections occur in completely different locations.
Poor Results in Crowded Scenes
Crowded scenes may produce:
missed objects
merged detections
suppressed valid boxes
Increase the NMS IoU threshold gradually and evaluate recall.
Also inspect the model itself. If the detector never generates separate candidate boxes for neighboring objects, changing NMS alone cannot recover detections that were never produced.
FAQs About YOLOv8 Non-Maximum Suppression
What is NMS in YOLOv8?
NMS, or Non-Maximum Suppression, is a post-processing algorithm that removes redundant overlapping bounding boxes from YOLO predictions.
It considers confidence scores and box overlap to keep stronger detections and suppress weaker duplicates. Ultralytics provides a dedicated NMS utility for this processing.
Why does YOLOv8 use non-maximum suppression?
YOLOv8 may initially produce multiple candidate boxes for the same object.
NMS converts these redundant candidates into a cleaner final detection set.
Without effective suppression, one real object could appear several times in the results.
What IoU threshold should I use for NMS?
There is no universal best threshold.
A reasonable baseline is to start with the current prediction defaults or the settings already used by your Ultralytics version, then tune according to your data. Current Ultralytics prediction configuration exposes iou as the NMS overlap threshold.
In general:
lower iou
→ stronger suppression
higher iou
→ more overlapping detections survive
Crowded datasets may need a higher value than sparse scenes.
What is the difference between confidence threshold and IoU threshold?
Confidence threshold answers:
Is this detection strong enough to keep?
IoU threshold answers:
Does this detection overlap too much with another box?
For example:
conf=0.25
iou=0.70
means predictions below 0.25 confidence are removed, while NMS uses 0.70 as its overlap threshold for suppression behavior. Both are independently configurable in Ultralytics Predict mode.
What is class-agnostic NMS in YOLOv8?
Class-agnostic NMS ignores class labels when deciding whether overlapping boxes compete with each other.
Enable it with:
agnostic_nms=True
Current Ultralytics exposes this parameter in prediction settings.
It can reduce duplicate boxes across different predicted classes but may also suppress valid overlapping objects from different categories.
Can NMS remove correct detections?
Yes.
If two real objects are very close and their boxes overlap strongly, aggressive NMS can incorrectly remove one.
This is more likely when the IoU threshold is too low for crowded scenes.
Increase the threshold carefully and compare recall and duplicate detections.
How can I reduce duplicate boxes in YOLOv8?
Possible approaches include:
reduce the NMS IoU threshold
increase the confidence threshold moderately
consider agnostic_nms=True
improve model training if box localization is unstable
Do not change several parameters simultaneously during testing.
Compare one change at a time on representative images.
Conclusion
YOLOv8 Non-Maximum Suppression is a critical post-processing step that removes redundant overlapping predictions and converts raw model output into a cleaner final set of bounding boxes.
The basic NMS workflow is:
YOLOv8 Predictions
↓
Confidence Filtering
↓
Sort Candidate Boxes
↓
Keep Highest-Score Box
↓
Calculate IoU
↓
Suppress Excessively Overlapping Boxes
↓
Repeat
↓
Final Detections
Current Ultralytics exposes the most important NMS-related controls through:
conf
iou
agnostic_nms
max_det
and its NMS utility explicitly filters predictions using confidence and IoU thresholds.
A practical Python configuration is:
from ultralytics import YOLO
model = YOLO("best.pt")
results = model.predict(
source="image.jpg",
conf=0.25,
iou=0.70,
agnostic_nms=False
)
The most important relationships are:
Higher confidence threshold
→ fewer weak detections
Lower NMS IoU threshold
→ stronger suppression
Higher NMS IoU threshold
→ more overlapping boxes retained
agnostic_nms=False
→ class-aware suppression
agnostic_nms=True
→ suppression can occur across classes
NMS tuning is especially important for crowded scenes, dense object detection, and applications where duplicate boxes affect counting or tracking. However, NMS should not be used as a substitute for improving a poorly trained model. If false positives occur at unrelated image locations or valid objects are never predicted in the first place, changes to the dataset, annotations, training configuration, or model may be required.
The best approach is to evaluate several confidence and IoU settings on representative validation images and choose the configuration that provides the best balance between duplicate suppression, false positives, and preservation of valid nearby detections.
I’m Jane Austen, a skilled content writer with the ability to simplify any complex topic. I focus on delivering valuable tips and strategies throughout my articles.