Deep Learning Practice, End Term
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?
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 torch import torch.nn as nn from 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? An RGB image of size 227 × 227 × 3 is first converted to grayscale and then passed through a 2D Convolutional Neural Network (CNN) layer with the following parameters:\ – Kernel size: 3 × 3\ – Stride: 1\ – Padding: 1\ – Number of filters: 16\ What will be the shape of the output feature map? Figure from the original question paper