-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconfig.py
executable file
·556 lines (516 loc) · 19.4 KB
/
config.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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# Filename: config.py
# License: LICENSES/LICENSE_UVIC_EPFL
import argparse
from servers import is_computecanada, is_cvlab_epfl, is_vcg_uvic
def str2bool(v):
return v.lower() in ("true", "1")
arg_lists = []
parser = argparse.ArgumentParser()
def add_argument_group(name):
arg = parser.add_argument_group(name)
arg_lists.append(arg)
return arg
# -----------------------------------------------------------------------------
# NeighNet
neigh_arg = add_argument_group("NeighNet")
neigh_arg.add_argument(
"--num_inner", type=int, default=2, help=""
"num of inner block in each residual block")
neigh_arg.add_argument(
"--num_acn_inner", type=int, default=1, help=""
"num of acn in each inner block")
neigh_arg.add_argument(
"--use_fundamental", type=int, default=0, help=""
"0: essential matrix case, 1: fundamental under image-size norm")
neigh_arg.add_argument(
"--prefiltering", type=str, default="", help=""
"do prefiltering on dataset")
neigh_arg.add_argument(
"--save_test_dir", type=str, default="", help=""
"save test dir")
neigh_arg.add_argument(
"--F_th", type=float, default=-1, help=""
"threshold")
neigh_arg.add_argument(
"--E_th", type=float, default=-1, help=""
"threshold")
neigh_arg.add_argument(
"--bool_hard_attention", type=str2bool, default=False, help=""
"button to trun on the hard attention"
)
neigh_arg.add_argument(
"--matching_crossCheck", type=str2bool, default=False, help=""
"whether do the cross check when dumping the data"
)
neigh_arg.add_argument(
"--bool_use_weight_for_score", type=str2bool, default=False, help=""
"button to trun on the hard attention"
)
neigh_arg.add_argument(
"--nonlinearity_output", type=str2bool, default=False, help=""
"whether add linearity output before sigmoid")
neigh_arg.add_argument(
"--ratio_test", type=float, default=None, help=""
"do ratio test during feature matching")
neigh_arg.add_argument(
"--sigma", type=float, default=1.0, help=""
"number of layers")
neigh_arg.add_argument(
"--loss_gaussian_sigma", type=float, default=1.0, help=""
"number of layers")
neigh_arg.add_argument(
"--loss_var", type=float, default=0.0, help=""
"number of layers")
neigh_arg.add_argument(
"--loss_multi_logit", type=float, default=0.0, help=""
"number of layers")
neigh_arg.add_argument(
"--loss_multi_logit_ada", type=float, default=0.0, help=""
"number of layers")
neigh_arg.add_argument(
"--loss_multi_logit_aux", type=float, default=0.0, help=""
"number of layers")
neigh_arg.add_argument(
"--loss_hinge", type=float, default=0.0, help=""
"number of layers")
neigh_arg.add_argument(
"--th_logit", type=float, default=0.0, help=""
"threshold for logit")
neigh_arg.add_argument(
"--loss_err", type=float, default=0.0, help=""
"number of layers")
neigh_arg.add_argument(
"--loss_attention", type=float, default=0.0, help=""
"number of layers")
neigh_arg.add_argument(
"--loss_inner", type=float, default=0.0, help=""
"number of layers")
neigh_arg.add_argument(
"--n_group", type=int, default=1, help=""
"number of groups")
neigh_arg.add_argument(
"--num_phase", type=int, default=1, help=""
"number of groups")
neigh_arg.add_argument(
"--gcn_opt", type=str, default="vanilla", help=""
"where the activation should be in case of resnet")
neigh_arg.add_argument(
"--bn_opt", type=str, default="bn", help=""
"where the activation should be in case of resnet")
neigh_arg.add_argument(
"--divergence_opt", type=str, default="cross_entropy", help=""
"where the activation should be in case of resnet")
neigh_arg.add_argument(
"--weight_opt", type=str, default="relu_tanh", help=""
"where the activation should be in case of resnet")
neigh_arg.add_argument(
"--gcn_pos", type=str, default="pre", help=""
"where the activation should be in case of resnet")
neigh_arg.add_argument(
"--w_opt", type=str, default=None,
choices=["none", None, "l2", "l2_sigma", "9w"], help=""
"where the activation should be in case of resnet")
neigh_arg.add_argument(
"--kernel_size", type=float, default=0.0, help=""
"kernel_size for the 9w strategy")
neigh_arg.add_argument(
"--pre_x_in", type=str, default="4",
choices=["4", "3", "9"], help=""
"Different choice for the input")
neigh_arg.add_argument(
"--var_mode", type=str, default="division", help=""
"Different choice for the input")
neigh_arg.add_argument(
"--mean_mode", type=str, default="1", help=""
"calculate the mean value for the gcn layer")
# -----------------------------------------------------------------------------
# Network
net_arg = add_argument_group("Network")
net_arg.add_argument(
"--net_depth", type=int, default=12, help=""
"number of layers")
net_arg.add_argument(
"--net_nchannel", type=int, default=128, help=""
"number of channels in a layer")
net_arg.add_argument(
"--net_act_pos", type=str, default="post",
choices=["pre", "mid", "post"], help=""
"where the activation should be in case of resnet")
net_arg.add_argument(
"--net_gcnorm", type=str2bool, default=True, help=""
"whether to use context normalization for each layer")
net_arg.add_argument(
"--net_batchnorm", type=str2bool, default=True, help=""
"whether to use batch normalization")
net_arg.add_argument(
"--net_bn_test_is_training", type=str2bool, default=False, help=""
"is_training value for testing")
# -----------------------------------------------------------------------------
# Data
data_arg = add_argument_group("Data")
data_arg.add_argument(
"--data_dump_prefix", type=str, default="./data_dump", help=""
"prefix for the dump folder locations")
data_arg.add_argument(
"--data_name", type=str, default="cne", help=""
"prefix for the dump folder locations")
data_arg.add_argument(
"--data_tr", type=str, default="st_peters", help=""
"name of the dataset for train")
data_arg.add_argument(
"--data_va", type=str, default="st_peters", help=""
"name of the dataset for valid")
data_arg.add_argument(
"--data_te", type=str, default="st_peters", help=""
"name of the dataset for test")
data_arg.add_argument(
"--data_crop_center", type=str2bool, default=False, help=""
"whether to crop center of the image "
"to match the expected input for methods that expect a square input")
data_arg.add_argument(
"--use_lift", type=str2bool, default=False, help=""
"if this is set to true, we expect lift to be dumped already for all "
"images.")
data_arg.add_argument(
"--use_lfnet", type=str2bool, default=False, help=""
"if this is set to true, we expect lift to be dumped already for all "
"images.")
data_arg.add_argument(
"--use_sp", type=str2bool, default=False, help=""
"if this is set to true, we expect lift to be dumped already for all "
"images.")
# -----------------------------------------------------------------------------
# Objective
obj_arg = add_argument_group("obj")
obj_arg.add_argument(
"--obj_num_kp", type=int, default=2000, help=""
"number of keypoints per image")
obj_arg.add_argument(
"--obj_top_k", type=int, default=-1, help=""
"number of keypoints above the threshold to use for "
"essential matrix estimation. put -1 to use all. ")
obj_arg.add_argument(
"--obj_num_nn", type=int, default=1, help=""
"number of nearest neighbors in terms of descriptor "
"distance that are considered when generating the "
"distance matrix")
obj_arg.add_argument(
"--obj_geod_type", type=str, default="episym",
choices=["sampson", "episqr", "episym"], help=""
"type of geodesic distance")
obj_arg.add_argument(
"--obj_geod_th", type=float, default=1e-4, help=""
"theshold for the good geodesic distance")
# -----------------------------------------------------------------------------
# Loss
loss_arg = add_argument_group("loss")
loss_arg.add_argument(
"--loss_decay", type=float, default=0.0, help=""
"l2 decay")
loss_arg.add_argument(
"--loss_EM", type=float, default=0.0, help=""
"Use EM loss")
loss_arg.add_argument(
"--loss_gaussian", type=float, default=0.0, help=""
"Use EM loss")
loss_arg.add_argument(
"--loss_classif", type=float, default=1.0, help=""
"weight of the classification loss")
loss_arg.add_argument(
"--loss_essential", type=float, default=0.1, help=""
"weight of the essential loss")
loss_arg.add_argument(
"--loss_essential_init_iter", type=int, default=20000, help=""
"initial iterations to run only the classification loss")
# -----------------------------------------------------------------------------
# Training
train_arg = add_argument_group("Train")
train_arg.add_argument(
"--run_mode", type=str, default="train", help=""
"run_mode")
train_arg.add_argument(
"--train_batch_size", type=int, default=32, help=""
"batch size")
train_arg.add_argument(
"--train_max_tr_sample", type=int, default=10000, help=""
"number of max training samples")
train_arg.add_argument(
"--train_max_va_sample", type=int, default=1000, help=""
"number of max validation samples")
train_arg.add_argument(
"--train_max_te_sample", type=int, default=1000, help=""
"number of max test samples")
train_arg.add_argument(
"--train_lr", type=float, default=1e-3, help=""
"learning rate")
train_arg.add_argument(
"--train_iter", type=int, default=500000, help=""
"training iterations to perform")
train_arg.add_argument(
"--res_dir", type=str, default="./logs", help=""
"base directory for results")
train_arg.add_argument(
"--log_dir", type=str, default="", help=""
"save directory name inside results")
train_arg.add_argument(
"--test_log_dir", type=str, default="", help=""
"which directory to test inside results")
train_arg.add_argument(
"--val_intv", type=int, default=5000, help=""
"validation interval")
train_arg.add_argument(
"--report_intv", type=int, default=1000, help=""
"summary interval")
# -----------------------------------------------------------------------------
# Visualization
vis_arg = add_argument_group('Visualization')
vis_arg.add_argument(
"--vis_dump", type=str2bool, default=False, help=""
"turn this on to dump data for visualization"
)
vis_arg.add_argument(
"--tqdm_width", type=int, default=79, help=""
"width of the tqdm bar"
)
vis_arg.add_argument(
"--vis_dir", type=str, default="", help=""
"vis is not none, then dump mask_before into vis_dir"
)
def setup_dataset(dataset_name):
"""Expands dataset name and directories properly"""
# Use only the first one for dump
dataset_name = dataset_name.split(".")[0]
# Setup the base directory depending on the environment
if is_computecanada():
data_dir = "/scratch/kyi/datasets/scenedata_splits/"
elif is_vcg_uvic():
data_dir = "/data/datasets/sfm/scenedata_splits/"
elif is_cvlab_epfl():
data_dir = "/cvlabdata2/home/kyi/Datasets/scenedata_splits/"
else:
data_dir = "./datasets/"
# Expand the abbreviations that we use to actual folder names
if "cogsci4" == dataset_name:
# Load the data
data_dir += "brown_cogsci_4---brown_cogsci_4---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.3
elif "reichstag" == dataset_name:
# Load the data
data_dir += "reichstag/"
geom_type = "Calibration"
vis_th = 100
elif "sacre_coeur" == dataset_name:
# Load the data
data_dir += "sacre_coeur/"
geom_type = "Calibration"
vis_th = 100
elif "buckingham" in dataset_name:
# Load the data
data_dir += "buckingham_palace/"
geom_type = "Calibration"
vis_th = 100
elif "notre_dame" == dataset_name:
# Load the data
data_dir += "notre_dame_front_facade/"
geom_type = "Calibration"
vis_th = 100
elif "st_peters" == dataset_name:
# Load the data
data_dir += "st_peters_square/"
geom_type = "Calibration"
vis_th = 100
elif "harvard_conf_big" == dataset_name:
# Load the data
data_dir += "harvard_conf_big---hv_conf_big_1---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.3
elif "home_ac" == dataset_name:
# Load the data
data_dir += "home_ac---home_ac_scan1_2012_aug_22---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.3
elif "fountain" in dataset_name:
# Load the data
data_dir += "fountain/"
geom_type = "Calibration"
vis_th = -1
elif "herzjesu" == dataset_name:
# Load the data
data_dir += "herzjesu/"
geom_type = "Calibration"
vis_th = -1
elif "gms-teddy" == dataset_name:
# Load the data
data_dir += "gms-teddy/"
geom_type = "Calibration"
vis_th = 100
elif "gms-large-cabinet" in dataset_name:
# Load the data
data_dir += "gms-large-cabinet/"
geom_type = "Calibration"
vis_th = 100
elif "cogsci8_05" == dataset_name:
# Load the data
data_dir += "brown_cogsci_8---brown_cogsci_8---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "cogsci2_05" == dataset_name:
# Load the data
data_dir += "brown_cogsci_2---brown_cogsci_2---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hv_lounge1_2_05" == dataset_name:
# Load the data
data_dir += "harvard_corridor_lounge---hv_lounge1_2---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hv_c10_2_05" == dataset_name:
# Load the data
data_dir += "harvard_c10---hv_c10_2---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hv_s1_2_05" == dataset_name:
# Load the data
data_dir += "harvard_robotics_lab---hv_s1_2---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hv_c4_1_05" == dataset_name:
# Load the data
data_dir += "harvard_c4---hv_c4_1---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "cs7_05" == dataset_name:
# Load the data
data_dir += "brown_cs_7---brown_cs7---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "cs3_05" == dataset_name:
# Load the data
data_dir += "brown_cs_3---brown_cs3---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "mit_46_6conf_05" == dataset_name:
# Load the data
data_dir += "mit_46_6conf---bcs_floor6_conf_1---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "mit_46_6lounge_05" == dataset_name:
# Load the data
data_dir += "mit_46_6lounge---bcs_floor6_long---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "mit_w85g_05" == dataset_name:
# Load the data
data_dir += "mit_w85g---g_0---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "mit_32_g725_05" == dataset_name:
# Load the data
data_dir += "mit_32_g725---g725_1---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "florence_hotel_05" == dataset_name:
# Load the data
data_dir += "hotel_florence_jx---florence_hotel_stair_room_all---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "mit_w85h_05" == dataset_name:
# Load the data
data_dir += "mit_w85h---h2_1---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "cogsci6_05" == dataset_name:
# Load the data
data_dir += "brown_cogsci_6---brown_cogsci_6---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
# New sets
elif "home_ac_05_fix" == dataset_name:
# Load the data
data_dir += "home_ac---home_ac_scan1_2012_aug_22---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "harvard_conf_big_05_fix" == dataset_name:
# Load the data
data_dir += "harvard_conf_big---hv_conf_big_1---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "cogsci3_05" == dataset_name:
# Load the data
data_dir += "brown_cogsci_3---brown_cogsci_3---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "cogsci4_05_fix" == dataset_name:
# Load the data
data_dir += "brown_cogsci_4---brown_cogsci_4---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "home_aca_05_fix" == dataset_name:
# Load the data
data_dir += "home_ag---apartment_ag_nov_7_2012_scan1_erika---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hotel_ucsd_05" == dataset_name:
# Load the data
data_dir += "hotel_ucsd---la2-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "brown_cs_4_05" == dataset_name:
data_dir += "brown_cs_4---brown_cs4-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hotel_ucla_ant_05" == dataset_name:
# Load the data
data_dir += "hotel_ucla_ant---hotel_room_ucla_scan1_2012_oct_05-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hv_lounge3_05" == dataset_name:
data_dir += "harvard_corridor_lounge---hv_lounge_corridor3_whole_floor-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "harvard_conf_big_05_rand" == dataset_name:
# Load the data
data_dir += "harvard_conf_big---hv_conf_big_1-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "brown_bm_3_05" == dataset_name:
# Load the data
data_dir += "brown_bm_3---brown_bm_3-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "home_pt_05" == dataset_name:
# Load the data
data_dir += "home_pt---home_pt_scan1_2012_oct_19-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hv_comp_05" == dataset_name:
# Load the data
data_dir += "harvard_computer_lab---hv_c1_1-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hv_lounge2_05" == dataset_name:
# Load the data
data_dir += "harvard_corridor_lounge---hv_lounge_corridor2_1-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
elif "hotel_ped_05" == dataset_name:
# Load the data
data_dir += "hotel_pedraza---hotel_room_pedraza_2012_nov_25-maxpairs-10000-random---skip-10-dilate-25/"
geom_type = "Calibration"
vis_th = 0.5
return data_dir, geom_type, vis_th
def get_config():
config, unparsed = parser.parse_known_args()
# Setup the dataset related things
for _mode in ["tr", "va", "te"]:
data_dir, geom_type, vis_th = setup_dataset(
getattr(config, "data_" + _mode))
setattr(config, "data_dir_" + _mode, data_dir)
setattr(config, "data_geom_type_" + _mode, geom_type)
setattr(config, "data_vis_th_" + _mode, vis_th)
return config, unparsed
def print_usage():
parser.print_usage()
#
# config.py ends here