Non-Max Suppression

kamal_DS
2 min readMar 14, 2023

--

Non-Maximum Suppression (NMS) is a post-processing step used in YOLOv3 and other object detection models to remove redundant bounding box predictions and improve the accuracy of object detection.

The basic idea of NMS is to compare the predicted bounding boxes for each object and only keep the one with the highest confidence score. This is because, in many cases, multiple bounding boxes may be predicted for the same object, and it is important to select the most accurate one.

Before NMS:

The NMS algorithm works as follows:

  1. Sort the predicted bounding boxes based on their confidence scores in descending order.
  2. Select the bounding box with the highest confidence score and remove all other boxes that overlap significantly with it (i.e., have a high Intersection over Union (IoU) score).
  3. Repeat step 2 until all boxes have been processed.

The key parameter in NMS is the IoU threshold, which determines how much overlap is allowed between two boxes before they are considered redundant. This threshold is typically set to a value between 0.5 and 0.7, depending on the specific use case and dataset.

NMS helps to reduce the number of false positives and improves the overall detection accuracy of the model. Without NMS, the model may generate multiple bounding box predictions for the same object, leading to duplication in the output and a decrease in accuracy.

Overall, Non-Maximum Suppression is a crucial step in object detection models like YOLOv3 to ensure that only the most accurate bounding box predictions are kept and redundant predictions are removed.

Here’s the math behind the calculation of IoU:

  • Intersection area (A<sub>int</sub>) between two boxes with coordinates (x<sub>1</sub>, y<sub>1</sub>, w<sub>1</sub>, h<sub>1</sub>) and (x<sub>2</sub>, y<sub>2</sub>, w<sub>2</sub>, h<sub>2</sub>) can be calculated as follows:
  • A<sub>int</sub> = max(0, min(x<sub>1</sub>+w<sub>1</sub>, x<sub>2</sub>+w<sub>2</sub>) — max(x<sub>1</sub>, x<sub>2</sub>)) * max(0, min(y<sub>1</sub>+h<sub>1</sub>, y<sub>2</sub>+h<sub>2</sub>) — max(y<sub>1</sub>, y<sub>2</sub>))
  • Union area (A<sub>uni</sub>) between the same two boxes can be calculated as:
  • A<sub>uni</sub> = A<sub>box1</sub> + A<sub>box2</sub> — A<sub>int</sub>, where A<sub>box1</sub> = w<sub>1</sub> * h<sub>1</sub> and A<sub>box2</sub> = w<sub>2</sub> * h<sub>2</sub>
  • Finally, the IoU between the two boxes is calculated as:
  • IoU = A<sub>int</sub> / A<sub>uni</sub>

After NMS

Follow Yolov3 Object detection : https://medium.com/p/74cf9ade2044/edit

LinkedIn : https://www.linkedin.com/in/sai-kamal-korlakunta-a81326163/

--

--

kamal_DS

Interested to work in the field of Artificial Intelligence, Machine Learning, Deep Learning, NLP and Computer Vision.