-
Notifications
You must be signed in to change notification settings - Fork 12
/
tagcn.py
28 lines (22 loc) · 946 Bytes
/
tagcn.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
import os.path as osp
import torch
import torch_geometric.transforms as T
from greatx.datasets import GraphDataset
from greatx.nn.models import TAGCN
from greatx.training import Trainer
from greatx.training.callbacks import ModelCheckpoint
from greatx.utils import split_nodes
dataset = 'Cora'
root = osp.join(osp.dirname(osp.realpath(__file__)), '../../..', 'data')
dataset = GraphDataset(root=root, name=dataset,
transform=T.LargestConnectedComponents())
data = dataset[0]
splits = split_nodes(data.y, random_state=15)
num_features = data.x.size(-1)
num_classes = data.y.max().item() + 1
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = TAGCN(num_features, num_classes)
trainer = Trainer(model, device=device)
ckp = ModelCheckpoint('model.pth', monitor='val_acc')
trainer.fit(data, mask=(splits.train_nodes, splits.val_nodes), callbacks=[ckp])
trainer.evaluate(data, splits.test_nodes)