[5d1c0a]: / tasks_adapt / generate.py

Download this file

70 lines (59 with data), 2.5 kB

 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
'''Training script generator for subject-adaptive classification.
'''
from os import makedirs
from os.path import join as pjoin
with open(pjoin('tasks_adapt', 'script.sh.template'), 'r') as f:
sh_template = f.read()
with open(pjoin('tasks_adapt', 'train.pbs.template'), 'r') as f:
pbs_template = f.read()
def list_to_str(l):
return ' '.join(map(str, l))
command_template = "python train_adapt.py $datapath $modelpath ./result_adapt{0}/r{1} -scheme {0} -trfrate {1} -gpu {2} > $logpath/stdout.r{1}.out &"
for scheme in range(1, 6):
tasks_dir = "tasks_adapt{}".format(scheme)
result_dir = "result_adapt{}".format(scheme)
makedirs(tasks_dir, exist_ok=True)
for rate in range(10, 101, 10):
makedirs(pjoin(result_dir, "r{}".format(rate)), exist_ok=True)
commands = []
for ind, rate in enumerate(range(10, 81, 10)):
commands.append(command_template.format(scheme, rate, ind))
commands.append('wait')
content = sh_template.format(scheme) + '\n'.join(commands)
ncpu = 40
ngpu = 8
with open(pjoin(tasks_dir, 'script.' + str(0) + '.sh'), 'w') as f:
f.write(content)
content = pbs_template.format(0, scheme, ncpu, ngpu)
with open(pjoin(tasks_dir, 'train.' + str(0) + '.pbs'), 'w') as f:
f.write(content)
tasks_dir = "tasks_adaptr"
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 &"
makedirs(tasks_dir, exist_ok=True)
commands = []
for scheme in range(1, 5):
for ind, rate in enumerate(range(90, 101, 10)):
igpu = (scheme - 1) * 2 + ind
commands.append(command_template.format(scheme, rate, igpu))
commands.append('wait')
content = sh_template.format('r') + '\n'.join(commands)
ncpu = 40
ngpu = 8
with open(pjoin(tasks_dir, 'script.' + str(0) + '.sh'), 'w') as f:
f.write(content)
content = pbs_template.format(0, 'r', ncpu, ngpu)
with open(pjoin(tasks_dir, 'train.' + str(0) + '.pbs'), 'w') as f:
f.write(content)
commands = []
scheme = 5
for ind, rate in enumerate(range(90, 101, 10)):
commands.append(command_template.format(scheme, rate, ind))
commands.append('wait')
content = sh_template.format('r') + '\n'.join(commands)
ncpu = 10
ngpu = 2
with open(pjoin(tasks_dir, 'script.' + str(1) + '.sh'), 'w') as f:
f.write(content)
content = pbs_template.format(1, 'r', ncpu, ngpu)
with open(pjoin(tasks_dir, 'train.' + str(1) + '.pbs'), 'w') as f:
f.write(content)