Question 5
You are building an image classifier for the Nature12K dataset, which contains 12 categories of natural scenes (i.e., 12 output classes). You decide to use VGG-16 pretrained on ImageNet as a feature extractor and modify only the final layer for fine-tuning.
Below is a partially completed PyTorch code snippet:
import torchimport torch.nn as nnfrom torchvision.models import vgg16
class Nature12KClassifier(nn.Module): def __init__(self): super(Nature12KClassifier, self).__init__() self.base = vgg16(pretrained=True) # [Missing Line]
def forward(self, x): x = self.base.features(x) x = self.base.avgpool(x) x = torch.flatten(x, 1) x = self.base.classifier(x) return x
model = Nature12KClassifier()Which of the following lines correctly fills in the missing line to adapt the VGG-16 model for Nature12K?