TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Non-Maximum Suppression

Computer Vision
Medium

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 AAA and BBB:

Aintersection=max⁡(0,xR−xL)max⁡(0,yB−yT)A_{\mathrm{intersection}}=\max(0,x_R-x_L)\max(0,y_B-y_T)Aintersection​=max(0,xR​−xL​)max(0,yB​−yT​) IoU⁡(A,B)=AintersectionAA+AB−Aintersection\operatorname{IoU}(A,B)=\frac{A_{\mathrm{intersection}}}{A_A+A_B-A_{\mathrm{intersection}}}IoU(A,B)=AA​+AB​−Aintersection​Aintersection​​

Return the selected original indices in selection order. Return an empty list for empty input.

Loading visualization...

Examples

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]

Hint 1

Sort range(len(scores)) with the scores as the key and reverse enabled.

Hint 2

After selecting an index, retain only candidates whose IoU is below the threshold.

Requirements

  • Process boxes in stable descending score order
  • Keep the current highest-scoring box
  • Suppress later boxes when IoU is at least the threshold
  • Return original indices in selection order

Constraints

  • Boxes and scores have equal length
  • Every box has valid ordered coordinates
  • The IoU threshold lies between zero and one
Try Similar Problems
Iou Bounding BoxAnchor Box GenerationRoi PoolingBilinear InterpolationMean Average Precision

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Non-Maximum Suppression

Computer Vision
Medium

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 AAA and BBB:

Aintersection=max⁡(0,xR−xL)max⁡(0,yB−yT)A_{\mathrm{intersection}}=\max(0,x_R-x_L)\max(0,y_B-y_T)Aintersection​=max(0,xR​−xL​)max(0,yB​−yT​) IoU⁡(A,B)=AintersectionAA+AB−Aintersection\operatorname{IoU}(A,B)=\frac{A_{\mathrm{intersection}}}{A_A+A_B-A_{\mathrm{intersection}}}IoU(A,B)=AA​+AB​−Aintersection​Aintersection​​

Return the selected original indices in selection order. Return an empty list for empty input.

Loading visualization...

Examples

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]

Hint 1

Sort range(len(scores)) with the scores as the key and reverse enabled.

Hint 2

After selecting an index, retain only candidates whose IoU is below the threshold.

Requirements

  • Process boxes in stable descending score order
  • Keep the current highest-scoring box
  • Suppress later boxes when IoU is at least the threshold
  • Return original indices in selection order

Constraints

  • Boxes and scores have equal length
  • Every box has valid ordered coordinates
  • The IoU threshold lies between zero and one
Try Similar Problems
Iou Bounding BoxAnchor Box GenerationRoi PoolingBilinear InterpolationMean Average Precision

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.