-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
67 lines (52 loc) · 1.82 KB
/
main.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
from globals import *
import yaml
import argparse
import random
import torch
from utils import ordered_yaml
from trainer import GNNTrainer
from evaluator import HomoGraphEvaluator, ExplainGraph
parser = argparse.ArgumentParser()
parser.add_argument('-config', type=str, help='Path to option YMAL file.', default="")
parser.add_argument('-seed', type=int, help='random seed of the run', default=611)
args = parser.parse_args()
opt_path = args.config
default_config_path = "BRCA/HEAT2_kimia_classification_v2.yml"
if opt_path == "":
opt_path = CONFIG_DIR / default_config_path
# Set seed
seed = args.seed
random.seed(seed)
torch.manual_seed(seed)
#############################################################
# Set modes:
# train: initialize trainer for classification
# eval: Evaluate the trained model quantitatively
# construct_graph: Construct graphs from WSI and save to disk
# graph_explain: Explain the GNN and plot the results
#############################################################
mode = "train"
def main():
with open(opt_path, mode='r') as f:
loader, _ = ordered_yaml()
config = yaml.load(f, loader)
print(f"Loaded configs from {opt_path}")
if mode == "train":
if config["train_type"] == "gnn":
trainer = GNNTrainer(config)
else:
raise NotImplementedError("This type of model is not implemented")
trainer.train()
elif mode == "eval":
if config["eval_type"] == "homo-graph":
evaluator = HomoGraphEvaluator(config)
else:
raise NotImplementedError("This type of evaluator is not implemented")
evaluator.eval()
elif mode == "graph_explain":
explainer = ExplainGraph(config)
explainer.eval()
elif mode == "construct_graph":
pass
if __name__ == "__main__":
main()