-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmodel.py
37 lines (33 loc) · 1.19 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
from torch import nn
CLASSES = ['airplane', 'alarm clock', 'banana', 'baseball bat', 'bicycle', 'candle', 'car', 'crown',
'dumbbell', 'eye', 'fish', 'flower', 'hat', 'headphones', 'ice cream', 'knife', 'pants',
'shoe', 'umbrella', 'windmill']
# define the CNN architecture
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(1, 5, kernel_size=3, padding=1),
nn.ReLU(),
nn.Conv2d(5, 5, kernel_size=3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2), # 14x14x5
nn.Conv2d(5, 8, kernel_size=3, padding=1),
nn.ReLU(),
nn.Conv2d(8, 8, kernel_size=3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2), # 7x7x8
nn.Conv2d(8, 16, kernel_size=3, padding=1),
nn.ReLU() # 7x7x16
)
self.fc = nn.Sequential(
nn.Linear(7 * 7 * 16, 100),
nn.ReLU(),
nn.Dropout(p=0.2),
nn.Linear(100, 23)
)
def forward(self, x):
out = self.layer1(x)
out = out.view(out.shape[0], -1)
out = self.fc(out)
return out