cvg / pixel-perfect-sfm

Pixel-Perfect Structure-from-Motion with Featuremetric Refinement (ICCV 2021, Best Student Paper Award)
Apache License 2.0
1.34k stars 139 forks source link

incompatible constructor with FeatureMetricKeypointOptimizer #131

Closed Legend94rz closed 4 months ago

Legend94rz commented 11 months ago

I've installed the pixsfm via conda, and trying to triangulate points with know cameras poses. The code is something like:

conf = {"BA": {"optimizer": {
    "refine_focal_length": False,
    "refine_extra_params": False,  # distortion parameters
    "refine_extrinsics": False,    # camera poses
}}}
sfm = PixSfM(conf)
sfm.triangulation(sfm_dir / "pixsfm", sfm_dir / "sparse", image_dir, sfm_pairs, features, matches)

When I run the above code, it will give me the errors:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[9], line 7
      1 conf = {"BA": {"optimizer": {
      2     "refine_focal_length": False,
      3     "refine_extra_params": False,  # distortion parameters
      4     "refine_extrinsics": False,    # camera poses
      5 }}}
      6 sfm = PixSfM(conf)
----> 7 sfm.triangulation(sfm_dir / "pixsfm", sfm_dir / "sparse", image_dir, sfm_pairs, features, matches)

File /opt/conda/envs/pixsfm/lib/python3.11/site-packages/pixsfm/refine_hloc.py:128, in PixSfM.triangulation(self, output_dir, reference_model_path, image_dir, pairs_path, features_path, matches_path, cache_path, feature_manager, **hloc_args)
    117 def triangulation(
    118         self,
    119         output_dir: Path,
   (...)
    126         feature_manager: Optional[FeatureManager] = None,
    127         **hloc_args):
--> 128     return self.run(
    129         output_dir, image_dir, pairs_path, features_path, matches_path,
    130         reference_model_path=reference_model_path, cache_path=cache_path,
    131         feature_manager=feature_manager, **hloc_args)

File /opt/conda/envs/pixsfm/lib/python3.11/site-packages/pixsfm/refine_hloc.py:42, in PixSfM.run(self, output_dir, image_dir, pairs_path, features_path, matches_path, reference_model_path, cache_path, feature_manager, **hloc_args)
     40 if self.conf.KA.apply:
     41     keypoints_path = output_dir / "refined_keypoints.h5"
---> 42     _, ka_data, feature_manager = self.refine_keypoints(
     43             keypoints_path, features_path, image_dir, pairs_path,
     44             matches_path, cache_path=cache_path,
     45             feature_manager=feature_manager)
     46 else:
     47     keypoints_path = features_path

File /opt/conda/envs/pixsfm/lib/python3.11/site-packages/pixsfm/refine_hloc.py:86, in PixSfM.refine_keypoints(self, output_path, features_path, image_dir, pairs_path, matches_path, cache_path, feature_manager)
     84 matches_scores = read_matches_hloc(matches_path, pairs)
     85 cache_path = self.resolve_cache_path(cache_path, output_path.parent)
---> 86 keypoints, ka_data, feature_manager = self.run_ka(
     87         keypoints, image_dir, pairs, matches_scores,
     88         cache_path=cache_path,
     89         feature_manager=feature_manager)
     90 to_hloc_coordinates(keypoints)
     91 write_keypoints_hloc(output_path, keypoints)

File /opt/conda/envs/pixsfm/lib/python3.11/site-packages/pixsfm/refine_colmap.py:77, in PixSfM.run_ka(self, keypoints, image_dir, pairs, matches_scores, cache_path, feature_manager)
     69 if feature_manager is None:
     70     feature_manager = extract.features_from_graph(
     71         self.extractor,
     72         image_dir,
   (...)
     75         cache_path=cache_path
     76     )
---> 77 ka_data = self.keypoint_adjuster.refine_multilevel(
     78         keypoints, feature_manager, graph)
     79 del graph
     80 return keypoints, ka_data, feature_manager

