forked from fxrshed/ScaledSPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nn_models.py
31 lines (27 loc) · 832 Bytes
/
nn_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from torch import nn
from torch.functional import F
def get_model(model_class):
if model_class == "smlenet":
return SmallLeNet
else:
return None
class SmallLeNet(nn.Module):
def __init__(self):
super(SmallLeNet, self).__init__()
self.conv1 = nn.Conv2d(1, 5, 3, 1)
self.conv2 = nn.Conv2d(5, 5, 3, 1)
self.conv3 = nn.Conv2d(5, 5, 3, 1)
self.conv4 = nn.Conv2d(5, 10, 3, 1)
def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.conv3(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.conv4(x)
x = F.max_pool2d(x, 2)
output = F.log_softmax(x, dim=1).squeeze(2).squeeze(2)
return output