Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a pre-trained object detection model from torchvision.
Computer Vision
import torchvision.models as models model = models.detection.[1](pretrained=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using classification model names instead of detection model names.
Forgetting to set pretrained=True.
✗ Incorrect
The correct function to load a pre-trained Faster R-CNN detection model is 'fasterrcnn_resnet50_fpn'. Other options are classification models.
2fill in blank
mediumComplete the code to put the model in evaluation mode before inference.
Computer Vision
model = models.detection.fasterrcnn_resnet50_fpn(pretrained=True) model.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using model.train() which sets training mode.
Trying to call model.predict() which is not a PyTorch method.
✗ Incorrect
Calling model.eval() sets the model to evaluation mode, disabling dropout and batch norm updates.
3fill in blank
hardFix the error in the code to prepare an input image tensor for the detection model.
Computer Vision
from torchvision import transforms transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[[1], 0.224, 0.225]) ])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect normalization values causing poor model performance.
Mixing mean and std values.
✗ Incorrect
The standard normalization mean and std for ImageNet models use std=0.229 for the red channel.
4fill in blank
hardFill both blanks to run inference and get predictions from the model.
Computer Vision
model.eval() with torch.no_grad(): predictions = model([[1]]) print(predictions[0][[2]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single tensor instead of a list.
Trying to print 'labels' instead of 'scores' when checking confidence.
✗ Incorrect
The model expects a list of input tensors. The predictions dictionary contains 'boxes', 'labels', and 'scores'. Printing 'scores' shows confidence values.
5fill in blank
hardFill all three blanks to filter predictions by confidence threshold and extract bounding boxes.
Computer Vision
threshold = 0.8 pred = predictions[0] scores = pred[[1]] boxes = pred[[2]] filtered_boxes = boxes[scores [3] threshold]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up keys 'scores' and 'boxes'.
Using '<' instead of '>' for filtering.
✗ Incorrect
We get scores and boxes from the prediction dictionary. Filtering boxes where scores are greater than threshold keeps confident detections.