-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel.py
54 lines (49 loc) · 1.96 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import torch
import torch.nn as nn
import numpy as np
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, output_dim = 9):
super().__init__()
self.features = nn.Sequential(
nn.Conv2d(in_channels = 3, out_channels = 32, kernel_size = 3, padding=(1, 1)),
nn.ReLU(inplace = True),
nn.Conv2d(in_channels = 32, out_channels = 32, kernel_size = 3, padding=(1, 1)),
nn.ReLU(inplace = True),
nn.MaxPool2d(kernel_size = 2, stride = 2),
nn.Dropout(0.25),
nn.Conv2d(in_channels = 32, out_channels = 64, kernel_size = 3, padding=(1, 1)),
nn.ReLU(inplace = True),
nn.Conv2d(in_channels = 64, out_channels = 64, kernel_size = 3, padding=(1, 1)),
nn.ReLU(inplace = True),
nn.MaxPool2d(kernel_size = 2, stride = 2),
nn.Dropout(0.25),
nn.Conv2d(in_channels = 64, out_channels = 128, kernel_size = 3, padding=(1, 1)),
nn.ReLU(inplace = True),
nn.Conv2d(in_channels = 128, out_channels = 128, kernel_size = 3, padding=(1, 1)),
nn.ReLU(inplace = True),
nn.MaxPool2d(kernel_size = 2, stride = 2),
nn.Flatten()
)
self.classifier = nn.Sequential(
nn.Linear(128*4*4, 256), ## 17
nn.ReLU(inplace = True),
#nn.Linear(512,128), ## 19
#nn.ReLU(inplace = True),
nn.Linear(256, output_dim), ## 21
# nn.ReLU(inplace = True),
# nn.Linear(32, output_dim) ## 23
)
def forward(self, x):
layer_output = []
# t = x
feats = x
for layer in self.features:
feats = layer(feats)
layer_output.append(feats)
# feats = self.features(x)
out = feats
for layer in self.classifier:
out = layer(out)
layer_output.append(out)
return layer_output, out