-
Notifications
You must be signed in to change notification settings - Fork 3
/
models.py
36 lines (29 loc) · 866 Bytes
/
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
32
33
34
35
36
import torch.nn as nn
import torch.nn.functional as F
import torch
class model1(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1,32, 3)
self.pool = nn.MaxPool2d(2, 2)
def forward(self, x):
# x = x.view(-1,1,28,28)
x = self.pool(F.relu(self.conv1(x)))
return x
class model2(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(32*13*13,1000)
self.fc2 = nn.Linear(1000,100)
def forward(self, x):
x = torch.flatten(x, 1) # flatten all dimensions except batch
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
return x
class model3(nn.Module):
def __init__(self):
super().__init__()
self.fc3 = nn.Linear(100, 10)
def forward(self, x):
x = self.fc3(x)
return x