0
0
PyTorchml~10 mins

Non-maximum suppression in PyTorch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the PyTorch function for non-maximum suppression.

PyTorch
from torchvision.ops import [1]
Drag options to blanks, or click blank then click option'
Arelu
Bnms
Csoftmax
Ddropout
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated functions like relu or softmax.
Trying to import from torch.nn instead of torchvision.ops.
2fill in blank
medium

Complete the code to call the non-maximum suppression function with boxes, scores, and threshold.

PyTorch
keep_indices = nms(boxes, scores, [1])
Drag options to blanks, or click blank then click option'
A-0.5
B1.5
C0.5
D2.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using values greater than 1 or negative values for the threshold.
Confusing threshold with score values.
3fill in blank
hard

Fix the error in the code by choosing the correct tensor device for boxes and scores before calling nms.

PyTorch
boxes = boxes.to([1])
scores = scores.to([1])
keep = nms(boxes, scores, 0.5)
Drag options to blanks, or click blank then click option'
A'cuda'
B'memory'
C'disk'
D'cpu'
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid device names like 'disk' or 'memory'.
Not moving tensors to the same device before calling nms.
4fill in blank
hard

Fill both blanks to create a dictionary of filtered boxes and scores after applying nms.

PyTorch
filtered = {
    'boxes': boxes[[1]],
    'scores': scores[[2]]
}
Drag options to blanks, or click blank then click option'
Akeep
Bindices
Crange(len(boxes))
Dtorch.arange(len(scores))
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated variables like 'indices' or ranges that do not correspond to nms output.
Indexing boxes and scores with different variables.
5fill in blank
hard

Fill all three blanks to compute the final selected boxes and their labels after nms.

PyTorch
keep = nms([1], [2], [3])
selected_boxes = boxes[keep]
selected_labels = labels[keep]
Drag options to blanks, or click blank then click option'
Aboxes
Bscores
C0.4
D0.9
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping boxes and scores arguments.
Using threshold values outside the 0-1 range.