-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy patharguments.py
509 lines (400 loc) · 17 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
DEFAULT_IMAGES_KITTI = 57874
DEFAULT_DEPTH_BATCH_SIZE = 6
DEFAULT_SEG_BATCH_SIZE = 6
DEFAULT_BATCHES_PER_EPOCH = DEFAULT_IMAGES_KITTI // DEFAULT_DEPTH_BATCH_SIZE
class ArgumentsBase(object):
DESCRIPTION = 'SGDepth Arguments'
def __init__(self):
self.ap = ArgumentParser(
description=self.DESCRIPTION,
formatter_class=ArgumentDefaultsHelpFormatter
)
def _harness_init_system(self):
self.ap.add_argument(
'--sys-cpu', default=False, action='store_true',
help='Disable Hardware acceleration'
)
self.ap.add_argument(
'--sys-num-workers', type=int, default=3,
help='Number of worker processes to spawn per DataLoader'
)
self.ap.add_argument(
'--sys-best-effort-determinism', default=False, action='store_true',
help='Try and make some parts of the training/validation deterministic'
)
def _harness_init_model(self):
self.ap.add_argument(
'--model-num-layers', type=int, default=18, choices=(18, 34, 50, 101, 152),
help='Number of ResNet Layers in the depth and segmentation encoder'
)
self.ap.add_argument(
'--model-num-layers-pose', type=int, default=18, choices=(18, 34, 50, 101, 152),
help='Number of ResNet Layers in the pose encoder'
)
self.ap.add_argument(
'--model-split-pos', type=int, default=1, choices=(0, 1, 2, 3, 4),
help='Position in the decoder to split from common to separate depth/segmentation decoders'
)
self.ap.add_argument(
'--model-depth-min', type=float, default=0.1,
help='Depth Estimates are scaled according to this min/max',
)
self.ap.add_argument(
'--model-depth-max', type=float, default=100.0,
help='Depth Estimates are scaled according to this min/max',
)
self.ap.add_argument(
'--model-depth-resolutions', type=int, default=4, choices=(1, 2, 3, 4),
help='Number of depth resolutions to generate in the network'
)
self.ap.add_argument(
'--experiment-class', type=str, default='sgdepth_eccv_test',
help='A nickname for the experiment folder'
)
self.ap.add_argument(
'--model-name', type=str, default='sgdepth_base',
help='A nickname for this model'
)
self.ap.add_argument(
'--model-load', type=str, default=None,
help='Load a model state from a state directory containing *.pth files'
)
self.ap.add_argument(
'--model-disable-lr-loading', default=False, action='store_true',
help='Do not load the learning rate scheduler if you load a checkpoint'
)
def _harness_init_depth(self):
self.ap.add_argument(
'--depth-validation-resize-height', type=int, default=192,
help='Depth images are resized to this height'
)
self.ap.add_argument(
'--depth-validation-resize-width', type=int, default=640,
help='Depth images are resized to this width'
)
self.ap.add_argument(
'--depth-validation-crop-height', type=int, default=192,
help='Segmentation validation images are cropped to this height'
)
self.ap.add_argument(
'--depth-validation-crop-width', type=int, default=640,
help='Segmentation validation images are cropped to this width'
)
self.ap.add_argument(
'--depth-validation-loaders', type=str, default='kitti_kitti_validation',
help='Comma separated list of depth dataset loaders from loaders/depth.py to use for validation'
)
self.ap.add_argument(
'--depth-validation-batch-size', type=int, default=1,
help='Batch size for depth validation'
)
self.ap.add_argument(
'--depth-validation-fixed-scaling', type=float, default=0,
help='Use this fixed scaling ratio (from another run) for validation outputs'
)
self.ap.add_argument(
'--depth-ratio-on-validation', default=False, action='store_true',
help='Determines the ratios only on the first quarter of the data'
)
def _harness_init_pose(self):
self.ap.add_argument(
'--pose-validation-resize-height', type=int, default=192,
help='Depth images are resized to this height'
)
self.ap.add_argument(
'--pose-validation-resize-width', type=int, default=640,
help='Depth images are resized to this width'
)
self.ap.add_argument(
'--pose-validation-loaders', type=str, default='',
help='Comma separated list of depth dataset loaders from loaders/depth.py to use for validation'
)
self.ap.add_argument(
'--pose-validation-batch-size', type=int, default=1,
help='Batch size for depth validation'
)
self.ap.add_argument(
'--pose-validation-fixed-scaling', type=float, default=0,
help='Use this fixed scaling ratio (from another run) for validation outputs'
)
def _harness_init_segmentation(self):
self.ap.add_argument(
'--segmentation-validation-resize-height', type=int, default=512,
help='Segmentation images are resized to this height prior to cropping'
)
self.ap.add_argument(
'--segmentation-validation-resize-width', type=int, default=1024,
help='Segmentation images are resized to this width prior to cropping'
)
self.ap.add_argument(
'--segmentation-validation-loaders', type=str, default='cityscapes_validation',
help='Comma separated list of segmentation dataset loaders from loaders/segmentation.py to '
'use for validation'
)
self.ap.add_argument(
'--segmentation-validation-batch-size', type=int, default=1,
help='Batch size for segmentation validation'
)
def _training_init_train(self):
self.ap.add_argument(
'--train-batches-per-epoch', type=int, default=DEFAULT_BATCHES_PER_EPOCH,
help='Number of batches we consider an epoch'
)
self.ap.add_argument(
'--train-num-epochs', type=int, default=20,
help='Number of epochs to train for'
)
self.ap.add_argument(
'--train-checkpoint-frequency', type=int, default=5,
help='Number of epochs between model checkpoint dumps'
)
self.ap.add_argument(
'--train-tb-frequency', type=int, default=500,
help='Number of steps between each info dump to tensorboard'
)
self.ap.add_argument(
'--train-print-frequency', type=int, default=2500,
help='Number of steps between each info dump to stdout'
)
self.ap.add_argument(
'--train-learning-rate', type=float, default=1e-4,
help='Initial learning rate to train with',
)
self.ap.add_argument(
'--train-scheduler-step-size', type=int, default=15,
help='Number of epochs between learning rate reductions',
)
self.ap.add_argument(
'--train-weight-decay', type=float, default=0.0,
help='Weight decay to train with',
)
self.ap.add_argument(
'--train-weights-init', type=str, default='pretrained', choices=('pretrained', 'scratch'),
help='Initialize the encoder networks with Imagenet pretrained ResNets oder start from scratch'
)
self.ap.add_argument(
'--train-depth-grad-scale', type=float, default=0.9,
help='How much are depth gradients scaled on their way into the common network parts'
)
self.ap.add_argument(
'--train-segmentation-grad-scale', type=float, default=0.1,
help='How much are segmentation gradients scaled on their way into the common network parts'
)
def _training_init_depth(self):
self.ap.add_argument(
'--depth-training-loaders', type=str, default='kitti_kitti_train',
help='Comma separated list of depth dataset loaders from loaders/depth.py to use for training'
)
self.ap.add_argument(
'--depth-training-batch-size', type=int, default=DEFAULT_DEPTH_BATCH_SIZE,
help='Batch size for depth training'
)
self.ap.add_argument(
'--depth-resize-height', type=int, default=192,
help='Depth images are resized to this height'
)
self.ap.add_argument(
'--depth-resize-width', type=int, default=640,
help='Depth images are resized to this width'
)
self.ap.add_argument(
'--depth-crop-height', type=int, default=192,
help='Segmentation images are cropped to this height'
)
self.ap.add_argument(
'--depth-crop-width', type=int, default=640,
help='Segmentation images are cropped to this width'
)
self.ap.add_argument(
'--depth-disparity-smoothness', type=float, default=1e-3,
help='Scaling factor for the disparity smoothness component of the depth loss'
)
self.ap.add_argument(
'--depth-min-sampling-res', type=int, default=10000,
help='Smallest max(x,y) image dimension at which to multi resolution sampling should '
'continue to downsample. Set this to >= max(--depth-resize-height,--depth-resize-width)'
'to disable multi resolution sampling all together'
)
self.ap.add_argument(
'--depth-avg-reprojection', action='store_true',
help='Use average reprojection loss instead of minimum reprojection loss'
)
self.ap.add_argument(
'--depth-disable-automasking', action='store_true',
help='Disable automasking with the unwarped input frames'
)
def _training_init_segmentation(self):
self.ap.add_argument(
'--segmentation-training-loaders', type=str, default='cityscapes_train',
help='Comma separated list of segmentation dataset loaders from loaders/segmentation.py to use for training'
)
self.ap.add_argument(
'--segmentation-training-batch-size', type=int, default=DEFAULT_SEG_BATCH_SIZE,
help='Batch size for segmentation training'
)
self.ap.add_argument(
'--segmentation-resize-height', type=int, default=512,
help='Segmentation images are resized to this height prior to cropping'
)
self.ap.add_argument(
'--segmentation-resize-width', type=int, default=1024,
help='Segmentation images are resized to this width prior to cropping'
)
self.ap.add_argument(
'--segmentation-crop-height', type=int, default=192,
help='Segmentation images are cropped to this height'
)
self.ap.add_argument(
'--segmentation-crop-width', type=int, default=640,
help='Segmentation images are cropped to this width'
)
def _training_init_masking(self):
self.ap.add_argument(
'--masking-enable', action='store_true',
help='if set uses segmentation mask to mask moving objects'
)
self.ap.add_argument(
'--masking-from-epoch', type=int, default=15,
help='defines at which epoch the mask is applied for the first time'
)
self.ap.add_argument(
'--moving-mask-percent', type=float, default=0.1,
help='Percentage of moving objects with worst iou should be masked, if --linear'
'is set than this will be the percentage at the end of training'
)
self.ap.add_argument(
'--masking-linear-increase', action='store_true',
help='if set first mask out all objects and then increases the percentage of allowed images linear'
)
def _eval_init_logging(self):
self.ap.add_argument(
'--eval-num-images', type=int, default=20,
help='Number of generated images to store to disk'
)
def _inference(self):
self.ap.add_argument(
'--image-path', type=str,
help='Path to image directory'
)
self.ap.add_argument(
'--output-path', type=str,
help='Path to output directory'
)
self.ap.add_argument(
'--model-path', type=str,
help='Path to model.pth'
)
self.ap.add_argument(
'--inference-resize-height', type=int, default=192,
help='Segmentation images are resized to this height'
)
self.ap.add_argument(
'--inference-resize-width', type=int, default=640,
help='Segmentation images are resized to this width'
)
self.ap.add_argument(
'--output-format', type=str, default='.jpg',
help='format the results will be saved in. Everything that OpenCV supports fe.: .jpg or .png'
)
def _parse(self):
return self.ap.parse_args()
class TrainingArguments(ArgumentsBase):
DESCRIPTION = 'SGDepth training arguments'
def __init__(self):
super().__init__()
self._harness_init_system()
self._harness_init_model()
self._harness_init_depth()
self._harness_init_segmentation()
self._training_init_train()
self._training_init_depth()
self._training_init_segmentation()
self._training_init_masking()
def parse(self):
opt = self._parse()
# This option is only useful for evaluation
# but required in the harness
opt.eval_avg_with_flipped = False
return opt
class DepthEvaluationArguments(ArgumentsBase):
DESCRIPTION = 'SGDepth Depth Evaluation'
def __init__(self):
super().__init__()
self._harness_init_system()
self._harness_init_model()
self._harness_init_depth()
self._eval_init_logging()
def parse(self):
opt = self._parse()
# These options are required by the StateManager
# but are effectively ignored when evaluating so
# they can be initialized to arbitrary values
opt.train_learning_rate = 0
opt.train_scheduler_step_size = 1000
opt.train_weight_decay = 0
opt.train_weights_init = 'scratch'
opt.train_depth_grad_scale = 0
opt.train_segmentation_grad_scale = 0
return opt
class SegmentationEvaluationArguments(ArgumentsBase):
DESCRIPTION = 'SGDepth Segmentation Evaluation'
def __init__(self):
super().__init__()
self._harness_init_system()
self._harness_init_model()
self._harness_init_segmentation()
self._eval_init_logging()
def parse(self):
opt = self._parse()
# These options are required by the StateManager
# but are effectively ignored when evaluating so
# they can be initialized to arbitrary values
opt.train_learning_rate = 0
opt.train_scheduler_step_size = 1000
opt.train_weight_decay = 0
opt.train_weights_init = 'scratch'
opt.train_depth_grad_scale = 0
opt.train_segmentation_grad_scale = 0
return opt
class PoseEvaluationArguments(ArgumentsBase):
DESCRIPTION = 'SGDepth Depth Evaluation'
def __init__(self):
super().__init__()
self._harness_init_system()
self._harness_init_model()
self._harness_init_pose()
self._eval_init_logging()
def parse(self):
opt = self._parse()
# These options are required by the StateManager
# but are effectively ignored when evaluating so
# they can be initialized to arbitrary values
opt.train_learning_rate = 0
opt.train_scheduler_step_size = 1000
opt.train_weight_decay = 0
opt.train_weights_init = 'scratch'
opt.train_depth_grad_scale = 0
opt.train_segmentation_grad_scale = 0
return opt
class InferenceEvaluationArguments(ArgumentsBase):
DESCRIPTION = 'SGDepth Segmentation Inference'
def __init__(self):
super().__init__()
self._harness_init_system()
self._harness_init_model()
# self._harness_init_segmentation()
# self._eval_init_logging()
self._inference()
def parse(self):
opt = self._parse()
# These options are required by the StateManager
# but are effectively ignored when evaluating so
# they can be initialized to arbitrary values
opt.train_learning_rate = 0
opt.train_scheduler_step_size = 1000
opt.train_weight_decay = 0
opt.train_weights_init = 'scratch'
opt.train_depth_grad_scale = 0
opt.train_segmentation_grad_scale = 0
return opt