Inferensys

Glossary

Non-Maximum Suppression (NMS)

A post-processing algorithm used in object detection to eliminate redundant bounding boxes by selecting the one with the highest confidence score and suppressing others with high IoU overlap.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
POST-PROCESSING ALGORITHM

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.

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.

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.

ALGORITHM FUNDAMENTALS

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.

01

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.
0.5
Typical IoU Threshold
02

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).
03

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.
04

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.
05

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.
06

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.
NON-MAXIMUM SUPPRESSION

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.

SUPPRESSION STRATEGY COMPARISON

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.

FeatureGreedy NMSSoft-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

Prasad Kumkar

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.