Complete the code to load a pre-trained model for image classification.
from torchvision import models model = models.[1](pretrained=True)
The resnet18 model is a common pre-trained model used for image classification in computer vision.
Complete the code to set the model to evaluation mode before making predictions.
model.[1]()train() instead of eval().Calling eval() sets the model to evaluation mode, which disables dropout and batch normalization updates.
Fix the error in the code to compute accuracy from model outputs and labels.
correct = (outputs.argmax(dim=1) [1] labels).sum().item() accuracy = correct / labels.size(0)
= instead of comparison ==.The equality operator == compares predicted labels to true labels to count correct predictions.
Fill both blanks to create a dictionary of model names and their validation accuracies.
results = { '[1]': val_acc1, '[2]': val_acc2 }Common model names like ResNet18 and VGG16 are used as keys to store their accuracies.
Fill all three blanks to complete the code that compares two models' accuracies and prints the better one.
if results['[1]'] [2] results['[3]']: print('Better model: ResNet18') else: print('Better model: VGG16')
The code compares the accuracy of ResNet18 and VGG16 using the greater than operator to find the better model.