-
Notifications
You must be signed in to change notification settings - Fork 16
/
model.py
40 lines (29 loc) · 926 Bytes
/
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
38
39
40
import torch
import torch.nn as nn
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
self.relu = nn.ReLU(inplace=True)
self.maxpool = nn.MaxPool2d(2, 2)
self.conv1 = nn.Conv2d(1, 32, 5, 1, 2)
self.bn1 = nn.BatchNorm2d(32)
self.conv2 = nn.Conv2d(32, 64, 5, 1, 2)
self.bn2 = nn.BatchNorm2d(64)
self.fc1 = nn.Linear(7 * 7 * 64, 1024)
self.fc2 = nn.Linear(1024, 10)
self.softmax = nn.Softmax(dim=1)
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.relu(x)
x = self.maxpool(x) # 28x28->14x14
x = self.conv2(x)
x = self.bn2(x)
x = self.relu(x)
x = self.maxpool(x) # 14x14->7x7
x = torch.flatten(x, 1)
x = self.fc1(x)
x = self.relu(x)
x = self.fc2(x)
x = self.softmax(x)
return x