Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated functions like relu or softmax.
Trying to import from torch.nn instead of torchvision.ops.
✗ Incorrect
The function for non-maximum suppression in PyTorch is called 'nms' and is imported from torchvision.ops.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using values greater than 1 or negative values for the threshold.
Confusing threshold with score values.
✗ Incorrect
The IoU threshold for non-maximum suppression is usually between 0 and 1; 0.5 is a common choice.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid device names like 'disk' or 'memory'.
Not moving tensors to the same device before calling nms.
✗ Incorrect
For GPU acceleration, tensors must be on the 'cuda' device before calling nms.
4fill in blank
hardFill 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'
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.
✗ Incorrect
The variable 'keep' contains the indices of boxes and scores to keep after nms filtering.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping boxes and scores arguments.
Using threshold values outside the 0-1 range.
✗ Incorrect
The nms function takes boxes, scores, and a threshold (like 0.4) to return indices of selected boxes.