add template

This commit is contained in:
hobogalaxy committed 2020-11-05 00:52:51 +01:00
1 parent b76bb9a271
commit 4be05dd4f9
5 files changed
+277

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
from torch import nn
import torch.nn.functional as F
class ModelMNISTv1(nn.Module):
def __init__(self, config):
super().__init__()
# mnist images are (1, 28, 28) (channels, width, height)
self.layer_1 = nn.Linear(28 * 28, 128)
self.layer_2 = nn.Linear(128, 256)
self.layer_3 = nn.Linear(256, 10)
def forward(self, x):
batch_size, channels, width, height = x.size()
# (b, 1, 28, 28) -> (b, 1*28*28)
x = x.view(batch_size, -1)
x = self.layer_1(x)
x = F.relu(x)
x = self.layer_2(x)
x = F.relu(x)
x = self.layer_3(x)
return F.log_softmax(x, dim=1)
class ModelMNISTv2(nn.Module):
def __init__(self, config):
super().__init__()
# mnist images are (1, 28, 28) (channels, width, height)
self.layer_1 = nn.Linear(28 * 28, 256)
self.layer_2 = nn.Linear(256, 128)
self.layer_3 = nn.Linear(128, 64)
self.layer_4 = nn.Linear(64, 10)
def forward(self, x):
batch_size, channels, width, height = x.size()
# (b, 1, 28, 28) -> (b, 1*28*28)
x = x.view(batch_size, -1)
x = self.layer_1(x)
x = F.relu(x)
x = self.layer_2(x)
x = F.relu(x)
x = self.layer_3(x)
x = F.relu(x)
x = self.layer_4(x)
return F.log_softmax(x, dim=1)