Non-Maximum Suppression removes duplicate object detections. Sort original box indices by descending confidence score, keeping input order when scores tie. Repeatedly select the first remaining box and suppress every later box whose IoU with it is greater than or equal to the threshold.
For boxes A and B:
Aintersection=max(0,xR−xL)max(0,yB−yT) IoU(A,B)=AA+AB−AintersectionAintersectionReturn the selected original indices in selection order. Return an empty list for empty input.
Input: boxes = [[0, 0, 4, 4], [1, 0, 5, 4]], scores = [0.9, 0.8], iou_threshold = 0.5
Output: [0]
Explanation: Box 0 is selected first and suppresses Box 1 because their IoU is 0.6.
Input: boxes = [[0, 0, 2, 2], [5, 5, 7, 7], [10, 10, 12, 12]], scores = [0.7, 0.9, 0.8], iou_threshold = 0.5
Output: [1, 2, 0]
Sort range(len(scores)) with the scores as the key and reverse enabled.
After selecting an index, retain only candidates whose IoU is below the threshold.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Non-Maximum Suppression removes duplicate object detections. Sort original box indices by descending confidence score, keeping input order when scores tie. Repeatedly select the first remaining box and suppress every later box whose IoU with it is greater than or equal to the threshold.
For boxes A and B:
Aintersection=max(0,xR−xL)max(0,yB−yT) IoU(A,B)=AA+AB−AintersectionAintersectionReturn the selected original indices in selection order. Return an empty list for empty input.
Input: boxes = [[0, 0, 4, 4], [1, 0, 5, 4]], scores = [0.9, 0.8], iou_threshold = 0.5
Output: [0]
Explanation: Box 0 is selected first and suppresses Box 1 because their IoU is 0.6.
Input: boxes = [[0, 0, 2, 2], [5, 5, 7, 7], [10, 10, 12, 12]], scores = [0.7, 0.9, 0.8], iou_threshold = 0.5
Output: [1, 2, 0]
Sort range(len(scores)) with the scores as the key and reverse enabled.
After selecting an index, retain only candidates whose IoU is below the threshold.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number