import torch.nn as nn import torch.nn.functional as F class MNISTNetwork(nn.Module): def __init__(self): super().__init__() self.layer1 = nn.Linear(784, 128) self.layer2 = nn.Linear(128, 64) self.layer3 = nn.Linear(64, 32) self.layer4 = nn.Linear(32, 10) def forward(self, x): x = F.relu(self.layer1(x)) x = F.relu(self.layer2(x)) x = F.relu(self.layer3(x)) x = self.layer4(x) return F.log_softmax(x, dim=1) # class MNISTNetwork(nn.Module): # def __init__(self): # super().__init__() # self.conv1 = nn.Conv2d(1, 32, kernel_size=5, padding=2) # self.conv2 = nn.Conv2d(32, 64, kernel_size=5, padding=2) # self.fc1 = nn.Linear(64*7*7, 1024) # self.fc2 = nn.Linear(1024, 10) # def forward(self, x): # x = nn.functional.relu(self.conv1(x)) # x = nn.functional.max_pool2d(x, 2) # x = nn.functional.relu(self.conv2(x)) # x = nn.functional.max_pool2d(x, 2) # x = x.view(-1, 64*7*7) # x = nn.functional.relu(self.fc1(x)) # x = nn.functional.dropout(x, training=self.training) # x = self.fc2(x) # return nn.functional.log_softmax(x, dim=1)