Course contentsShow
← Machine Learning and Deep Learning
Lesson 954 of 3,53822. Computer Vision TasksFree lesson

Non-Maximum Suppression (NMS)

Understand NMS algorithm for removing duplicate detections and keeping only the best bounding box per object.

Non-Maximum Suppression (NMS)

What you'll learn: How NMS cleans up overlapping bounding boxes to select the best detection for each object.

The Problem: Too Many Boxes

When object detectors run, they often generate many bounding boxes for the same object—especially when using sliding windows or anchor boxes at multiple scales. Imagine detecting a car: you might get 10 overlapping boxes all claiming to have found it, each with slightly different positions and confidence scores.

NMS solves this by keeping only the best box per object and suppressing (removing) the redundant ones.

How NMS Works

The algorithm is straightforward:

  1. Sort all bounding boxes by their confidence scores (highest first)
  2. Select the box with the highest confidence and add it to your final output
  3. Suppress all remaining boxes that overlap significantly with this selected box (using IoU threshold, typically 0.5)
  4. Repeat with the next highest-confidence box from the remaining pool
  5. Continue until no boxes remain

The Key Ingredient: IoU

Remember that IoU (Intersection over Union) measures overlap between boxes. If two boxes have IoU > 0.5 (a common threshold), they're likely detecting the same object. NMS keeps the higher-confidence one and discards the other.

Analogy: Voting for Class President

Imagine multiple students nominating candidates. NMS is like saying: "Keep the most popular candidate, then remove all other nominations that are basically the same person (high overlap). Now repeat with remaining nominations."

Key Takeaway: Non-Maximum Suppression removes duplicate detections by iteratively selecting the highest-confidence box and suppressing overlapping boxes, ensuring each object gets only one final bounding box.