Non-Maximum Suppression for Object Detection

Detection, Video & Advanced Vision DS practice problem on Onlearn.

Difficulty: hard.

Topics: Non-Maximum Suppression for Object Detection, Intersection over Union (IoU), Confidence Score Thresholding, Greedy Selection Strategy, Overlap Suppression, Candidate Box Ranking, Computer Vision, Optimization Theory, Computational Geometry, Probability and Statistics, Software Engineering, Object Detection Architectures, Bounding Box Regression, Heuristic Filtering Algorithms, Performance Evaluation Metrics, Spatial Data Structures.

Task: Implement Non Maximum Suppression (NMS) Non Maximum Suppression is a critical post processing technique in object detection pipelines. When object detectors like YOLO, SSD, or Faster R CNN generate predictions, they often produce multiple overlapping bounding boxes for the same object. NMS filters these redundant detections by keeping only the most confident box and suppressing boxes that significantly overlap with it. Input: boxes: An array like of shape (N, 4) containing N bounding boxes in format [x1, y1, x2, y2] where (x1, y1) is the top left corner and (x2, y2) is the bottom right corner scores: An array like of shape (N,) containing confidence scores for each box iou threshold: A float between 0 and 1 specifying the Intersection over Union threshold for suppression Output: Return a list of indices of the kept boxes, ordered by descending confidence score Return 1 for invalid inputs (mismatched dimensions, invalid shapes, threshold out of range) Return empty list for empty input Algorithm Overview: 1. Select the box with the highest confidence score 2. Remove all boxes that have high IoU overlap with the selected box 3. Repeat until no boxes remain IoU (Intersection over Union): The IoU between two boxes measures their overlap and is computed as the area of intersection divided by the area of union.