-
Notifications
You must be signed in to change notification settings - Fork 0
/
Neural_Networks.py
72 lines (58 loc) · 1.94 KB
/
Neural_Networks.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from torch import nn
import torch
from torch.nn import functional
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
#this is for mobile use adaptation
#self.quant = torch.quantization.QuantStub()
#self.dequant = torch.quantization.DeQuantStub()
self.layer1 = nn.Sequential(
nn.Dropout(p = 0.25),
nn.Conv1d(12, 32, kernel_size = 3, stride = 1, padding = 1),
nn.ReLU(),
nn.MaxPool1d(2, 2)
)#output size = 125
self.layer2 = nn.Sequential(
nn.Conv1d(32, 64, kernel_size = 3, stride = 1, padding = 1),
nn.ReLU(),
nn.MaxPool1d(2, 2)
)#output size = 62
self.layer3 = nn.Sequential(
nn.Conv1d(64, 128, kernel_size = 3, stride = 1, padding = 1),
nn.ReLU(),
nn.MaxPool1d(2, 2)
)#output size = 31
self.layer4 = nn.Sequential(
nn.Conv1d(128, 256, kernel_size = 3, stride = 1, padding = 1),
nn.ReLU(),
nn.MaxPool1d(2, 2)
)#output size = 15
self.layer5 = nn.Sequential(
nn.Conv1d(256, 512, kernel_size = 3, stride = 1, padding = 1),
nn.ReLU(),
nn.MaxPool1d(2, 2)
)#output size = 7
self.layer6 = nn.Sequential(
nn.Linear(7*512, 2048),
nn.ReLU(),
nn.Linear(2048, 1024),
nn.ReLU(),
nn.Linear(1024, 512),
nn.ReLU(),
nn.Linear(512, 128),
nn.ReLU(),
nn.Linear(128, 15),
#nn.LogSoftmax(0)
)
def forward(self, x):
#x = self.quant(x)
out = self.layer1(x)
out = self.layer2(out)
out = self.layer3(out)
out = self.layer4(out)
out = self.layer5(out)
out = out.view(out.size(0), -1)
out = self.layer6(out)
#out = self.dequant(out)
return out