-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharguments.py
226 lines (218 loc) · 6.28 KB
/
arguments.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
import argparse
def parse_args():
"""
parse_args parses command line arguments and returns argparse.Namespace object
Returns
-------
argparse.Namespace
Namespace that contains all command line arguments with their corresponding values
"""
parser = argparse.ArgumentParser(description="FixMatch training")
# General arguments
parser.add_argument(
"--model",
default="wide_resnet28_2",
choices=[
"vgg11",
"vgg13",
"vgg16",
"vgg19",
"resnet18",
"resnet34",
"resnet50",
"wide_resnet28_2",
"wide_resnet28_10",
"wide_resnet50_10",
"densenet121",
"densenet161",
"densenet201",
"preact_resnet18",
"preact_resnet34",
"preact_resnet50",
],
type=str,
help="Used model architecture for classification task",
)
parser.add_argument(
"--device",
default="cuda",
type=str,
choices=["cpu", "cuda"],
help="Device used for training",
)
parser.add_argument(
"--num-workers",
default=0,
type=int,
help="Number of workers used for data loading",
)
parser.add_argument(
"--out-dir",
default="./out",
type=str,
help="path to which output logs, losses and model checkpoints are saved.",
)
parser.add_argument(
"--dataset",
default="cifar10",
choices=[
"cifar10",
"cifar100",
"imagenet",
"svhn",
"caltech101",
"caltech256",
"stl10",
"ham10000",
],
type=str,
help="name of dataset",
)
parser.add_argument(
"--data-dir", default="./data", type=str, help="path to which dataset is saved"
)
parser.add_argument(
"--resume",
default="",
type=str,
help="path to checkpoint from which to resume training",
)
parser.add_argument("--epochs", default=1024, type=int, help="number of epochs")
parser.add_argument(
"--iters-per-epoch",
default=1024,
type=int,
help="number of iterations per epoch",
)
parser.add_argument("--batch-size", default=64, type=int, help="batch_size")
parser.add_argument("--lr", default=0.03, type=float, help="initial learning rate")
parser.add_argument("--wd", default=0.0005, type=float, help="weight decay")
parser.add_argument(
"--ema-decay",
default=0.999,
type=float,
help="exponential moving average decay",
)
parser.add_argument(
"--pin-memory",
action="store_true",
help="Should CPU tensors be directly allocated in Pinned memory for data loading",
)
parser.add_argument(
"--checkpoint-interval",
type=int,
default=50,
help="Interval [epoch] in which checkpoints are saved.",
)
parser.add_argument(
"--seed",
type=int,
default=65,
help="Manually set seed for random number generators",
)
parser.add_argument(
"--trainable-layers",
type=str,
nargs='+',
default=[],
help='If pretrained flag is set, this specifies the layers for which weights should be frozen'
)
# Flags
parser.add_argument(
"--pretrained",
dest="pretrained",
action="store_true",
default=False,
help="Flag indicating if models should be loaded as pretrained (if available) or not",
)
parser.add_argument(
"--weighted-sampling",
dest="weighted_sampling",
action="store_true",
default=False,
help="""Flag indicating if batches selects samples inversely proportional to class distribution,
i.e. whether on average samples from each class should be selected with equal probability"""
)
parser.add_argument(
"--save",
dest="save",
action="store_true",
default=False,
help="Flag indicating if models should be saved or not",
)
parser.add_argument(
"--use-ema",
dest="use_ema",
action="store_true",
default=False,
help="use ema model for plotting",
)
parser.add_argument(
"--random-seed",
dest="random_seed",
action="store_true",
default=False,
help="if specified seed is randomly set",
)
parser.add_argument(
"--polyaxon",
dest="polyaxon",
action="store_true",
default=False,
help="Flag indicating if training is run on polyaxon or not",
)
parser.add_argument(
"--pbar", dest="pbar", action="store_true", default=False, help="print progress bar"
)
# Dataset split settings
parser.add_argument("--initial-indices", type=str, help='path to initial indice file to start from')
parser.add_argument(
"--num-labeled", default=250, type=float, help="number of labeled samples *per class* for SSL"
)
parser.add_argument(
"--num-validation",
type=int,
default=1,
help="Defines percentage used for training and validation",
)
# FixMatch arguments
parser.add_argument(
"--mu", default=7, type=int, help="coefficient of unlabeled batch size"
)
parser.add_argument(
"--wu",
default=1,
type=float,
help="Weight of unlabeled loss (all SSL algorithms) ",
)
parser.add_argument(
"--num-augmentations",
default=2,
type=int,
help="number of augmentations used for strong aug.",
)
parser.add_argument(
"--m",
default=30,
type=int,
help="magnitude of randaugment (strong augmentation)",
)
parser.add_argument(
"--threshold",
default=0.95,
type=float,
help="Pseudo-label threshold in FixMatch (tau)",
)
parser.add_argument(
"--beta",
default=0.9,
type=float,
help="beta for momentum of SGD optimizer in FixMatch",
)
parser.add_argument(
"--lr-decay-K",
default=2 ** 20,
type=int,
help="parameter K for cosine LR decay",
)
return parser.parse_args()