-
Notifications
You must be signed in to change notification settings - Fork 0
/
Smaller_input_CNN.py
48 lines (39 loc) · 1.24 KB
/
Smaller_input_CNN.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
from torch import nn
from torch.nn.modules import linear
from torch.utils.data import DataLoader
from torchvision import datasets, transforms
import math
import torch
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
self.layer1 = nn.Sequential(
nn.Dropout(p = 0.25),
nn.Conv1d(6, 32, kernel_size = 4, stride = 2, padding = 1),
nn.ReLU(),
nn.MaxPool1d(2, 2)
)#output size = 62
self.layer2 = nn.Sequential(
nn.Conv1d(32, 128, kernel_size = 4, stride = 2, padding = 1),
nn.ReLU(),
nn.MaxPool1d(2, 2)
)#output size = 15
self.layer3 = nn.Sequential(
nn.Conv1d(128, 512, kernel_size = 3, stride = 2, padding = 1),
nn.ReLU(),
nn.MaxPool1d(2, 2)
)#output size = 4
self.layer4 = nn.Sequential(
nn.Linear(4*512, 512),
nn.ReLU(),
nn.Linear(512, 128),
nn.ReLU(),
nn.Linear(128, 16)
)
def forward(self, x):
out = self.layer1(x)
out = self.layer2(out)
out = self.layer3(out)
out = out.view(out.size(0), -1)
out = self.layer4(out)
return out