-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainGNN.py
34 lines (27 loc) · 1003 Bytes
/
trainGNN.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
from GNNs.gnn_trainer import GNNTrainer
from GNNs.dgl_gnn_trainer import DGLGNNTrainer
import pandas as pd
from config import cfg, update_cfg
import time
def run(cfg):
seeds = [cfg.seed] if cfg.seed is not None else range(cfg.runs)
if cfg.gnn.model.name == 'RevGAT':
TRAINER = DGLGNNTrainer
else:
TRAINER = GNNTrainer
all_acc = []
start = time.time()
for seed in seeds:
cfg.seed = seed
trainer = TRAINER(cfg, cfg.gnn.train.feature_type)
trainer.train()
_, acc = trainer.eval_and_save()
all_acc.append(acc)
end = time.time()
if len(all_acc) > 1:
df = pd.DataFrame(all_acc)
print(f"[{cfg.gnn.model.name} + {cfg.gnn.train.feature_type}] ValACC: {df['val_acc'].mean():.4f} ± {df['val_acc'].std():.4f}, TestAcc: {df['test_acc'].mean():.4f} ± {df['test_acc'].std():.4f}")
print(f"Running time: {(end-start)/len(seeds):.2f}s")
if __name__ == '__main__':
cfg = update_cfg(cfg)
run(cfg)