-
Notifications
You must be signed in to change notification settings - Fork 15
/
model.py
45 lines (39 loc) · 1.61 KB
/
model.py
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
37
38
39
40
41
42
43
44
45
import torch
import torch.nn.functional as F
from torch import nn
from torch.nn import Conv1d, MaxPool1d, Linear, Dropout
from torch_geometric.nn import GCNConv, SortAggregation
from torch_geometric.utils import remove_self_loops
class Model(nn.Module):
def __init__(self, num_features, num_classes):
super(Model, self).__init__()
self.conv1 = GCNConv(num_features, 32)
self.conv2 = GCNConv(32, 32)
self.conv3 = GCNConv(32, 32)
self.conv4 = GCNConv(32, 1)
self.sort_pool = SortAggregation(k=30)
self.conv5 = Conv1d(1, 16, 97, 97)
self.conv6 = Conv1d(16, 32, 5, 1)
self.pool = MaxPool1d(2, 2)
self.classifier_1 = Linear(352, 128)
self.drop_out = Dropout(0.5)
self.classifier_2 = Linear(128, num_classes)
self.relu = nn.ReLU(inplace=True)
def forward(self, data):
x, edge_index, batch = data.x, data.edge_index, data.batch
edge_index, _ = remove_self_loops(edge_index)
x_1 = torch.tanh(self.conv1(x, edge_index))
x_2 = torch.tanh(self.conv2(x_1, edge_index))
x_3 = torch.tanh(self.conv3(x_2, edge_index))
x_4 = torch.tanh(self.conv4(x_3, edge_index))
x = torch.cat([x_1, x_2, x_3, x_4], dim=-1)
x = self.sort_pool(x, batch)
x = x.view(x.size(0), 1, x.size(-1))
x = self.relu(self.conv5(x))
x = self.pool(x)
x = self.relu(self.conv6(x))
x = x.view(x.size(0), -1)
out = self.relu(self.classifier_1(x))
out = self.drop_out(out)
classes = F.log_softmax(self.classifier_2(out), dim=-1)
return classes