Skip to content

Commit c9eb9fb

Browse files
authored
[BREAKING] Move the COLMAP .bin files to the top level SfM directory (#76)
* Move the COLMAP .bin files to the top level SfM directory * Update the notebooks * Propagate the changes to the new pipelines * Remove the Aachen v1.1 notebook again
1 parent 288cd65 commit c9eb9fb

File tree

12 files changed

+34
-35
lines changed

12 files changed

+34
-35
lines changed

hloc/pipelines/4Seasons/localize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
ffile = extract_features.main(fconf, seq_images, output_dir)
6464
mfile = match_features.main(mconf, loc_pairs, fconf['output'], output_dir)
6565
localize_sfm.main(
66-
ref_sfm / 'model', query_list, loc_pairs, ffile, mfile, results_path)
66+
ref_sfm, query_list, loc_pairs, ffile, mfile, results_path)
6767

6868
# Convert the absolute poses to relative poses with the reference frames.
6969
submission_dir.mkdir(exist_ok=True)

hloc/pipelines/7Scenes/create_gt_sfm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def correct_sfm_with_gt_depth(sfm_path, depth_folder_path, output_path):
120120
outputs = Path('outputs/7Scenes')
121121

122122
for scene in SCENES:
123-
sfm_path = outputs / scene / 'sfm_superpoint+superglue/model'
123+
sfm_path = outputs / scene / 'sfm_superpoint+superglue'
124124
depth_path = dataset / f'depth/7scenes_{scene}/train/depth'
125-
output_path = outputs / scene / 'sfm_superpoint+superglue+depth/model'
125+
output_path = outputs / scene / 'sfm_superpoint+superglue+depth'
126126
correct_sfm_with_gt_depth(sfm_path, depth_path, output_path)

hloc/pipelines/7Scenes/pipeline.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ def run_scene(images, gt_dir, retrieval, outputs, results, num_covis,
5656
if use_dense_depth:
5757
assert depth_dir is not None
5858
ref_sfm_fix = outputs / 'sfm_superpoint+superglue+depth'
59-
correct_sfm_with_gt_depth(
60-
ref_sfm / 'model', depth_dir, ref_sfm_fix / 'model')
59+
correct_sfm_with_gt_depth(ref_sfm, depth_dir, ref_sfm_fix)
6160
ref_sfm = ref_sfm_fix
6261

6362
loc_matches = match_features.main(
6463
matcher_conf, retrieval, feature_conf['output'], outputs)
6564

6665
localize_sfm.main(
67-
ref_sfm / 'model',
66+
ref_sfm,
6867
query_list,
6968
retrieval,
7069
features,

hloc/pipelines/Aachen/pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@
6262
global_descriptors = extract_features.main(retrieval_conf, images, outputs)
6363
pairs_from_retrieval.main(
6464
global_descriptors, loc_pairs, args.num_loc,
65-
query_prefix='query', db_model=reference_sfm / 'model')
65+
query_prefix='query', db_model=reference_sfm)
6666
loc_matches = match_features.main(
6767
matcher_conf, loc_pairs, feature_conf['output'], outputs)
6868

6969
localize_sfm.main(
70-
reference_sfm / 'model',
70+
reference_sfm,
7171
dataset / 'queries/*_time_queries_with_intrinsics.txt',
7272
loc_pairs,
7373
features,

hloc/pipelines/Aachen_v1_1/pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@
5656
global_descriptors = extract_features.main(retrieval_conf, images, outputs)
5757
pairs_from_retrieval.main(
5858
global_descriptors, loc_pairs, args.num_loc,
59-
query_prefix='query', db_model=reference_sfm / 'model')
59+
query_prefix='query', db_model=reference_sfm)
6060
loc_matches = match_features.main(
6161
matcher_conf, loc_pairs, feature_conf['output'], outputs)
6262

6363
localize_sfm.main(
64-
reference_sfm / 'model',
64+
reference_sfm,
6565
dataset / 'queries/*_time_queries_with_intrinsics.txt',
6666
loc_pairs,
6767
features,

hloc/pipelines/CMU/pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ def run_slice(slice_, root, outputs, num_covis, num_loc):
6666
retrieval_conf, query_images, outputs)
6767
pairs_from_retrieval.main(
6868
global_descriptors, loc_pairs, num_loc,
69-
query_list=query_list, db_model=ref_sfm / 'model')
69+
query_list=query_list, db_model=ref_sfm)
7070

7171
features = extract_features.main(
7272
feature_conf, query_images, outputs, as_half=True)
7373
loc_matches = match_features.main(
7474
matcher_conf, loc_pairs, feature_conf['output'], outputs)
7575

7676
localize_sfm.main(
77-
ref_sfm / 'model',
77+
ref_sfm,
7878
dataset / 'queries/*_time_queries_with_intrinsics.txt',
7979
loc_pairs,
8080
features,

hloc/pipelines/Cambridge/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run_scene(images, gt_dir, outputs, results, num_covis, num_loc):
6868
matcher_conf, loc_pairs, feature_conf['output'], outputs)
6969

