-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathconfig.py
441 lines (409 loc) · 14.9 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
# config.py ---
#
# Filename: config.py
# Description: Based on argparse usage from
# https://github.com/carpedm20/DCGAN-tensorflow
# Author: Kwang Moo Yi
# Maintainer:
# Created: Mon Jun 26 11:06:51 2017 (+0200)
# Version:
# Package-Requires: ()
# URL:
# Doc URL:
# Keywords:
# Compatibility:
#
#
# Commentary:
#
#
#
#
# Change Log:
#
#
#
# Code:
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
# -----------------------------------------------------------------------------
# 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_tr", type=str, default="st_peters.brown_bm_3_05", help=""
"name of the dataset for train")
data_arg.add_argument(
"--data_va", type=str, default="st_peters.brown_bm_3_05", help=""
"name of the dataset for valid")
data_arg.add_argument(
"--data_te", type=str, default="st_peters.brown_bm_3_05", 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.")
# -----------------------------------------------------------------------------
# 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_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(
"--sav_res_npy", action='store_true', help=""
"save results as a .npy file when run_mode=test_simple")
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"
)
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