-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrun.py
100 lines (70 loc) · 2.31 KB
/
run.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
import sys
import os.path
import subprocess
import datetime
import uuid
import pandas
import numpy
from microesc import common
def arglist(options):
args = [ "--{}={}".format(k, v) for k, v in options.items() ]
return args
def command_for_job(options):
args = [
'python3', 'train.py'
]
args += arglist(options)
return args
def generate_train_jobs(experiments, settings_path, folds, overrides):
timestamp = datetime.datetime.now().strftime('%Y%m%d-%H%M')
unique = str(uuid.uuid4())[0:4]
def name(experiment, fold):
name = "-".join([experiment, timestamp, unique])
return name+'-fold{}'.format(fold)
def job(exname, experiment):
for fold in folds:
n = name(exname, fold)
options = {
'name': n,
'fold': fold,
'settings': settings_path,
}
for k, v in experiment.items():
# overrides per experiment
options[k] = v
for k, v in overrides.items():
options[k] = v
cmd = command_for_job(options)
return cmd
# FIXME: better job name
jobs = [ job(str(idx), ex) for idx, ex in experiments.iterrows() ]
return jobs
def parse(args):
import argparse
parser = argparse.ArgumentParser(description='Generate jobs')
#common.add_arguments(parser)
a = parser.add_argument
a('--models', default='models.csv',
help='%(default)s')
a('--settings', default='experiments/ldcnn20k60.yaml',
help='%(default)s')
a('--jobs', dest='jobs_dir', default='./data/jobs',
help='%(default)s')
a('--check', action='store_true',
help='Only run a pre-flight check')
parsed = parser.parse_args(args)
return parsed
def main():
args = parse(sys.argv[1:])
models = pandas.read_csv(args.models)
settings = common.load_settings_path(args.settings)
overrides = {}
folds = list(range(0, 9))
if args.check:
folds = (1,)
overrides['train_samples'] = settings['batch']*1
overrides['val_samples'] = settings['batch']*1
cmds = generate_train_jobs(models, args.settings, folds, overrides)
print('\n'.join(" ".join(cmd) for cmd in cmds))
if __name__ == '__main__':
main()