File size: 737 Bytes
f829d47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import torch
import torch.nn.functional as F
from torch.nn import Linear, ModuleList
from torch_geometric.nn.dense.linear import Linear


class MLP(torch.nn.Module):
    def __init__(self, in_channels, hidden_channels, out_channels, num_layers=2):
        super().__init__()
        self.mlp = ModuleList()
        self.mlp.append(Linear(in_channels, hidden_channels))
        if num_layers >= 2:
            for _ in range(num_layers - 2):
                self.mlp.append(Linear(hidden_channels, hidden_channels))
        self.mlp.append(Linear(hidden_channels, out_channels))

    def forward(self, x):
        for layer in self.mlp[:-1]:
            x = layer(x)
            x = F.relu(x)
        x = self.mlp[-1](x)
        return x