0
0
PyTorchml~20 mins

Non-maximum suppression in PyTorch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NMS Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of PyTorch NMS with overlapping boxes
Given the following bounding boxes and scores, what indices does PyTorch's non_max_suppression (NMS) return?
PyTorch
import torch
from torchvision.ops import nms

boxes = torch.tensor([[10, 10, 20, 20], [11, 11, 21, 21], [30, 30, 40, 40]], dtype=torch.float32)
scores = torch.tensor([0.9, 0.8, 0.7])
iou_threshold = 0.5

keep_indices = nms(boxes, scores, iou_threshold)
print(keep_indices.tolist())
A[0, 2]
B[1, 2]
C[0, 1, 2]
D[2]
Attempts:
2 left
💡 Hint
NMS keeps the highest scoring box and removes boxes with IoU above threshold.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Non-Maximum Suppression in Object Detection
What is the main purpose of applying Non-Maximum Suppression (NMS) in object detection pipelines?
ATo remove duplicate detections of the same object by keeping only the highest scoring bounding box.
BTo increase the number of detected objects by adding more bounding boxes.
CTo randomly select bounding boxes to reduce computation.
DTo resize bounding boxes to a fixed size.
Attempts:
2 left
💡 Hint
Think about why multiple boxes might appear around the same object.
Hyperparameter
advanced
1:30remaining
Effect of IoU Threshold on NMS Output
If you increase the IoU threshold parameter in NMS from 0.3 to 0.7, what is the expected effect on the number of bounding boxes kept?
AAll boxes will be removed.
BFewer boxes will be kept because the suppression is more strict.
CThe number of boxes kept will not change.
DMore boxes will be kept because the suppression is less strict.
Attempts:
2 left
💡 Hint
Higher IoU threshold means boxes need to overlap more to be suppressed.
🔧 Debug
advanced
2:00remaining
Identify the error in this NMS usage code
What error will this PyTorch code raise when running NMS?
PyTorch
import torch
from torchvision.ops import nms

boxes = torch.tensor([[10, 10, 20, 20], [15, 15, 25, 25]])
scores = [0.9, 0.8]
iou_threshold = 0.5

keep = nms(boxes, scores, iou_threshold)
print(keep)
ANo error, code runs fine.
BValueError because boxes have wrong shape.
CTypeError because scores is a list, not a tensor.
DRuntimeError because iou_threshold is not a tensor.
Attempts:
2 left
💡 Hint
Check the data types required by torchvision.ops.nms.
Model Choice
expert
2:30remaining
Choosing NMS variant for crowded scenes
In a crowded scene with many overlapping objects, which NMS variant is best to reduce missed detections while controlling duplicates?
ARandom NMS, to randomly keep boxes and reduce duplicates.
BSoft-NMS, because it reduces scores of overlapping boxes instead of removing them outright.
CNo NMS, to keep all detections regardless of overlap.
DStandard NMS, because it strictly removes all overlapping boxes above threshold.
Attempts:
2 left
💡 Hint
Consider methods that soften suppression to keep more true positives.