-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmodel.py
More file actions
105 lines (95 loc) · 3.28 KB
/
Copy pathmodel.py
File metadata and controls
105 lines (95 loc) · 3.28 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import torch
import torch.nn as nn
import config
class SampleCNN(nn.Module):
def __init__(self):
super(SampleCNN, self).__init__()
# 59049 x 1
self.conv1 = nn.Sequential(
nn.Conv1d(1, 128, kernel_size=3, stride=3, padding=0),
nn.BatchNorm1d(128),
nn.ReLU())
# 19683 x 128
self.conv2 = nn.Sequential(
nn.Conv1d(128, 128, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(128),
nn.ReLU(),
nn.MaxPool1d(3, stride=3))
# 6561 x 128
self.conv3 = nn.Sequential(
nn.Conv1d(128, 128, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(128),
nn.ReLU(),
nn.MaxPool1d(3,stride=3))
# 2187 x 128
self.conv4 = nn.Sequential(
nn.Conv1d(128, 256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.MaxPool1d(3,stride=3))
# 729 x 256
self.conv5 = nn.Sequential(
nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.MaxPool1d(3,stride=3))
# 243 x 256
self.conv6 = nn.Sequential(
nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.MaxPool1d(3,stride=3),
nn.Dropout(config.DROPOUT))
# 81 x 256
self.conv7 = nn.Sequential(
nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.MaxPool1d(3,stride=3))
# 27 x 256
self.conv8 = nn.Sequential(
nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.MaxPool1d(3,stride=3))
# 9 x 256
self.conv9 = nn.Sequential(
nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.MaxPool1d(3,stride=3))
# 3 x 256
self.conv10 = nn.Sequential(
nn.Conv1d(256, 512, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(512),
nn.ReLU(),
nn.MaxPool1d(3,stride=3))
# 1 x 512
self.conv11 = nn.Sequential(
nn.Conv1d(512, 512, kernel_size=3, stride=1, padding=1),
nn.BatchNorm1d(512),
nn.ReLU(),
nn.Dropout(config.DROPOUT))
# 1 x 512
self.fc = nn.Linear(512, 50)
self.activation = nn.Sigmoid()
def forward(self, x):
# input x : 23 x 59049 x 1
# expected conv1d input : minibatch_size x num_channel x width
x = x.view(x.shape[0], 1,-1)
# x : 23 x 1 x 59049
out = self.conv1(x)
out = self.conv2(out)
out = self.conv3(out)
out = self.conv4(out)
out = self.conv5(out)
out = self.conv6(out)
out = self.conv7(out)
out = self.conv8(out)
out = self.conv9(out)
out = self.conv10(out)
out = self.conv11(out)
out = out.view(x.shape[0], out.size(1) * out.size(2))
logit = self.fc(out)
#logit = self.activation(logit)
return logit