-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
57 lines (45 loc) · 1.58 KB
/
models.py
File metadata and controls
57 lines (45 loc) · 1.58 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
from dataclasses import dataclass
from typing import Any
import torch
import torch.nn.functional as F
from torch_geometric.nn import GCNConv
from torch_geometric.nn import Linear
from torch_geometric.nn import SGConv
@dataclass
class ModelData:
model_type: Any
model_name: str
class GCN_CUSTOM(torch.nn.Module):
def __init__(self, dataset):
super().__init__()
self.conv1 = GCNConv(dataset.num_node_features, dataset.num_node_features)
self.conv2 = GCNConv(dataset.num_node_features, dataset.num_node_features)
self.lin1 = Linear(dataset.num_node_features, dataset.num_classes)
def forward(self, x, edge_index):
x = self.conv1(x, edge_index)
x = F.relu(x)
x = F.dropout(x, training=self.training)
x = self.conv2(x, edge_index)
x = F.relu(x)
x = F.dropout(x, training=self.training)
x = self.lin1(x)
return F.log_softmax(x, dim=1)
# SGC Feature Extractor
class SGC_CUSTOM(torch.nn.Module):
def __init__(self, dataset):
super().__init__()
self.conv1 = SGConv(dataset.num_node_features, dataset.num_node_features, K=2)
self.conv1.lin = torch.nn.Identity()
def forward(self, x, edge_index):
return self.conv1(x, edge_index)
models = [
# ModelData(GCN_CUSTOM, "GCN_CUSTOM"),
ModelData(SGC_CUSTOM, "SGC_CUSTOM"),
# ModelData(GCN, "GCN"),
# ModelData(GraphSAGE, "GraphSAGE"),
# ModelData(GIN, "GIN"),
# ModelData(PNA, "PNA"),
# ModelData(GAT, "GAT"),
# ModelData(SVC, 'SVM'),
# ModelData(RandomForestClassifier, 'RF')
]