-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
37 lines (31 loc) · 1.06 KB
/
model.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
37
import torch.nn as nn
from torch.nn.functional import max_pool2d
class BinaryFMnist(nn.Module):
def __init__(self):
super(BinaryFMnist, self).__init__()
self.conv1 = nn.Conv2d(in_channels=1, out_channels=6, kernel_size=5)
self.conv2 = nn.Conv2d(in_channels=6, out_channels=12, kernel_size=5)
self.relu = nn.LeakyReLU()
self.flatten = nn.Flatten()
self.linear1 = nn.Linear(in_features=12 * 4 * 4, out_features=120)
self.linear2 = nn.Linear(in_features=120, out_features=60)
self.out = nn.Linear(in_features=60, out_features=1)
def forward(self, x):
# conv 1
x = self.conv1(x)
x = self.relu(x)
x = max_pool2d(x, kernel_size=2, stride=2)
# conv 2
x = self.conv2(x)
x = self.relu(x)
x = max_pool2d(x, kernel_size=2, stride=2)
# fc1
x = self.flatten(x)
x = self.linear1(x)
x = self.relu(x)
# fc2
x = self.linear2(x)
x = self.relu(x)
# output
x = self.out(x)
return x