forked from haeusser/NebuLight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridsearch.py
72 lines (52 loc) · 1.74 KB
/
gridsearch.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
# basic hyperparameter grid search
# just calls scripts using exec, and logs result
from subprocess import call
from random import randint
def create_task_list(combine_params):
"""
recursively creates a grid-search task list
params should be a dictionary
"""
keys = list(combine_params.keys())
task_list = []
firstKey = keys[0]
firstKeyValues = combine_params[firstKey]
if len(keys) > 1:
dict_without_first_key = combine_params.copy()
del dict_without_first_key[firstKey]
subtasks = create_task_list(dict_without_first_key)
for v in firstKeyValues:
new_dict = {firstKey: v}
for task in subtasks:
merged = new_dict.copy()
merged.update(task)
task_list = task_list + [merged]
else:
task_list = [{firstKey: v} for v in firstKeyValues]
return task_list
def addTasks(script, params):
"""
Create tasks and add to nebulight
:param script: script name
:param params:
:return:
"""
tasks = create_task_list(params)
for task in tasks:
runid = str(randint(0,999999))
params_list = [" --run_id " + runid]
for a in task.items():
params_list = params_list + ['--'+str(a[0]), str(a[1])]
command = script + ' '.join(params_list)
logfile = '--logfile=results'+runid+'.log'
call(["./nebulight.py", "add", logfile, '"'+command+'"'])
if __name__ == '__main__':
addTasks("python3 /usr/stud/plapp/learning_by_association/semisup/cifar100_train_eval.py", {
"dataset_dir": ["/usr/stud/plapp/data/cifar100/sup100_20CoarseClasses"],
"logdir": ["/usr/stud/plapp/data/logs/cifar100sup100test"],
"eval_interval": [5000],
"max_steps": [2000],
"unsup": [True],
"sup_batch_size": [128],
"unsup_batch_size": [128, 256]
})