Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Non-Max Suppression (NMS) is a common post-processing step in object detection that removes duplicate bounding boxes for the same object. You’ll implement classic greedy NMS based on Intersection-over-Union (IoU), keeping only the most confident boxes.
The key overlap metric is:
Implement the function
Rules:
max(0, ...)).scores.Output:
| Argument | Type |
|---|---|
| boxes | np.ndarray |
| scores | np.ndarray |
| iou_threshold | float |
| Return Name | Type |
|---|---|
| value | list |
Use only NumPy.
Return original indices sorted by score.
Suppress boxes if IoU > threshold.
Start by sorting the indices of the boxes by scores descending; you will iterate through this ordered list and build a keep list of original indices.
Implement an iou(box_a, boxes) calculation: compute intersection corners with max()/min(), then inter_w = max(0, xx2-xx1), inter_h = max(0, yy2-yy1), and iou = inter_area / union_area.
Greedy loop pattern: pop the highest-score index i, then filter remaining indices by keeping only those with IoU(i, others) <= iou_threshold. Use boolean masking to filter order array.