pyceres
pyceres copied to clipboard
ceres GradientChecker and ceres AutoDiffCostFunction
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!
-
GradientChecker
is not bound yet but this shouldn't be difficult, you are welcome to contribute it. You would likely need to also bindGradientChecker::ProbeResults
andNumericDiffOptions
. - 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.
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!
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.
And is the geometry of Sophus not going to be suported in Pyceres in the future?
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.
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?
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.