-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcnn_net_model.py
More file actions
33 lines (26 loc) · 939 Bytes
/
cnn_net_model.py
File metadata and controls
33 lines (26 loc) · 939 Bytes
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
import torch
import torch.nn as nn
class CnnNet(nn.Module):
def __init__(self):
super(CnnNet, self).__init__()
self.input_conv = nn.Conv1d(1, 32, 5, padding=2)
self.rec_convs = nn.ModuleList([nn.Conv1d(32, 32, 5, padding=2) for i in range(10)])
self.activation = nn.ReLU()
self.pool = nn.MaxPool1d(5, stride=2)
self.fc1 = nn.Linear(64, 32)
self.fc2 = nn.Linear(32, 5)
self.softmax = nn.Softmax(dim=1)
def forward(self, x):
prev_x = self.input_conv(x)
for i in range(0, 10, 2):
x = self.rec_convs[i](prev_x)
x = self.activation(x)
x = self.rec_convs[i + 1](x) + prev_x
x = self.activation(x)
prev_x = self.pool(x)
x = torch.flatten(prev_x, start_dim=1)
x = self.fc1(x)
x = self.activation(x)
x = self.fc2(x)
x = self.softmax(x)
return x