-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
36 lines (27 loc) · 1.08 KB
/
Copy pathmodels.py
File metadata and controls
36 lines (27 loc) · 1.08 KB
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
import torch
import torch.nn as nn
import torch.nn.functional as F
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
self.seq = [32768, 8192, 2048, 512]
self.pool = nn.MaxPool1d(kernel_size=1)
self.conv1 = nn.Conv1d(self.seq[0], int(self.seq[0] / 4), 1)
self.conv2 = nn.Conv1d(self.seq[1], int(self.seq[1] / 4), 1)
self.conv3 = nn.Conv1d(self.seq[2], int(self.seq[2] / 4), 1)
self.conv4 = nn.Conv1d(self.seq[3], int(self.seq[3] / 4), 1)
self.fc1 = nn.Linear(128, 64)
self.fc2 = nn.Linear(64, 32)
self.fc3 = nn.Linear(32, 4)
def forward(self, x):
activation_maps = []
activation_maps.append(x.detach().cpu().numpy())
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = self.pool(F.relu(self.conv3(x)))
x = self.pool(F.relu(self.conv4(x)))
x = torch.flatten(x, 1)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x, activation_maps