Question 17
Consider the following CNN defined in PyTorch:
import torchimport torch.nn as nnimport torch.nn.functional as F
class SimpleCNN(nn.Module): def __init__(self): super(SimpleCNN, self).__init__() # Conv Layer 1: in_channels=1 (grayscale), out_channels=8 self.conv1 = nn.Conv2d(in_channels=1, out_channels=8, kernel_size=3, stride=1, padding=1) # Pool Layer 1 self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2)
# Conv Layer 2: in_channels=8, out_channels=16 self.conv2 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size=3, stride=1, padding=1) # Pool Layer 2 self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)
# Fully Connected Layers self.fc1 = nn.Linear(16 * 7 * 7, 128) # Flattened from conv2 output self.fc2 = nn.Linear(128, 10) # Output for 10 classes
def forward(self, x): x = self.pool1(F.relu(self.conv1(x))) # Conv1 + Pool1 x = self.pool2(F.relu(self.conv2(x))) # Conv2 + Pool2 x = x.view(-1, 16 * 7 * 7) # Flatten x = F.relu(self.fc1(x)) # FC1 x = self.fc2(x) # FC2 return x
# Example inputmodel = SimpleCNN()print(model)Based on the above data, answer the given subquestions.
What is the total number of convolution filters used in this CNN?