Spaces:
Runtime error
Runtime error
from torch import nn | |
import torch.nn.functional as F | |
# TODO: Would be cool to use a simple Transformer model... then I could use the Trainer API π | |
class CNN(nn.Module): | |
def __init__(self): | |
super(CNN, self).__init__() | |
self.conv1 = nn.Conv2d(1, 32, kernel_size=5) | |
self.conv2 = nn.Conv2d(32, 32, kernel_size=5) | |
self.conv3 = nn.Conv2d(32, 64, kernel_size=5) | |
self.fc1 = nn.Linear(3 * 3 * 64, 256) | |
self.fc2 = nn.Linear(256, 10) | |
def forward(self, x, eval=False): | |
x = F.relu(self.conv1(x)) | |
x = F.relu(F.max_pool2d(self.conv2(x), 2)) | |
x = F.dropout(x, p=0.5, training=not eval) | |
x = F.relu(F.max_pool2d(self.conv3(x), 2)) | |
x = F.dropout(x, p=0.5, training=not eval) | |
x = x.view(-1, 3 * 3 * 64) | |
x = F.relu(self.fc1(x)) | |
x = F.dropout(x, p=0.5, training=not eval) | |
x = self.fc2(x) | |
return F.log_softmax(x, dim=1) | |