-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
89 lines (74 loc) · 2.21 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import torch.distributed as dist
import torch.multiprocessing as mp
import os
import os.path as osp
import sys
import numpy as np
import copy
from lib.cfg_holder import cfg_unique_holder as cfguh
from lib.cfg_helper import \
get_experiment_id, \
cfg_to_debug, \
get_command_line_args, \
cfg_initiates
from lib.utils import train as train_base
from lib.utils import eval as eval_base
from lib.model_zoo.shgan import version
from lib.experiments import get_experiment
class train(train_base):
def prepare_model(self):
# Do not load model here
return {}
def prepare_dataloader(self):
# Do not load dataset here
return {}
def save(self, *args, **kwargs):
pass
class eval(eval_base):
def prepare_model(self):
# Do not load model here
return {}
def prepare_dataloader(self):
# Do not load dataset here
return {}
if __name__ == "__main__":
cfg = get_command_line_args()
isresume = 'resume_path' in cfg.env
if ('train' in cfg) and not isresume:
cfg.train.experiment_id = get_experiment_id()
isdebug = getattr(cfg.env, 'debug', False)
if isdebug:
# pass
if not isresume:
cfg = cfg_to_debug(cfg)
else:
cfg.env.gpu_device = [0]
cfg.env.gpu_count = 1
if 'train' in cfg:
cfg.train.image_snapshot_ticks = 1
if 'eval' in cfg:
cfg.eval.dataset.try_sample = 32
cfg.eval.batch_size_per_gpu = 32
cfg = cfg_initiates(cfg)
if 'train' in cfg:
trainer = train(cfg)
tstage = get_experiment(cfg.train.exec_stage)()
trainer.register_stage(tstage)
if cfg.env.gpu_count == 1:
trainer(0)
else:
mp.spawn(trainer,
args=(),
nprocs=cfg.env.gpu_count,
join=True)
else:
evaler = eval(cfg)
estage = get_experiment(cfg.eval.exec_stage)()
evaler.register_stage(estage)
if cfg.env.gpu_count == 1:
evaler(0)
else:
mp.spawn(evaler,
args=(),
nprocs=cfg.env.gpu_count,
join=True)