cvg / pixel-perfect-sfm

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

incompatible constructor arguments with KeypointOptimizer #106

Closed Linxius closed 11 months ago

Linxius commented 1 year ago

I got the same error with issue#81 when running the refined, sfm_outputs = sfm.reconstruction(ref_dir, images, sfm_pairs, features, matches, image_list=references) at demo.ipynb,

the code ka.FeatureMetricKeypointOptimizer(optimizer_options,problem_setup, to_ctr(self.conf.interpolation)) results in errors:

  File "/home/lx/code/pixel-perfect-sfm/pixsfm/keypoint_adjustment/main.py", line 178, in refine
    solver = ka.FeatureMetricKeypointOptimizer(
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 0x7f58705c4e70>, {'nodes': [[0.0, 0.0]], 'mode': 'BICUBIC', 'l2_normalize': True, 'ncc_normalize': False, 'use_float_simd': False}

I have tried

import pixsfm

ops = {'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': 2.0, 'num_threads': -1
}
ka_setup = pixsfm.keypoint_adjustment.KeypointAdjustmentSetup()

interp = {'nodes': [[0.0, 0.0]], 'mode': 'BICUBIC', 'l2_normalize': True, 'ncc_normalize': False, 'use_float_simd': False}
pixsfm.keypoint_adjustment.TopologicalReferenceKeypointOptimizer(ops, ka_setup, interp)

and got

>>> pixsfm.keypoint_adjustment.TopologicalReferenceKeypointOptimizer(ops, ka_setup, interp)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:

    1. pixsfm._pixsfm._keypoint_adjustment.TopologicalReferenceKeypointOptimizer(arg0: pixsfm._pixsfm._keypoint_adjustment.TopologicalReferenceKeypointOptimizerOptions, 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': 2.0, 'num_threads': -1}, <pixsfm._pixsfm._keypoint_adjustment.KeypointAdjustmentSetup object at 0x7fe58d9da8b0>, {'nodes': [[0.0, 0.0]], 'mode': 'BICUBIC', 'l2_normalize': True, 'ncc_normalize': False, 'use_float_simd': False}

and

>>> pixsfm._pixsfm._keypoint_adjustment.TopologicalReferenceKeypointOptimizerOptions(ops)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: Unable to convert function return value to a Python type! The signature was

        (self: pixsfm._pixsfm._keypoint_adjustment.KeypointOptimizerOptions) -> ceres::LossFunction

Maybe the bug is in the binding. I have no idea how to solve it or try to make further debug.

ceres-solver, colmap, pycolmap, pyceres, and pixel-perfect-sfm are built from latest commits on Ubuntu 22.04

Phil26AT commented 1 year ago

This indeed seems to be a linking error. As described in issue #81 this might be related to libraries being linked to the wrong ceres library (do you have different versions of ceres installed?). I suggest rebuilding all packages and checking that the correct ceres version is used in each package (printed during CMake). Otherwise, you can send me a docker file of your environment and I can have a look.

Linxius commented 11 months ago

This indeed seems to be a linking error. As described in issue #81 this might be related to libraries being linked to the wrong ceres library (do you have different versions of ceres installed?). I suggest rebuilding all packages and checking that the correct ceres version is used in each package (printed during CMake). Otherwise, you can send me a docker file of your environment and I can have a look.

Thank you for your reply. The 'callbacks' keyword in ka.FeatureMetricKeypointOptimizerOptions cause this issue. When I replace all the to_optim_ctr(self.conf.optimizer, callbacks) with to_ctr(self.conf.optimizer), it works well.