| 10 | |
| 11 | |
| 12 | class CNN(nn.Module): |
| 13 | def __init__(self): |
| 14 | super().__init__() |
| 15 | self.conv1 = nn.Sequential( |
| 16 | nn.Conv2d( |
| 17 | in_channels=1, |
| 18 | out_channels=16, |
| 19 | kernel_size=5, |
| 20 | stride=1, |
| 21 | padding=2, |
| 22 | ), |
| 23 | nn.ReLU(), |
| 24 | nn.MaxPool2d(kernel_size=2), |
| 25 | ) |
| 26 | self.conv2 = nn.Sequential( |
| 27 | nn.Conv2d(16, 32, 5, 1, 2), |
| 28 | nn.ReLU(), |
| 29 | nn.MaxPool2d(2), |
| 30 | ) |
| 31 | # Fully connected layer, output 10 classes |
| 32 | self.out = nn.Linear(32 * 7 * 7, 10) |
| 33 | |
| 34 | def forward(self, x): |
| 35 | x = self.conv1(x) |
| 36 | x = self.conv2(x) |
| 37 | # Flatten the output of conv2 to (batch_size, 32 * 7 * 7) |
| 38 | x = x.view(x.size(0), -1) |
| 39 | output = self.out(x) |
| 40 | return output |
| 41 | |
| 42 | |
| 43 | # Parameters and DataLoaders |
no outgoing calls
no test coverage detected