-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch_main.py
102 lines (90 loc) · 3.27 KB
/
launch_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
90
91
92
93
94
95
96
97
98
99
100
101
102
import argparse
import yaml
import subprocess
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Train or evaluate a gdrn model")
parser.add_argument("run", help="config file name", type=str)
parser.add_argument("run_id", help="unique run id", type=str)
parser.add_argument("--evaluate", action="store_true", default=False, help="evaluate or train")
parser.add_argument("--checkpoint", help="checkpoint to load", type=str)
parser.add_argument("--resume", action="store_true", default=False, help="resume training from checkpoint")
parser.add_argument("--debug", action="store_true", default=False, help="run in debug mode")
args = parser.parse_args()
run = args.run
run_id = args.run_id
if run_id.split('_')[-1][-1] == 's':
seeded = True
seed = int(run_id.split('_')[-1][:-1])
with open('runs/{run}.yaml'.format(run=run), 'r') as f:
config = yaml.load(f, Loader=yaml.FullLoader)
config_file = config['config_file']['value']
core = config['core']['value']
method = config['method']['value']
dataset = config['dataset']['value']
epochs = config['epochs']['value']
bs = config['bs']['value']
gpus = config['gpus']['value']
config_path = 'configs/{method}/{dataset}/{config_file}'.format(
method=method,
dataset=dataset,
config_file=config_file
)
weights = 'output/{method}/{dataset}/{run_id}/model_final.pth'.format(
method=method,
dataset=dataset,
run_id=run_id
)
if args.evaluate and args.checkpoint:
weights = args.checkpoint
if not args.evaluate:
# Train
s = (
"python core/{core}_modeling/main_gdrn.py"
+ " --config-file {config}"
+ " --num-gpus {gpus}"
+ " --opts"
+ " SOLVER.IMS_PER_BATCH={bs}"
+ " SOLVER.TOTAL_EPOCHS={epochs}"
+ " OUTPUT_DIR=\"output/{method}/{dataset}/{run_id}\""
+ " SOLVER.MAX_TO_KEEP={max_to_keep}"
+ " SOLVER.CHECKPOINT_PERIOD={checkpoint_period}"
+ " {weights}"
+ " {seed}"
)
s = s.format(
core=core,
method=method,
dataset=dataset,
config=config_path,
run_id=run_id,
gpus=gpus,
bs=bs,
epochs=epochs,
max_to_keep=2,
checkpoint_period=5,
weights="MODEL.WEIGHTS=\"{}\"".format(args.checkpoint) if args.resume else "",
seed="SEED={}".format(seed) if seeded else "",
)
print(s + '\n')
subprocess.call(s, shell=True)
# Evaluate
if not args.debug:
s = (
"python core/{core}_modeling/main_gdrn.py"
+ " --config-file {config}"
+ " --num-gpus 1"
+ " --eval-only"
+ " --opts"
+ " OUTPUT_DIR=\"output/{method}/{dataset}/{run_id}\""
+ " MODEL.WEIGHTS=\"{weights}\""
)
s = s.format(
core=core,
method=method,
dataset=dataset,
config=config_path,
run_id=run_id,
weights=weights,
)
print(s + '\n')
subprocess.call(s, shell=True)