|
a |
|
b/tasks_adapt/generate.py |
|
|
1 |
'''Training script generator for subject-adaptive classification. |
|
|
2 |
''' |
|
|
3 |
from os import makedirs |
|
|
4 |
from os.path import join as pjoin |
|
|
5 |
|
|
|
6 |
with open(pjoin('tasks_adapt', 'script.sh.template'), 'r') as f: |
|
|
7 |
sh_template = f.read() |
|
|
8 |
with open(pjoin('tasks_adapt', 'train.pbs.template'), 'r') as f: |
|
|
9 |
pbs_template = f.read() |
|
|
10 |
|
|
|
11 |
|
|
|
12 |
def list_to_str(l): |
|
|
13 |
return ' '.join(map(str, l)) |
|
|
14 |
|
|
|
15 |
|
|
|
16 |
command_template = "python train_adapt.py $datapath $modelpath ./result_adapt{0}/r{1} -scheme {0} -trfrate {1} -gpu {2} > $logpath/stdout.r{1}.out &" |
|
|
17 |
|
|
|
18 |
for scheme in range(1, 6): |
|
|
19 |
tasks_dir = "tasks_adapt{}".format(scheme) |
|
|
20 |
result_dir = "result_adapt{}".format(scheme) |
|
|
21 |
|
|
|
22 |
makedirs(tasks_dir, exist_ok=True) |
|
|
23 |
for rate in range(10, 101, 10): |
|
|
24 |
makedirs(pjoin(result_dir, "r{}".format(rate)), exist_ok=True) |
|
|
25 |
|
|
|
26 |
commands = [] |
|
|
27 |
for ind, rate in enumerate(range(10, 81, 10)): |
|
|
28 |
commands.append(command_template.format(scheme, rate, ind)) |
|
|
29 |
commands.append('wait') |
|
|
30 |
content = sh_template.format(scheme) + '\n'.join(commands) |
|
|
31 |
ncpu = 40 |
|
|
32 |
ngpu = 8 |
|
|
33 |
with open(pjoin(tasks_dir, 'script.' + str(0) + '.sh'), 'w') as f: |
|
|
34 |
f.write(content) |
|
|
35 |
content = pbs_template.format(0, scheme, ncpu, ngpu) |
|
|
36 |
with open(pjoin(tasks_dir, 'train.' + str(0) + '.pbs'), 'w') as f: |
|
|
37 |
f.write(content) |
|
|
38 |
|
|
|
39 |
tasks_dir = "tasks_adaptr" |
|
|
40 |
command_template = "python train_adapt.py $datapath $modelpath ./result_adapt{0}/r{1} -scheme {0} -trfrate {1} -gpu {2} > $logpath/stdout.s{0}.r{1}.out &" |
|
|
41 |
makedirs(tasks_dir, exist_ok=True) |
|
|
42 |
commands = [] |
|
|
43 |
for scheme in range(1, 5): |
|
|
44 |
for ind, rate in enumerate(range(90, 101, 10)): |
|
|
45 |
igpu = (scheme - 1) * 2 + ind |
|
|
46 |
commands.append(command_template.format(scheme, rate, igpu)) |
|
|
47 |
commands.append('wait') |
|
|
48 |
content = sh_template.format('r') + '\n'.join(commands) |
|
|
49 |
ncpu = 40 |
|
|
50 |
ngpu = 8 |
|
|
51 |
with open(pjoin(tasks_dir, 'script.' + str(0) + '.sh'), 'w') as f: |
|
|
52 |
f.write(content) |
|
|
53 |
content = pbs_template.format(0, 'r', ncpu, ngpu) |
|
|
54 |
with open(pjoin(tasks_dir, 'train.' + str(0) + '.pbs'), 'w') as f: |
|
|
55 |
f.write(content) |
|
|
56 |
|
|
|
57 |
commands = [] |
|
|
58 |
scheme = 5 |
|
|
59 |
for ind, rate in enumerate(range(90, 101, 10)): |
|
|
60 |
commands.append(command_template.format(scheme, rate, ind)) |
|
|
61 |
commands.append('wait') |
|
|
62 |
content = sh_template.format('r') + '\n'.join(commands) |
|
|
63 |
ncpu = 10 |
|
|
64 |
ngpu = 2 |
|
|
65 |
with open(pjoin(tasks_dir, 'script.' + str(1) + '.sh'), 'w') as f: |
|
|
66 |
f.write(content) |
|
|
67 |
content = pbs_template.format(1, 'r', ncpu, ngpu) |
|
|
68 |
with open(pjoin(tasks_dir, 'train.' + str(1) + '.pbs'), 'w') as f: |
|
|
69 |
f.write(content) |