Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ceres GradientChecker and ceres AutoDiffCostFunction #41

Open
xuq9908 opened this issue Feb 25, 2024 · 7 comments
Open

ceres GradientChecker and ceres AutoDiffCostFunction #41

xuq9908 opened this issue Feb 25, 2024 · 7 comments

Comments

@xuq9908
Copy link

xuq9908 commented Feb 25, 2024

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
Copy link
Member

  • GradientChecker is not bound yet but this shouldn't be difficult, you are welcome to contribute it. You would likely need to also bind GradientChecker::ProbeResults and NumericDiffOptions.
  • We don't bind AutoDiffCostFunction because Ceres cannot auto-diff through Python code. It is best to perform the auto-diff on the Python side, e.g. with a deep learning framework like PyTorch.

@colin-de
Copy link

colin-de commented Mar 11, 2024

i saw this from v1.0

return (new ceres::AutoDiffCostFunction<BundleAdjustmentConstantPoseCost<CameraModel>,

so the AutoDiffCostFunction is removed becasue of this?

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

Thanks!

@sarlinpe
Copy link
Member

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
Copy link

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

@sarlinpe
Copy link
Member

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
Copy link

inkyusa commented Jul 26, 2024

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
Copy link
Member

sarlinpe commented Jul 31, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants