Complete the code to load a pre-trained ResNet50 model from torchvision.
import torchvision.models as models model = models.[1](pretrained=True)
The resnet50 function loads the ResNet50 pre-trained model from torchvision.
Complete the code to replace the final classification layer of a VGG16 model for 10 classes.
import torch.nn as nn import torchvision.models as models model = models.vgg16(pretrained=True) num_ftrs = model.classifier[6].in_features model.classifier[6] = nn.[1](num_ftrs, 10)
The final layer of VGG16 classifier is a Linear layer. We replace it with a new Linear layer with 10 outputs for 10 classes.
Fix the error in the code to load EfficientNet-B0 pre-trained model from torchvision.
import torchvision.models as models model = models.[1](weights=models.EfficientNet_B0_Weights.IMAGENET1K_V1)
The correct function to load EfficientNet-B0 is efficientnet_b0. The weights argument uses the correct weights enum.
Fill both blanks to freeze all parameters of a pre-trained ResNet18 model.
import torchvision.models as models model = models.resnet18(pretrained=True) for param in model.[1](): param.[2] = False
We loop over all parameters using parameters() and set requires_grad = False to freeze them.
Fill all three blanks to create a dictionary that maps model names to their pre-trained loading functions.
import torchvision.models as models model_loaders = { '[1]': models.[2], '[3]': models.vgg16, }
The dictionary keys are model names as strings. The values are the corresponding functions from torchvision.models.