cnn_1x1.py 993 Bytes
Newer Older
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
import torch
import torch.nn as nn
import torch.nn.functional as F

class ConvNet4(nn.Module):
    def __init__(self):
        super(ConvNet4, self).__init__()
        self.conv1 = nn.Conv1d(1, 8, 1)
        self.conv2 = nn.Conv1d(8, 16, 16)
        self.max_pool1 = nn.MaxPool1d(4,4)
        self.conv3 = nn.Conv1d(16, 32, 8)
        self.max_pool2 = nn.MaxPool1d(4,4)
        self.conv4 = nn.Conv1d(32, 64, 8)
        self.max_pool3 = nn.MaxPool1d(4,4)
        self.fc1 = nn.Linear(3904, 64)
        self.fc2 = nn.Linear(64, 1)
 
    def forward(self, x):
        x = self.conv1(x)
        x = F.relu(x)
        x = self.conv2(x)
        x = F.relu(x)
        x = self.max_pool1(x)
        x = self.conv3(x)
        x = F.relu(x)
        x = self.max_pool2(x)
        x = self.conv4(x)
        x = F.relu(x)
        x = self.max_pool3(x)
        # resize
        x = x.view(x.size(0), -1)
        x = F.relu(self.fc1(x))
        x = self.fc2(x)
        x = torch.sigmoid(x)
        return x