class FashionCNN(nn.Module):
"""A compact CNN for Fashion-MNIST: two conv-pool stages, two linear."""
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
self.fc1 = nn.Linear(64 * 7 * 7, 128)
self.fc2 = nn.Linear(128, 10)
def forward(self, X):
X = F.max_pool2d(F.relu(self.conv1(X)), 2)
X = F.max_pool2d(F.relu(self.conv2(X)), 2)
return self.fc2(F.relu(self.fc1(X.flatten(1))))