-
Notifications
You must be signed in to change notification settings - Fork 10
/
train.py
88 lines (68 loc) · 2.43 KB
/
train.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import numpy as np
import argparse
from diffusion.utils import add_parent_path, set_seeds
# Data
add_parent_path(level=1)
from datasets.data import get_data, get_data_id, add_data_args
# Exp
from experiment import GraphExperiment, add_exp_args
# Model
from model import get_model, get_model_id, add_model_args
# Optim
from diffusion.optim.multistep import get_optim, get_optim_id, add_optim_args
###########
## Setup ##
###########
parser = argparse.ArgumentParser()
add_data_args(parser)
add_exp_args(parser)
add_model_args(parser)
add_optim_args(parser)
args = parser.parse_args()
set_seeds(args.seed)
##################
## Specify data ##
##################
train_loader, eval_loader, test_loader, num_node_feat, num_node_classes, num_edge_classes, max_degree, augmented_feature_dict, initial_graph_sampler, eval_evaluator, test_evaluator, monitoring_statistics = get_data(args)
args.num_edge_classes = num_edge_classes
args.num_node_classes = num_node_classes
if args.final_prob_node is None:
args.final_prob_node = [1-1e-12, 1e-12]
args.num_node_classes = 2
args.has_node_feature = False
if 0 in args.final_prob_edge:
args.final_prob_edge[np.argmax(args.final_prob_edge)] = args.final_prob_edge[np.argmax(args.final_prob_edge)]-1e-12
args.final_prob_edge[np.argmin(args.final_prob_edge)] = 1e-12
args.max_degree = max_degree
args.num_node_feat = num_node_feat
args.augmented_feature_dict = augmented_feature_dict
data_id = get_data_id(args)
###################
## Specify model ##
###################
model = get_model(args, initial_graph_sampler=initial_graph_sampler)
model_id = get_model_id(args)
#######################
## Specify optimizer ##
#######################
optimizer, scheduler_iter, scheduler_epoch = get_optim(args, model)
optim_id = get_optim_id(args)
##############
## Training ##
##############
exp = GraphExperiment(args=args,
data_id=data_id,
model_id=model_id,
optim_id=optim_id,
train_loader=train_loader,
eval_loader=eval_loader,
test_loader=test_loader,
model=model,
optimizer=optimizer,
scheduler_iter=scheduler_iter,
scheduler_epoch=scheduler_epoch,
monitoring_statistics=monitoring_statistics,
eval_evaluator=eval_evaluator,
test_evaluator=test_evaluator,
n_patient=50)
exp.run()