-
Notifications
You must be signed in to change notification settings - Fork 6
/
generate_exps_lenet.py
153 lines (144 loc) · 4.88 KB
/
generate_exps_lenet.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import yaml
import os
def get_name_exp_from_yaml(d):
name = "lenet_"
name += str(d["run"]) + "_"
name += str(d["nbr_sup"]) + "_"
name += str(len(d["h_ind"]) - 1) + "_"
name += "_".join([str(int(k)) for k in d["h_ind"]]) + "_"
name += str(d["repet"]) + "_"
name += str(d["hint"]) + "_"
name += str(d["norm_gsup"]) + "_"
name += str(d["norm_gh"]) + "_"
name += str(d["debug_code"]) + "_"
name += str(d["use_unsupervised"])
return name
def save_file(exp, rep, max_rep):
# grad normalization
# conf_norm = [(1, 0), (0, 1), (1, 1)]
conf_norm = [(0, 0)]
for c in conf_norm:
exp["norm_gh"] = bool(c[0])
exp["norm_gsup"] = bool(c[1])
if rep == max_rep - 1:
exp["debug_code"] = True
print "Just forces debuge to TRUE *********"
exp["debug_code"] = False
name = get_name_exp_from_yaml(exp)
with open(fold_exps+"/"+name+".yaml", "w") as fyaml:
yaml.dump(exp, fyaml)
f.write("python " + runner + " " + name + ".yaml \n")
# Default
nbr_layers = 3
use_unsupervised = False
exp = {"debug_code": False,
"nbr_sup": 1000,
"run": 45,
"h_ind": [False for i in range(nbr_layers+1)],
"use_batch_normalization": [False for i in range(nbr_layers+1)],
"corrupt_input_l": 0.,
"start_corrupting": 0,
"use_sparsity": False,
"use_sparsity_in_pred": False,
"max_epochs": 400,
"hint": False,
"extreme_random": True,
"norm_gsup": False,
"norm_gh": False,
"repet": 0,
"use_unsupervised": use_unsupervised,
"h_w": 1.,
"start_hint": 5
}
nbr_sup_ = [1000, 3000, 5000, 50000]
h_w_vls = [.0, .0, .0, .0]
start_hint_vl = [1, 1, 1, 1]
run = 0
fold_exps = "config_yaml"
bash_name = "joblenet.sh"
f = open(bash_name, "w")
f.write("#!/usr/bin/env bash \n")
runner = "trainLenet.py"
max_rep = 7
for nbr, h_w, start_hint in zip(nbr_sup_, h_w_vls, start_hint_vl):
for rep in range(max_rep):
print rep
exp["nbr_sup"] = nbr
# we need one run for an MLP without hint.
if rep == 0:
exp["debug_code"] = False
else:
exp["debug_code"] = False
exp["h_ind"] = [False for k in range(nbr_layers+1)]
exp["use_batch_normalization"] = [False for k in range(nbr_layers+1)]
exp["use_batch_normalization"][-2] = False
exp["hint"] = False
exp["run"] = run
exp["repet"] = rep
exp["norm_gh"] = False
exp["norm_gsup"] = False
exp["max_epochs"] = 2000
exp["start_hint"] = 0
print h_w
exp["h_w"] = h_w
name = get_name_exp_from_yaml(exp)
# with open(fold_exps+"/"+name+".yaml", "w") as fyaml:
# yaml.dump(exp, fyaml)
# f.write("python " + runner + " " + name + ".yaml \n")
# The layer just before the softmax.
exp["max_epochs"] = 400
exp["debug_code"] = False
# ******* Train inly the layer before the output.
exp["h_ind"] = [False for k in range(nbr_layers+1)]
exp["use_batch_normalization"] = [False for k in range(nbr_layers+1)]
exp["use_batch_normalization"][-2] = True
exp["h_ind"][-2] = True
exp["hint"] = True
exp["run"] = run
exp["repet"] = rep
exp["start_hint"] = start_hint
save_file(exp, rep, max_rep)
continue
# The output of the last cnn layer.
exp["max_epochs"] = 400
exp["debug_code"] = False
exp["h_ind"] = [False for k in range(nbr_layers+1)]
exp["h_ind"][-3] = True
exp["hint"] = True
exp["run"] = run
exp["repet"] = rep
save_file(exp, rep, max_rep)
# The last two layers beofre the softmax.
exp["max_epochs"] = 400
exp["debug_code"] = False
exp["h_ind"] = [False for k in range(nbr_layers+1)]
exp["h_ind"][-2] = True
exp["h_ind"][-3] = True
exp["hint"] = True
exp["run"] = run
exp["repet"] = rep
save_file(exp, rep, max_rep)
continue
# *****
# Exclusive layers
for i in range(nbr_layers+1):
exp["h_ind"] = [False for k in range(nbr_layers+1)]
exp["h_ind"][i] = True
exp["hint"] = True
exp["run"] = run
exp["repet"] = rep
save_file(exp, rep, max_rep)
# From input to output
# exp["h_ind"] = [False for k in range(nbr_layers+1)]
# exp["h_ind"][0] = True
# for kk in range(1, nbr_layers+1):
# exp["h_ind"][kk] = True
# save_file(exp, rep, max_rep)
# From output to input
exp["h_ind"] = [False for k in range(nbr_layers+1)]
exp["h_ind"][-1] = True
for kk in range(-2, -(nbr_layers+2), -1):
exp["h_ind"][kk] = True
save_file(exp, rep, max_rep)
f.close()
os.system("chmod +x " + bash_name)