File /opt/conda/envs/pixsfm/lib/python3.11/site-packages/pixsfm/keypoint_adjustment/main.py:127, in KeypointAdjuster.refine_multilevel(self, keypoints_dict, feature_manager, graph, track_labels, root_labels, problem_setup)
    125 outputs = {}
    126 for level_index in levels:
--> 127     out = self.refine(keypoints_dict,
    128                       feature_manager.fset(level_index),
    129                       graph, track_labels, root_labels,
    130                       problem_setup=problem_setup)
    131     for k, v in out.items():
    132         if k in outputs.keys():

File /opt/conda/envs/pixsfm/lib/python3.11/site-packages/pixsfm/keypoint_adjustment/main.py:178, in FeatureMetricKeypointAdjuster.refine(self, keypoints_dict, feature_set, graph, track_labels, root_labels, problem_setup)
    176     problem_setup = ka.KeypointAdjustmentSetup()
    177     problem_setup.set_masked_nodes_constant(graph, root_labels)
--> 178 solver = ka.FeatureMetricKeypointOptimizer(
    179             to_optim_ctr(self.conf.optimizer, self.callbacks),
    180             problem_setup,
    181             to_ctr(self.conf.interpolation))
    183 if self.conf.split_in_subproblems:
    184     # Split problem in indepent chunks
    185     # nodes with same labels are optimized together
    186     problem_labels, _ = find_problem_labels(
    187                                 track_labels,
    188                                 self.conf.max_kps_per_problem)

TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. pixsfm._pixsfm._keypoint_adjustment.FeatureMetricKeypointOptimizer(arg0: pixsfm._pixsfm._keypoint_adjustment.FeatureMetricKeypointOptimizerOptions, arg1: pixsfm._pixsfm._keypoint_adjustment.KeypointAdjustmentSetup, arg2: pixsfm._pixsfm._base.InterpolationConfig)

Invoked with: {'loss': {'name': 'cauchy', 'params': [0.25]}, 'solver': {'function_tolerance': 0.0, 'gradient_tolerance': 0.0, 'parameter_tolerance': 1e-05, 'minimizer_progress_to_stdout': False, 'max_num_iterations': 100, 'max_linear_solver_iterations': 200, 'max_num_consecutive_invalid_steps': 10, 'max_consecutive_nonmonotonic_steps': 10, 'use_inner_iterations': False, 'use_nonmonotonic_steps': False, 'update_state_every_iteration': False, 'num_threads': 1, 'callbacks': []}, 'print_summary': False, 'bound': 4.0, 'num_threads': -1, 'root_regularize_weight': -1, 'weight_by_sim': True, 'root_edges_only': False}, <pixsfm._pixsfm._keypoint_adjustment.KeypointAdjustmentSetup object at 0x7f4616f37930>, {'nodes': [[0.0, 0.0]], 'mode': 'BICUBIC', 'l2_normalize': True, 'ncc_normalize': False, 'use_float_simd': False}

It seems like the init of FeatureMetricKeypointOptimizer requires (FeatureMetricKeypointOptimizerOptions, KeypointAdjustmentSetup, InterpolationConfig), but it was passed: (dict, KeypointAdjustmentSetup, dict).

How to solve it? I've tried https://github.com/cvg/pixel-perfect-sfm/issues/106#issuecomment-1628612535, but it doesn't work for me.

Here are some packages I installed:

ceres-solver              2.2.0                h2ea6fbf_1    conda-forge
colmap                    3.8             gpuhde9e9d0_110    conda-forge
hloc                      1.4                pyhd8ed1ab_0    conda-forge
pixsfm                    1.0.0           gpuh198f6bf_105    conda-forge
pyceres                   1.0             py311ha9c6872_6    conda-forge
pycolmap                  0.4.0           cuda112py311hb8d6633_6    conda-forge
karthik101200 commented 4 months ago

i have the error. did you manage to solve it?

Legend94rz commented 4 months ago

@karthik101200 sorry, I don't remember.. maybe some packages installed from conda-forge is broken at that time. You could try to install packages via pypi (or the newest packages from conda-forge)