cvg / pyceres

Factor graphs with Ceres in Python
Apache License 2.0
242 stars 34 forks source link

ceres GradientChecker and ceres AutoDiffCostFunction #41

Open xuq9908 opened 8 months ago

xuq9908 commented 8 months ago

Hi,

Does this package bind these 2 functions into python? I failed to find them. if it is not included, is there any replacement methods recommended in python?

Thank you for help!

sarlinpe commented 8 months ago
colin-de commented 7 months ago

i saw this from v1.0 https://github.com/cvg/pyceres/blob/179883ec69b0acff7bb2e96eb22cca9390c1404d/_pyceres/factors/bundle.cc#L80 so the AutoDiffCostFunction is removed becasue of this?

We don't bind AutoDiffCostFunction because Ceres cannot auto-diff through Python code.

Thanks!

sarlinpe commented 7 months ago

An AutoDiffCostFunction needs to be defined in C++ because Ceres cannot differentiate Python code. The code that you link is irrelevant - the implementation of the main cost functions was simply move from pyceres to pycolmap to reduce the dependencies of the core pyceres library.

colin-de commented 7 months ago

And is the geometry of Sophus not going to be suported in Pyceres in the future?

sarlinpe commented 6 months ago

So far we've been relying on the geometry objects available in COLMAP. We could consider adding support for Sophus objects if there is a need for minimal dependencies within pyceres.

inkyusa commented 2 months ago

As @sarlinpe mentioned, it may be useful to use torch's autograd for some cases. Here is a simple example for curve fitting. https://github.com/inkyusa/pyceres/blob/main/examples/test_curve_fitting_torch_autograd.ipynb Hope this help or useful somehow. Cheers,

PS: Haven't tested for a large scale problem (i.e., large parameter block size), maybe using GPU benefical in this case?

sarlinpe commented 2 months ago

Nice, thanks for sharing! For larger problems, you would likely need to pre-compute the forward and backward passes for all residuals and parameters in parallel (e.g. in an evaluation callback) and simply lookup their values in CostFunction.Evaluate. It would be nice to have an example on how to do this.