Skip to content

Commit 0b0e924

Browse files
committed
pass use_pba to mapper to use GPU
1 parent a45dee5 commit 0b0e924

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

hloc/reconstruction.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@ def get_image_ids(database_path):
4141
return images
4242

4343

44-
def run_reconstruction(sfm_dir, database_path, image_dir, verbose=False):
44+
def run_reconstruction(sfm_dir, database_path, image_dir, use_pba=False, verbose=False):
4545
models_path = sfm_dir / 'models'
4646
models_path.mkdir(exist_ok=True, parents=True)
4747
logger.info('Running 3D reconstruction...')
4848
with OutputCapture(verbose):
4949
with pycolmap.ostream():
50+
opt = pycolmap.IncrementalMapperOptions()
51+
opt.num_threads = min(multiprocessing.cpu_count(), 16)
52+
if use_pba:
53+
opt.ba_global_use_pba = True
5054
reconstructions = pycolmap.incremental_mapping(
5155
database_path, image_dir, models_path,
52-
num_threads=min(multiprocessing.cpu_count(), 16))
56+
opt)
5357

5458
if len(reconstructions) == 0:
5559
logger.error('Could not reconstruct any model!')
@@ -76,7 +80,7 @@ def run_reconstruction(sfm_dir, database_path, image_dir, verbose=False):
7680

7781

7882
def main(sfm_dir, image_dir, pairs, features, matches,
79-
camera_mode=pycolmap.CameraMode.AUTO, verbose=False,
83+
camera_mode=pycolmap.CameraMode.AUTO, verbose=False, use_pba=False,
8084
skip_geometric_verification=False, min_match_score=None,
8185
image_list: Optional[List[str]] = None):
8286

@@ -95,7 +99,7 @@ def main(sfm_dir, image_dir, pairs, features, matches,
9599
min_match_score, skip_geometric_verification)
96100
if not skip_geometric_verification:
97101
geometric_verification(database, pairs, verbose)
98-
reconstruction = run_reconstruction(sfm_dir, database, image_dir, verbose)
102+
reconstruction = run_reconstruction(sfm_dir, database, image_dir, use_pba, verbose)
99103
if reconstruction is not None:
100104
logger.info(f'Reconstruction statistics:\n{reconstruction.summary()}'
101105
+ f'\n\tnum_input_images = {len(image_ids)}')
@@ -116,6 +120,7 @@ def main(sfm_dir, image_dir, pairs, features, matches,
116120
parser.add_argument('--skip_geometric_verification', action='store_true')
117121
parser.add_argument('--min_match_score', type=float)
118122
parser.add_argument('--verbose', action='store_true')
123+
parser.add_argument('--use_pba', action='store_true')
119124
args = parser.parse_args()
120125

121126
main(**args.__dict__)

0 commit comments

Comments
 (0)