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

Class CNN1

models/CNN1/cnn1.py:5–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4
5class CNN1(pl.LightningModule):
6 def __init__(self, num_features=40, num_classes=3, temp=26):
7 super().__init__()
8
9 # Convolution 1
10 self.conv1 = nn.Conv2d(in_channels=1, out_channels=16, kernel_size=(4, num_features), padding=(3, 0), dilation=(2, 1))
11 self.relu1 = nn.LeakyReLU()
12
13 # Convolution 2
14 self.conv2 = nn.Conv1d(in_channels=16, out_channels=16, kernel_size=(4,))
15 self.relu2 = nn.LeakyReLU()
16
17 # Max pool 1
18 self.maxpool1 = nn.MaxPool1d(kernel_size=2)
19
20 # Convolution 3
21 self.conv3 = nn.Conv1d(in_channels=16, out_channels=32, kernel_size=(3,), padding=2)
22 self.relu3 = nn.LeakyReLU()
23
24 # Convolution 4
25 self.conv4 = nn.Conv1d(in_channels=32, out_channels=32, kernel_size=(3,), padding=2)
26 self.relu4 = nn.LeakyReLU()
27
28 # Max pool 2
29 self.maxpool2 = nn.MaxPool1d(kernel_size=2)
30
31 # Fully connected 1
32 self.fc1 = nn.Linear(temp*32, 32)
33 self.relu5 = nn.LeakyReLU()
34
35 # Fully connected 2
36 self.fc2 = nn.Linear(32, num_classes)
37
38 def forward(self, x):
39 # Convolution 1
40 out = self.conv1(x)
41 out = self.relu1(out)
42 out = out.reshape(out.shape[0], out.shape[1], -1)
43 # print('After convolution1:', out.shape)
44
45 # Convolution 2
46 out = self.conv2(out)
47 out = self.relu2(out)
48 # print('After convolution2:', out.shape)
49
50 # Max pool 1
51 out = self.maxpool1(out)
52 # print('After maxpool1:', out.shape)
53
54 # Convolution 3
55 out = self.conv3(out)
56 out = self.relu3(out)
57 # print('After convolution3:', out.shape)
58
59 # Convolution 4
60 out = self.conv4(out)
61 out = self.relu4(out)
62 # print('After convolution4:', out.shape)

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected