-
Notifications
You must be signed in to change notification settings - Fork 18
/
args.py
247 lines (236 loc) · 6.42 KB
/
args.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#
# For licensing see accompanying LICENSE file.
# Copyright (C) 2020 Apple Inc. All Rights Reserved.
#
import argparse
args = None
def parse_arguments():
# Training settings
parser = argparse.ArgumentParser(description="Learning-Subspaces")
parser.add_argument(
"--num-models",
type=int,
default=1,
help="Number of models currently being considered for training ensembles or SWA",
)
parser.add_argument(
"--num-samples",
type=int,
default=1,
help="Number of samples drawn from the subspace for each batch.",
)
parser.add_argument(
"--optimizer", type=str, default="sgd", help="Which optimizer to use"
)
parser.add_argument(
"--batch-size",
type=int,
default=128,
metavar="N",
help="input batch size for training (default: 64)",
)
parser.add_argument(
"--test-batch-size",
type=int,
default=128,
metavar="N",
help="input batch size for testing (default: 128)",
)
parser.add_argument(
"--epochs",
type=int,
default=160,
metavar="N",
help="number of epochs to train (default: 100)",
)
parser.add_argument(
"--lr",
type=float,
default=0.1,
metavar="LR",
help="learning rate (default: 0.1)",
)
parser.add_argument(
"--momentum",
type=float,
default=0.9,
metavar="M",
help="Momentum (default: 0.9)",
)
parser.add_argument(
"--dropout", type=float, default=0.5,
)
parser.add_argument(
"--wd",
type=float,
default=0.0001,
metavar="M",
help="Weight decay (default: 0.0001)",
)
parser.add_argument(
"--seed",
type=int,
default=1,
metavar="S",
help="random seed (default: 1)",
)
parser.add_argument(
"--log-interval",
type=int,
default=10,
metavar="N",
help="how many batches to wait before logging training status",
)
parser.add_argument(
"--workers", type=int, default=4, help="how many cpu workers"
)
parser.add_argument(
"--output-size",
type=int,
default=10,
help="how many total neurons in last layer",
)
parser.add_argument(
"--name", type=str, default="default", help="Experiment id."
)
parser.add_argument(
"--data", type=str, help="Location to store data",
)
parser.add_argument(
"--log-dir", type=str, help="Location to logs/checkpoints",
)
parser.add_argument(
"--resume",
type=lambda x: [str(a) for a in x.split(",")],
default=None,
help="optionally resume",
)
parser.add_argument(
"--model-name", type=str, default=None, help="model name where required"
)
parser.add_argument(
"--ct", type=str, default="snow", help="Corruption type for ImageNet-C"
)
parser.add_argument(
"--sev", type=int, default=1, help="Corruption severity for ImageNet-C"
)
parser.add_argument(
"--width-mult", type=float, default=1.0, help="how wide is each layer"
)
parser.add_argument(
"--conv_type",
type=str,
default="StandardConv",
help="Type of conv layer",
)
parser.add_argument(
"--bn_type",
type=str,
default="StandardBN",
help="Type of batch norm layer.",
)
parser.add_argument(
"--conv-init",
type=str,
default="kaiming_normal",
help="How to initialize the conv weights.",
)
parser.add_argument(
"--baset", type=float, default=0.1,
)
parser.add_argument(
"--n",
type=int,
default=-1,
help="For simplexes -- number of endpoints used to define the simplex.",
)
parser.add_argument("--model", type=str, help="Type of model.")
parser.add_argument(
"--multigpu",
default=None,
type=lambda x: [int(a) for a in x.split(",")],
help="Which GPUs to use for multigpu training",
)
parser.add_argument(
"--save-epochs",
default=None,
type=lambda x: [int(a) for a in x.split(",")],
help="Which epochs to save",
)
parser.add_argument(
"--save-iters",
default=None,
type=lambda x: [int(a) for a in x.split(",")],
help="Which epochs to save",
)
parser.add_argument(
"--swa-save-epochs",
default=None,
type=lambda x: [int(a) for a in x.split(",")],
help="Which epochs to save for swa",
)
parser.add_argument(
"--mode", default="fan_in", help="Weight initialization mode"
)
parser.add_argument(
"--nonlinearity",
default="relu",
help="Nonlinearity used by initialization",
)
parser.add_argument("--set", type=str, help="Which dataset to use")
parser.add_argument(
"--trainer",
default=None,
type=str,
help="Which trainer to use, default in trainers/default.py",
)
parser.add_argument("--lr-policy", default=None, help="Scheduler to use")
parser.add_argument(
"--warmup-length", default=0, type=int,
)
parser.add_argument(
"--pretrained", action="store_true", default=False,
)
parser.add_argument(
"--save", action="store_true", default=False,
)
parser.add_argument(
"--save-data", action="store_true", default=False,
)
parser.add_argument(
"--trainswa", action="store_true", default=False,
)
parser.add_argument(
"--label-smoothing", type=float, default=None,
)
parser.add_argument(
"--label-noise", type=float, default=None,
)
parser.add_argument(
"--beta", type=float, default=-1,
)
parser.add_argument(
"--lamb", type=float, default=-1,
)
parser.add_argument(
"--swa-start", type=float, default=0.75,
)
parser.add_argument(
"--swa-lr", type=float, default=0.05,
)
parser.add_argument(
"--test-freq", type=int, default=None,
)
parser.add_argument(
"--update-bn", action="store_true", default=False,
)
parser.add_argument(
"--train-update-bn", action="store_true", default=False,
)
args = parser.parse_args()
return args
def run_args():
global args
if args is None:
args = parse_arguments()
run_args()