File size: 985 Bytes
da7c0f0
 
956b371
da7c0f0
 
956b371
da7c0f0
 
 
 
 
 
 
 
 
 
956b371
da7c0f0
 
 
 
 
 
 
 
 
956b371
da7c0f0
 
 
956b371
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
import torch.nn as nn
import torch.nn.functional as F


from torch_geometric.nn import GCNConv, global_mean_pool


class GNNClassifier(nn.Module):
    def __init__(self, input_dim, output_dim, hidden_channels):
        super().__init__()
        self.hidden_channels = hidden_channels

        self.conv1 = GCNConv(input_dim, hidden_channels)
        self.conv2 = GCNConv(hidden_channels, hidden_channels)
        self.conv3 = GCNConv(hidden_channels, hidden_channels)

        self.lin = nn.Linear(hidden_channels, output_dim)  # classification task 0 or 1

    def forward(self, x, edge_index, batch):
        x = self.conv1(x, edge_index)
        x = x.relu()
        x = self.conv2(x, edge_index)
        x = x.relu()
        x = self.conv3(x, edge_index)

        # Averaging nodes and got the molecula vector
        x = global_mean_pool(x, batch)  # [batch_size, hidden_channels]

        x = F.dropout(x, p=0.5, training=self.training)
        x = self.lin(x)
        return x