| 126 | |
| 127 | |
| 128 | class Net(nn.Module): |
| 129 | def __init__(self): |
| 130 | super().__init__() |
| 131 | self.conv1 = nn.Conv2d(3, 6, 5) |
| 132 | self.pool = nn.MaxPool2d(2, 2) |
| 133 | self.conv2 = nn.Conv2d(6, 16, 5) |
| 134 | self.fc1 = nn.Linear(16 * 5 * 5, 120) |
| 135 | self.fc2 = nn.Linear(120, 84) |
| 136 | self.fc3 = nn.Linear(84, 10) |
| 137 | |
| 138 | def forward(self, x): |
| 139 | x = self.pool(F.relu(self.conv1(x))) |
| 140 | x = self.pool(F.relu(self.conv2(x))) |
| 141 | x = torch.flatten(x, 1) # flatten all dimensions except batch |
| 142 | x = F.relu(self.fc1(x)) |
| 143 | x = F.relu(self.fc2(x)) |
| 144 | x = self.fc3(x) |
| 145 | return x |
| 146 | |
| 147 | |
| 148 | net = Net() |