Spaces:
Sleeping
Sleeping
| # model.py | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class CNN(nn.Module): | |
| def __init__(self): | |
| super(CNN, self).__init__() | |
| self.conv1 = nn.Conv2d(1, 32, kernel_size=3) # (1, 28, 28) -> (32, 26, 26) | |
| self.pool1 = nn.MaxPool2d(2, 2) # (32, 26, 26) -> (32, 13, 13) | |
| self.conv2 = nn.Conv2d(32, 64, kernel_size=3) # (32, 13, 13) -> (64, 11, 11) | |
| self.pool2 = nn.MaxPool2d(2, 2) # (64, 11, 11) -> (64, 5, 5) | |
| self.fc1 = nn.Linear(64 * 5 * 5, 64) | |
| self.fc2 = nn.Linear(64, 10) | |
| def forward(self, x): | |
| x = F.relu(self.conv1(x)) | |
| x = self.pool1(x) | |
| x = F.relu(self.conv2(x)) | |
| x = self.pool2(x) | |
| x = x.view(-1, 64 * 5 * 5) | |
| x = F.relu(self.fc1(x)) | |
| x = self.fc2(x) | |
| return x |