Complete the code to import the R-CNN model from torchvision.
from torchvision.models.detection import [1]
The fasterrcnn_resnet50_fpn is the Faster R-CNN model implementation in torchvision.
Complete the code to create a Faster R-CNN model pre-trained on COCO dataset.
model = [1](pretrained=True)
The fasterrcnn_resnet50_fpn function creates a Faster R-CNN model with a ResNet-50 backbone and Feature Pyramid Network, pretrained on COCO.
Fix the error in the code to get the number of classes for the Faster R-CNN model.
num_classes = model.roi_heads.box_predictor.[1]The attribute num_classes holds the number of classes the Faster R-CNN model predicts.
Fill both blanks to replace the Faster R-CNN box predictor with a new one for a custom number of classes.
in_features = model.roi_heads.box_predictor.[1] model.roi_heads.box_predictor = FastRCNNPredictor(in_features, [2])
The cls_score.in_features gives the input features for the box predictor. We replace the box predictor with FastRCNNPredictor using the new number of classes, here 5.
Fill all three blanks to create a Mask R-CNN model with a ResNet-50 backbone and set it to evaluation mode.
from torchvision.models.detection import [1] model = [2](pretrained=True) model.[3]()
Import maskrcnn_resnet50_fpn, create the model with pretrained weights, and set it to evaluation mode with eval().