7070
localize_sfm.main(
71-
ref_sfm / 'model',
71+
ref_sfm,
7272
query_list,
7373
loc_pairs,
7474
features,

hloc/pipelines/RobotCar/pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ def generate_query_list(dataset, image_dir, path):
9191
# TODO: do per location and per camera
9292
pairs_from_retrieval.main(
9393
global_descriptors, loc_pairs, args.num_loc,
94-
query_prefix='query', db_model=reference_sfm / 'model')
94+
query_prefix='query', db_model=reference_sfm)
9595
loc_matches = match_features.main(
9696
matcher_conf, loc_pairs, feature_conf['output'], outputs)
9797

9898
localize_sfm.main(
99-
reference_sfm / 'model',
99+
reference_sfm,
100100
Path(str(query_list).format(condition='*')),
101101
loc_pairs,
102102
features,

hloc/reconstruction.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,24 @@ def get_image_ids(database_path):
6060
return images
6161

6262

63-
def run_reconstruction(colmap_path, model_path, database_path, image_dir,
63+
def run_reconstruction(colmap_path, sfm_dir, database_path, image_dir,
6464
min_num_matches=None):
6565
logging.info('Running the 3D reconstruction...')
66-
model_path.mkdir(exist_ok=True)
66+
models_path = sfm_dir / 'models'
67+
models_path.mkdir(exist_ok=True, parents=True)
6768

6869
cmd = [
6970
str(colmap_path), 'mapper',
7071
'--database_path', str(database_path),
7172
'--image_path', str(image_dir),
72-
'--output_path', str(model_path),
73+
'--output_path', str(models_path),
7374
'--Mapper.num_threads', str(min(multiprocessing.cpu_count(), 16))]
7475
if min_num_matches:
7576
cmd += ['--Mapper.min_num_matches', str(min_num_matches)]
7677
logging.info(' '.join(cmd))
7778
subprocess.run(cmd, check=True)
7879

79-
models = list(model_path.iterdir())
80+
models = list(models_path.iterdir())
8081
if len(models) == 0:
8182
logging.error('Could not reconstruct any model!')
8283
return False
@@ -91,7 +92,7 @@ def run_reconstruction(colmap_path, model_path, database_path, image_dir,
9192
largest_model_num_images = num_images
9293
assert largest_model_num_images > 0
9394
logging.info(f'Largest model is #{largest_model.name} '
94-
'with {largest_model_num_images} images.')
95+
f'with {largest_model_num_images} images.')
9596

9697
stats_raw = subprocess.check_output(
9798
[str(colmap_path), 'model_analyzer',
@@ -112,6 +113,9 @@ def run_reconstruction(colmap_path, model_path, database_path, image_dir,
112113
elif stat.startswith("Mean reprojection error"):
113114
stats['mean_reproj_error'] = float(stat.split()[-1][:-2])
114115

116+
for filename in ['images.bin', 'cameras.bin', 'points3D.bin']:
117+
shutil.move(str(largest_model / filename), str(sfm_dir))
118+
115119
return stats
116120

117121

@@ -126,8 +130,6 @@ def main(sfm_dir, image_dir, pairs, features, matches,
126130

127131
sfm_dir.mkdir(parents=True, exist_ok=True)
128132
database = sfm_dir / 'database.db'
129-
models = sfm_dir / 'models'
130-
models.mkdir(exist_ok=True)
131133

132134
create_empty_db(database)
133135
import_images(
@@ -139,7 +141,7 @@ def main(sfm_dir, image_dir, pairs, features, matches,
139141
if not skip_geometric_verification:
140142
geometric_verification(colmap_path, database, pairs)
141143
stats = run_reconstruction(
142-
colmap_path, models, database, image_dir, min_num_matches)
144+
colmap_path, sfm_dir, database, image_dir, min_num_matches)
143145
stats['num_input_images'] = len(image_ids)
144146
logging.info(f'Statistics:\n{pprint.pformat(stats)}')
145147

hloc/triangulation.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ def main(sfm_dir, reference_sfm_model, image_dir, pairs, features, matches,
168168

169169
sfm_dir.mkdir(parents=True, exist_ok=True)
170170
database = sfm_dir / 'database.db'
171-
model = sfm_dir / 'model'
172-
model.mkdir(exist_ok=True)
173171
empty_model = sfm_dir / 'empty'
174172

175173
create_empty_model(reference_sfm_model, empty_model)
@@ -180,7 +178,7 @@ def main(sfm_dir, reference_sfm_model, image_dir, pairs, features, matches,
180178
if not skip_geometric_verification:
181179
geometric_verification(colmap_path, database, pairs)
182180
stats = run_triangulation(
183-
colmap_path, model, database, image_dir, empty_model)
181+
colmap_path, sfm_dir, database, image_dir, empty_model)
184182

185183
logging.info(f'Statistics:\n{pprint.pformat(stats)}')
186184
shutil.rmtree(empty_model)

0 commit comments

Comments
 (0)