0
0
PyTorchml~10 mins

Faster R-CNN usage 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 load a pre-trained Faster R-CNN model from torchvision.

PyTorch
import torchvision.models.detection as detection
model = detection.[1](pretrained=True)
Drag options to blanks, or click blank then click option'
Afasterrcnn_resnet50_fpn
Bresnet50
Cmaskrcnn_resnet50_fpn
Dfasterrcnn_vgg16
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'resnet50' which is a classification model, not detection.
Using 'maskrcnn_resnet50_fpn' which is for instance segmentation, not Faster R-CNN.
2fill in blank
medium

Complete the code to put the Faster R-CNN model in evaluation mode before inference.

PyTorch
model.[1]()
Drag options to blanks, or click blank then click option'
Atrain
Bpredict
Cfit
Deval
Attempts:
3 left
💡 Hint
Common Mistakes
Calling 'train()' instead of 'eval()' which keeps the model in training mode.
Trying to call 'predict()' which is not a PyTorch model method.
3fill in blank
hard

Fix the error in the code to move the input image tensor to the same device as the model.

PyTorch
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model.to(device)
image = image.[1](device)
Drag options to blanks, or click blank then click option'
Adevice
Bcuda
Cto
Dmove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cuda' which fails if CUDA is not available.
Using 'device' or 'move' which are not valid tensor methods.
4fill in blank
hard

Fill both blanks to prepare the input image tensor as a list and normalize pixel values between 0 and 1.

PyTorch
image = image.[1](dtype=torch.float32) / 255.0
inputs = [image.[2](0)]
Drag options to blanks, or click blank then click option'
Ato
Bunsqueeze
Creshape
Dview
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reshape' or 'view' which can change data layout incorrectly.
Forgetting to convert to float before dividing by 255.
5fill in blank
hard

Fill all three blanks to run inference and extract predicted boxes and labels from the output.

PyTorch
with torch.no_grad():
    outputs = model([1])

boxes = outputs[0][[2]].cpu().numpy()
labels = outputs[0][[3]].cpu().numpy()
Drag options to blanks, or click blank then click option'
Ainputs
B'boxes'
C'labels'
D'scores'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a tensor instead of a list to the model.
Using wrong keys like 'scores' instead of 'labels'.