Complete the code to load a pre-trained ResNet18 model from torchvision.
import torchvision.models as models model = models.[1](pretrained=True)
The function resnet18 loads the ResNet18 architecture with pre-trained weights.
Complete the code to set the model to evaluation mode.
model = models.resnet18(pretrained=True) model.[1]()
Calling eval() sets the model to evaluation mode, disabling dropout and batch normalization updates.
Fix the error in the code to correctly load a pre-trained VGG16 model.
import torchvision.models as models model = models.vgg16([1]=True)
The correct argument to load pre-trained weights in torchvision models is pretrained=True.
Fill both blanks to create a dictionary of model names and their corresponding pre-trained model functions.
models_dict = {
'resnet': models.[1],
'alexnet': models.[2]
}The dictionary maps 'resnet' to resnet18 and 'alexnet' to alexnet functions from torchvision.models.
Fill all three blanks to create a dictionary comprehension that maps model names to their pre-trained model instances, filtering only models with names longer than 6 characters.
model_names = ['resnet18', 'vgg16', 'alexnet', 'densenet121'] models_dict = { [1]: models.[2](pretrained=True) for [3] in model_names if len([1]) > 6 }
The comprehension uses name as the key and function name, and model as the loop variable. The condition filters names longer than 6 characters.