Non-Maximum Suppression (NMS) is a post-processing algorithm that resolves the problem of multiple, overlapping bounding boxes for a single object by selecting the detection with the highest confidence score and suppressing all others that exceed a predefined Intersection over Union (IoU) threshold. This greedy, iterative process begins by sorting all predicted boxes by their confidence, then systematically removes any box whose overlap with the chosen box is too high, ensuring a clean, non-redundant output.
Glossary
Non-Maximum Suppression (NMS)

What is Non-Maximum Suppression (NMS)?
Non-Maximum Suppression is a critical post-processing algorithm in object detection that eliminates redundant, overlapping bounding boxes to ensure each detected object is represented by a single, high-confidence prediction.
The algorithm's behavior is governed by the IoU threshold, a hyperparameter that defines the maximum allowed spatial overlap between distinct detections. A low threshold aggressively suppresses boxes, risking missed detections in crowded scenes, while a high threshold may leave duplicate predictions. Variants like Soft-NMS decay scores rather than hard-suppressing boxes, improving performance on occluded objects common in dense manufacturing inspection environments.
Key Characteristics of NMS
Non-Maximum Suppression is a critical post-processing step in object detection pipelines that resolves the problem of multiple overlapping bounding boxes for the same object. By selecting the most confident detection and suppressing redundant proposals, NMS ensures clean, actionable outputs for downstream quality inspection logic.
Greedy Selection Algorithm
NMS operates on a greedy selection principle to iteratively build a final set of detections. The algorithm sorts all predicted bounding boxes by their confidence score in descending order. It selects the highest-scoring box, then computes the Intersection over Union (IoU) between this box and all remaining boxes. Any box with an IoU exceeding a predefined threshold is considered a duplicate and is suppressed (removed). This process repeats with the next highest-scoring surviving box until no boxes remain. This deterministic behavior makes NMS highly predictable and debuggable in production environments.
- Sorting: Boxes are ranked by confidence score before processing.
- IoU Threshold: A hyperparameter, typically set between 0.3 and 0.7, that controls suppression aggressiveness.
- Iterative Loop: Continues until the candidate list is exhausted.
Resolving Multiple Detections
Without NMS, object detectors like YOLO or Faster R-CNN often produce numerous bounding boxes clustered around a single object. This happens because the model's region proposal network or grid-based prediction generates multiple high-confidence anchors for the same defect. NMS is the mechanism that collapses this cluster into a single, precise localization. For a quality assurance director, this means one defect on a part results in exactly one alarm, preventing a single scratch from triggering a cascade of false alerts that would halt the production line unnecessarily.
- Anchor Overlap: Inherent to dense prediction architectures.
- Single Alarm Principle: Ensures one defect equals one detection event.
- Clean Output: Prepares data for downstream metrics like Mean Average Precision (mAP).
Soft-NMS Variant
Standard NMS uses a hard threshold, completely removing boxes above the IoU limit. This can be problematic in crowded scenes where two distinct objects of the same class are very close together. Soft-NMS addresses this by applying a continuous penalty function. Instead of zeroing out the score of an overlapping box, Soft-NMS decays its confidence score based on the IoU overlap. A box with 0.9 IoU receives a heavy penalty, while a box with 0.6 IoU receives a lighter one. This preserves detections of genuinely separate but adjacent objects, which is critical for inspecting densely packed components on a circuit board.
- Continuous Penalty: Uses a Gaussian or linear decay function.
- Crowded Scene Preservation: Retains detections for adjacent, non-duplicate objects.
- Computational Cost: Marginally higher than standard NMS due to score recalculation.
Class-Agnostic vs. Class-Specific
NMS can be applied in two modes depending on the detection architecture. Class-Agnostic NMS treats all bounding boxes equally regardless of their predicted class, suppressing any highly overlapping box. This is fast but risks suppressing a true positive of a different class that happens to overlap. Class-Specific NMS applies the suppression algorithm independently for each class. A 'scratch' detection will not suppress a 'dent' detection even if they overlap significantly. In manufacturing, class-specific NMS is essential when multiple defect types can co-occur on the same component surface.
- Class-Agnostic: Faster, but risks cross-class suppression.
- Class-Specific: Applies NMS per class label, preserving co-occurring defect types.
- Use Case: Essential for multi-class defect detection on complex assemblies.
Impact on Precision and Recall
The IoU threshold in NMS directly trades off between precision and recall. A low threshold (e.g., 0.3) aggressively suppresses boxes, reducing false positives and increasing precision, but risks removing true positives for clustered objects, lowering recall. A high threshold (e.g., 0.7) is more permissive, preserving true positives and boosting recall, but may allow duplicate detections to pass through, decreasing precision. Tuning this threshold on a validation set using a Gage Repeatability and Reproducibility (GR&R) study ensures the inspection system meets the required balance for the specific manufacturing tolerance.
- Low Threshold: Higher precision, lower recall. Risk of missed defects.
- High Threshold: Higher recall, lower precision. Risk of duplicate counts.
- Tuning: Must be validated against ground truth data for the specific product.
NMS in Modern Detectors
While NMS remains a standard post-processing step, some modern architectures aim to eliminate it. End-to-end detectors like the Detection Transformer (DETR) use a transformer encoder-decoder with a set-based global loss that performs bipartite matching, forcing the model to predict a unique set of detections without any need for NMS. Similarly, anchor-free methods like CenterNet predict object centers and regress dimensions, inherently reducing duplicate proposals. However, for high-speed, single-stage detectors like YOLO deployed on the edge, NMS remains the de facto standard due to its simplicity and low computational overhead.
- DETR: Uses bipartite matching loss to eliminate NMS entirely.
- CenterNet: Predicts a single heatmap peak per object.
- Edge Deployment: NMS remains preferred for its speed and deterministic execution on embedded hardware.
Frequently Asked Questions
Clear, technical answers to the most common questions about how Non-Maximum Suppression works, why it's essential for object detection, and how to optimize it for manufacturing quality inspection.
Non-Maximum Suppression (NMS) is a post-processing algorithm that eliminates redundant bounding boxes in object detection by retaining only the prediction with the highest confidence score and discarding all others that have a high spatial overlap. The algorithm operates by first sorting all detected boxes by their confidence score in descending order. It then iteratively selects the highest-scoring box, computes its Intersection over Union (IoU) with every remaining box, and suppresses any box whose IoU exceeds a predefined threshold—typically 0.5. This process repeats until no boxes remain, ensuring each object in the image is represented by a single, optimal bounding box. Without NMS, detectors like YOLO and Faster R-CNN would output dozens of overlapping predictions for the same defect, making automated quality inspection unworkable.
NMS Variants: Greedy vs. Soft-NMS
Comparison of the standard greedy Non-Maximum Suppression algorithm with the Soft-NMS variant, which decays scores instead of hard-suppressing overlapping boxes to improve recall in dense object scenes.
| Feature | Greedy NMS | Soft-NMS |
|---|---|---|
Suppression Mechanism | Hard suppression: removes all boxes exceeding IoU threshold | Soft suppression: decays confidence scores of overlapping boxes via a penalty function |
Confidence Score Handling | Sets score to 0 for suppressed boxes | Reduces score proportionally to IoU overlap |
Handling Dense Object Scenes | Prone to missing adjacent objects of the same class | Preserves detections of nearby objects with high overlap |
Recall Performance | Lower recall in crowded scenes | Higher recall, especially at elevated IoU thresholds |
Computational Complexity | O(N²) with standard implementation | O(N²) with a small constant factor overhead for score decay computation |
Hyperparameters | Single IoU threshold (e.g., 0.5) | IoU threshold plus decay penalty function (linear or Gaussian) and optional sigma parameter |
Integration Complexity | Trivial drop-in post-processing step | Requires modifying the scoring loop; still a straightforward post-processing step |
Typical mAP Improvement | +1-2% mAP on COCO-style benchmarks with crowded scenes |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Non-Maximum Suppression is a critical post-processing step that sits within a larger object detection ecosystem. These related concepts define the inputs, outputs, and evaluation context for NMS.
Intersection over Union (IoU)
The primary geometric criterion that NMS uses to determine if two bounding boxes are detecting the same object. IoU computes the ratio of the area of overlap to the area of union between two boxes.
- Formula:
IoU = Area of Overlap / Area of Union - NMS Role: If the IoU between a high-confidence box and a lower-confidence box exceeds a set threshold (e.g., 0.5), the lower-confidence box is suppressed.
- Threshold Tuning: A higher IoU threshold (e.g., 0.7) is more permissive, keeping more boxes; a lower threshold (e.g., 0.3) is more aggressive, suppressing more.
Mean Average Precision (mAP)
The standard evaluation metric for object detectors that directly measures the impact of NMS on final model performance. mAP computes the area under the precision-recall curve averaged across all classes.
- Sensitivity to NMS: Overly aggressive NMS increases false negatives (missed detections), lowering recall and mAP. Overly permissive NMS increases false positives, lowering precision and mAP.
- [email protected]: The most common variant, using an IoU threshold of 0.5 to determine a true positive match.
- [email protected]:0.95: A stricter variant averaging mAP across IoU thresholds from 0.5 to 0.95 in 0.05 increments, penalizing imprecise localization.
Confusion Matrix
The tabular foundation for understanding the downstream quality impact of NMS decisions. Every suppression or retention action shifts the counts of true positives, false positives, and false negatives.
- False Positive (FP): A redundant box that NMS failed to suppress, incorrectly flagged as a defect.
- False Negative (FN): A valid detection that NMS incorrectly suppressed, causing a missed defect.
- Precision/Recall Trade-off:
Precision = TP / (TP + FP)andRecall = TP / (TP + FN). NMS threshold tuning directly navigates this trade-off.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us