-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmodels.py
34 lines (32 loc) · 1.08 KB
/
models.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
import torch.nn as nn
class CNN1D(nn.Module):
def __init__(self, output_size):
super(CNN1D, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv1d(1,32,kernel_size=3,padding=1),
nn.BatchNorm1d(32),
nn.ReLU(),
nn.MaxPool1d(kernel_size=2, padding=0)
)
self.layer2 = nn.Sequential(
nn.Conv1d(32,64,kernel_size=3,padding=1),
nn.BatchNorm1d(64),
nn.ReLU(),
nn.MaxPool1d(kernel_size=2, padding=0)
)
self.layer3 = nn.Sequential(
nn.Conv1d(64,64,kernel_size=3,padding=1),
nn.BatchNorm1d(64),
nn.ReLU(),
nn.MaxPool1d(kernel_size=2, padding=0)
)
self.avgpool = nn.AdaptiveAvgPool1d(64) # output (batch, 64, 64)
self.fc = nn.Linear(64*64, output_size)
def forward(self, x):
x = self.layer1(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.avgpool(x) # [200, 64, 128]
x = x.view(x.size(0), -1)
x = self.fc(x)
return x