Question 1
Consider the following code snippet for modifying an AlexNet architecture to adapt it for a custom classification task with 10 output classes. Fill in the blank portion with the most appropriate code snippet.
import torchimport torch.nn as nnfrom torchvision.models import alexnet
class CustomAlexNet(nn.Module): def __init__(self, num_classes=10): super(CustomAlexNet, self).__init__() self.alexnet = alexnet(pretrained=True) # Blank portion def forward(self, x): x = self.alexnet.features(x) x = self.alexnet.avgpool(x) x = torch.flatten(x, 1) x = self.alexnet.classifier(x) return x
model = CustomAlexNet()Which of the following code snippets correctly fills the blank portion to modify the AlexNet classifier while preserving the pretrained feature extraction layers?
