-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.py
executable file
·164 lines (158 loc) · 4.15 KB
/
utils.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
154
155
156
157
158
159
160
161
162
163
164
import numpy as np
def one_hot(a, num_classes):
return np.squeeze(np.eye(num_classes)[a.reshape(-1)])
def double_print(text, output_file = None, end = '\n'):
print(text, end = end)
if not output_file is None:
output_file.write(str(text) + end)
output_file.flush()
def get_best_finite_hypers(ds, ss, use_label_scale = True, use_instance = False, from_instance = False):
#hyperparameters for finite networks trained with gradient descent
if use_instance:
if not from_instance:
if ss == 1:
lr = 1e-4
ls = 8
wd = 0
elif ss == 10:
lr = 1e-3
ls = 8
wd = 0
elif ss == 50:
lr = 1e-3
ls = 2
wd = 0
else:
if ss == 1:
lr = 1e-3
ls = 16
wd = 0
elif ss == 10:
lr = 1e-2
ls = 8
wd = 0
elif ss == 50:
lr = 1e-3
ls = 2
wd = 0
elif from_instance:
if ss == 1:
lr = 1e-4
ls = 16
wd = 0
elif ss == 10:
lr = 1e-4
ls = 8
wd = 0
elif ss == 50:
lr = 1e-2
ls = 8
wd = 0
elif use_label_scale:
if ss == 1:
if ds == 'mnist':
lr = 1e-3
ls = 8
wd = 1e-3
elif ds == 'fashion':
lr = 1e-3
ls = 8
wd = 0
elif ds == 'svhn':
lr = 1e-3
ls = 16
wd = 0
elif ds == 'cifar10':
lr = 1e-3
ls = 8
wd = 0
elif ds == 'cifar100':
lr = 1e-1
ls = 8
wd = 0
elif ss == 10:
if ds == 'mnist':
lr = 1e-2
ls = 8
wd = 1e-3
elif ds == 'fashion':
lr = 1e-2
ls = 8
wd = 1e-3
elif ds == 'svhn':
lr = 1e-2
ls = 8
wd = 0
elif ds == 'cifar10':
lr = 1e-3
ls = 2
wd = 0
elif ds == 'cifar100':
lr = 1e-1
ls = 2
wd = 0
elif ss == 50:
if ds == 'mnist':
lr = 1e-2
ls = 8
wd = 0
elif ds == 'fashion':
lr = 1e-3
ls = 2
wd = 0
elif ds == 'svhn':
lr = 1e-2
ls = 2
wd = 0
elif ds == 'cifar10':
lr = 1e-2
ls = 2
wd = 0
else:
ls = 1
if ss == 1:
if ds == 'mnist':
lr = 1e-5
wd = 0
elif ds == 'fashion':
lr = 1e-3
wd = 0
elif ds == 'svhn':
lr = 1e-4
wd = 0
elif ds == 'cifar10':
lr = 1e-4
wd = 0
elif ds == 'cifar100':
lr = 1e-2
wd = 0
elif ss == 10:
if ds == 'mnist':
lr = 1e-4
wd = 1e-3
elif ds == 'fashion':
lr = 1e-4
wd = 1e-3
elif ds == 'svhn':
lr = 1e-3
wd = 0
elif ds == 'cifar10':
lr = 1e-4
wd = 0
elif ds == 'cifar100':
lr = 1e-2
wd = 0
elif ss == 50:
if ds == 'mnist':
lr = 1e-3
wd = 0
elif ds == 'fashion':
lr = 1e-3
wd = 0
elif ds == 'svhn':
lr = 1e-3
wd = 0
elif ds == 'cifar10':
lr = 1e-3
wd = 0
return lr, ls, wd