MCPcopy Create free account
hub / github.com/FinancialComputingUCL/LOBFrame / CNN2

Class CNN2

models/CNN2/cnn2.py:8–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class CNN2(pl.LightningModule):
9 def __init__(self, num_features=40, num_classes=3, temp=249):
10 super().__init__()
11
12 # Convolution 1
13 self.conv1 = nn.Conv2d(in_channels=1, out_channels=16, kernel_size=(10, 42), padding=(0, 2))
14 self.bn1 = nn.BatchNorm2d(16)
15 self.prelu1 = nn.PReLU()
16
17 # Convolution 2
18 self.conv2 = nn.Conv1d(in_channels=16, out_channels=16, kernel_size=(10,)) # 3
19 self.bn2 = nn.BatchNorm1d(16)
20 self.prelu2 = nn.PReLU()
21
22 # Convolution 3
23 self.conv3 = nn.Conv1d(in_channels=16, out_channels=32, kernel_size=(8,)) # 1
24 self.bn3 = nn.BatchNorm1d(32)
25 self.prelu3 = nn.PReLU()
26
27 # Convolution 4
28 self.conv4 = nn.Conv1d(in_channels=32, out_channels=32, kernel_size=(6,)) # 1
29 self.bn4 = nn.BatchNorm1d(32)
30 self.prelu4 = nn.PReLU()
31
32 # Convolution 5
33 self.conv5 = nn.Conv1d(in_channels=32, out_channels=32, kernel_size=(4,)) # 1
34 self.bn5 = nn.BatchNorm1d(32)
35 self.prelu5 = nn.PReLU()
36
37 # Fully connected 1
38 self.fc1 = nn.Linear(temp*32, 32)
39 self.prelu6 = nn.PReLU()
40
41 # Fully connected 2
42 self.fc2 = nn.Linear(32, num_classes)
43
44 def forward(self, x):
45 # Convolution 1
46 out = self.conv1(x)
47 # print('After convolution1:', out.shape)
48
49 out = self.bn1(out)
50 # print('After bn1:', out.shape)
51
52 out = self.prelu1(out)
53 out = out.reshape(out.shape[0], out.shape[1], -1)
54 # print('After prelu1:', out.shape)
55
56 # Convolution 2
57 out = self.conv2(out)
58 out = self.bn2(out)
59 out = self.prelu2(out)
60 # print('After convolution2, bn2, prelu2:', out.shape)
61
62 # Convolution 3
63 out = self.conv3(out)
64 out = self.bn3(out)
65 out = self.prelu3(out)

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected