| 15 | |
| 16 | |
| 17 | class ConvNet(M.Module): |
| 18 | def __init__(self): |
| 19 | super().__init__() |
| 20 | self.conv1 = M.Conv2d(3, 6, 5, bias=False) |
| 21 | self.bn1 = M.BatchNorm2d(6) |
| 22 | self.conv2 = M.Conv2d(6, 16, 5, bias=False) |
| 23 | self.bn2 = M.BatchNorm2d(16) |
| 24 | self.fc1 = M.Linear(16 * 5 * 5, 120) |
| 25 | self.fc2 = M.Linear(120, 84) |
| 26 | self.classifier = M.Linear(84, 10) |
| 27 | |
| 28 | self.pool = M.AvgPool2d(2, 2) |
| 29 | |
| 30 | def forward(self, x): |
| 31 | x = self.pool(self.bn1(self.conv1(x))) |
| 32 | x = self.pool(self.bn2(self.conv2(x))) |
| 33 | x = F.flatten(x, 1) |
| 34 | x = self.fc1(x) |
| 35 | x = self.fc2(x) |
| 36 | x = self.classifier(x) |
| 37 | return x |
| 38 | |
| 39 | |
| 40 | @pytest.mark.skipif(int(platform.python_version_tuple()[1]) < 8, reason="need py38") |