Skip to content

Commit b2ce943

Browse files
committed
isolate argparse creation for all remaining pipeline scripts
1 parent 8b16914 commit b2ce943

6 files changed

+56
-14
lines changed

pipeline/kapture_hloc_pipeline_from_kapture_dataset.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ def hloc_pipeline_from_kapture_dataset(kapture_path_map: str,
254254
run_python_command(local_export_LTVL2020_path, export_LTVL2020_args, python_binary)
255255

256256

257-
def hloc_pipeline_from_kapture_dataset_command_line():
257+
def hloc_pipeline_from_kapture_dataset_get_parser():
258258
"""
259-
Parse the command line arguments to build a colmap map and localize using the given kapture data.
259+
get the argparse object for the kapture_hloc_pipeline_from_kapture_dataset.py command
260260
"""
261261
parser = argparse.ArgumentParser(description=('create a Colmap model (map) from data specified in kapture format.'))
262262
parser_verbosity = parser.add_mutually_exclusive_group()
@@ -325,6 +325,14 @@ def hloc_pipeline_from_kapture_dataset_command_line():
325325
'export_LTVL2020'],
326326
nargs='+', default=[],
327327
help='steps to skip')
328+
return parser
329+
330+
331+
def hloc_pipeline_from_kapture_dataset_command_line():
332+
"""
333+
Parse the command line arguments to build a colmap map and localize using the given kapture data.
334+
"""
335+
parser = hloc_pipeline_from_kapture_dataset_get_parser()
328336
args = parser.parse_args()
329337

330338
logger.setLevel(args.verbose)

pipeline/kapture_pipeline_colmap_vocab_tree.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ def colmap_vocab_tree_pipeline(kapture_map_path: str,
165165
run_python_command(local_export_LTVL2020_path, export_LTVL2020_args, python_binary)
166166

167167

168-
def colmap_vocab_tree_pipeline_command_line():
168+
def colmap_vocab_tree_pipeline_get_parser():
169169
"""
170-
Parse the command line arguments to build a map and localize images using colmap on the given kapture data.
170+
get the argparse object for the kapture_pipeline_colmap_vocab_tree.py command
171171
"""
172172
parser = argparse.ArgumentParser(description='localize images given in kapture format on a colmap map')
173173
parser_verbosity = parser.add_mutually_exclusive_group()
@@ -226,6 +226,14 @@ def colmap_vocab_tree_pipeline_command_line():
226226
'export_LTVL2020'],
227227
nargs='+', default=[],
228228
help='steps to skip')
229+
return parser
230+
231+
232+
def colmap_vocab_tree_pipeline_command_line():
233+
"""
234+
Parse the command line arguments to build a map and localize images using colmap on the given kapture data.
235+
"""
236+
parser = colmap_vocab_tree_pipeline_get_parser()
229237
args = parser.parse_args()
230238

231239
logger.setLevel(args.verbose)

pipeline/kapture_pipeline_image_retrieval_benchmark.py

+3
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ def image_retrieval_benchmark(kapture_map_path: str,
388388

389389

390390
def image_retrieval_benchmark_get_parser():
391+
"""
392+
get the argparse object for the kapture_pipeline_image_retrieval_benchmark.py command
393+
"""
391394
parser = argparse.ArgumentParser(description='run the image retrieval benchmark on kapture data')
392395
parser_verbosity = parser.add_mutually_exclusive_group()
393396
parser_verbosity.add_argument('-v', '--verbose', nargs='?', default=logging.WARNING, const=logging.INFO,

pipeline/kapture_pipeline_image_retrieval_benchmark_from_pairsfile.py

+3
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ def image_retrieval_benchmark_from_pairsfile(kapture_map_path: str,
348348

349349

350350
def image_retrieval_benchmark_from_pairsfile_get_parser():
351+
"""
352+
get the argparse object for the kapture_pipeline_image_retrieval_benchmark_from_pairsfile.py command
353+
"""
351354
parser = argparse.ArgumentParser(description='run the image retrieval benchmark on kapture data')
352355
parser_verbosity = parser.add_mutually_exclusive_group()
353356
parser_verbosity.add_argument('-v', '--verbose', nargs='?', default=logging.WARNING, const=logging.INFO,

pipeline/kapture_pipeline_localize.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import kapture_localization.utils.path_to_kapture # noqa: F401
2323
import kapture.utils.logging
2424
from kapture.utils.paths import safe_remove_file
25+
2526
logger = logging.getLogger('localization_pipeline')
27+
DEFAULT_TOPK = 20
2628

2729

2830
def localize_pipeline(kapture_map_path: str,
@@ -252,9 +254,9 @@ def localize_pipeline(kapture_map_path: str,
252254
run_python_command(local_export_LTVL2020_path, export_LTVL2020_args, python_binary)
253255

254256

255-
def localize_pipeline_command_line():
257+
def localize_pipeline_get_parser():
256258
"""
257-
Parse the command line arguments to localize images on a colmap map using the given kapture data.
259+
get the argparse object for the kapture_pipeline_localize.py command
258260
"""
259261
parser = argparse.ArgumentParser(description='localize images given in kapture format on a colmap map')
260262
parser_verbosity = parser.add_mutually_exclusive_group()
@@ -303,9 +305,8 @@ def localize_pipeline_command_line():
303305
' can infer the python binary from the files itself, shebang or extension).')
304306
parser_python_bin.add_argument('--auto-python-binary', action='store_true', default=False,
305307
help='use sys.executable as python binary.')
306-
default_topk = 20
307308
parser.add_argument('--topk',
308-
default=default_topk,
309+
default=DEFAULT_TOPK,
309310
type=int,
310311
help='the max number of top retained images when computing image pairs from global features')
311312
parser.add_argument('--config', default=1, type=int,
@@ -335,6 +336,14 @@ def localize_pipeline_command_line():
335336
parser.add_argument('--keypoints-type', default=None, help='kapture keypoints type.')
336337
parser.add_argument('--descriptors-type', default=None, help='kapture descriptors type.')
337338
parser.add_argument('--global-features-type', default=None, help='kapture global features type.')
339+
return parser
340+
341+
342+
def localize_pipeline_command_line():
343+
"""
344+
Parse the command line arguments to localize images on a colmap map using the given kapture data.
345+
"""
346+
parser = localize_pipeline_get_parser()
338347
args = parser.parse_args()
339348

340349
logger.setLevel(args.verbose)
@@ -343,7 +352,8 @@ def localize_pipeline_command_line():
343352
kapture.utils.logging.getLogger().setLevel(args.verbose)
344353
kapture_localization.utils.logging.getLogger().setLevel(args.verbose)
345354

346-
if args.pairsfile_path is not None and args.topk != default_topk:
355+
# only show the warning if the user attempted to change the topk value since it'll have no effect
356+
if args.pairsfile_path is not None and args.topk != DEFAULT_TOPK:
347357
logger.warning(f'pairsfile was given explicitely, paramerer topk={args.topk} will be ignored')
348358

349359
args_dict = vars(args)

pipeline/kapture_pipeline_mapping.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import argparse
9+
from ctypes import DEFAULT_MODE
910
import logging
1011
import os
1112
import os.path as path
@@ -23,6 +24,7 @@
2324
from kapture.utils.paths import safe_remove_file
2425

2526
logger = logging.getLogger('mapping_pipeline')
27+
DEFAULT_TOPK = 20
2628

2729

2830
def mapping_pipeline(kapture_path: str,
@@ -144,9 +146,9 @@ def mapping_pipeline(kapture_path: str,
144146
run_python_command(local_build_map_path, build_map_args, python_binary)
145147

146148

147-
def mapping_pipeline_command_line():
149+
def mapping_pipeline_get_parser():
148150
"""
149-
Parse the command line arguments to build a colmap map using the given kapture data.
151+
get the argparse object for the kapture_pipeline_mapping.py command
150152
"""
151153
parser = argparse.ArgumentParser(description=('create a Colmap model (map) from data specified in kapture format.'
152154
'kapture data must contain keypoints, descriptors and '
@@ -190,9 +192,8 @@ def mapping_pipeline_command_line():
190192
' can infer the python binary from the files itself, shebang or extension).')
191193
parser_python_bin.add_argument('--auto-python-binary', action='store_true', default=False,
192194
help='use sys.executable as python binary.')
193-
default_topk = 20
194195
parser.add_argument('--topk',
195-
default=default_topk,
196+
default=DEFAULT_TOPK,
196197
type=int,
197198
help=('the max number of top retained images when computing image pairs from global features'
198199
'ignored if global-features-path is None or pairfile is explicitely given'))
@@ -207,6 +208,14 @@ def mapping_pipeline_command_line():
207208
parser.add_argument('--keypoints-type', default=None, help='kapture keypoints type.')
208209
parser.add_argument('--descriptors-type', default=None, help='kapture descriptors type.')
209210
parser.add_argument('--global-features-type', default=None, help='kapture global features type.')
211+
return parser
212+
213+
214+
def mapping_pipeline_command_line():
215+
"""
216+
Parse the command line arguments to build a colmap map using the given kapture data.
217+
"""
218+
parser = mapping_pipeline_get_parser()
210219
args = parser.parse_args()
211220

212221
logger.setLevel(args.verbose)
@@ -215,7 +224,8 @@ def mapping_pipeline_command_line():
215224
kapture.utils.logging.getLogger().setLevel(args.verbose)
216225
kapture_localization.utils.logging.getLogger().setLevel(args.verbose)
217226

218-
if args.pairsfile_path is not None and args.topk != default_topk:
227+
# only show the warning if the user attempted to change the topk value since it'll have no effect
228+
if args.pairsfile_path is not None and args.topk != DEFAULT_TOPK:
219229
logger.warning(f'pairsfile was given explicitely, paramerer topk={args.topk} will be ignored')
220230

221231
args_dict = vars(args)

0 commit comments

Comments
 (0)