EvaluationCallback with AutoDiffCostFunction?

41 views
Skip to first unread message

Young Ho Shin

unread,
May 13, 2024, 12:54:44 AMMay 13
to Ceres Solver
Hello all,

Is it possible to use the EvaluationCallback interface to share computation between AutoDiffCostFunction objects? I'm a bit lost as to how one would adapt evaluation_callback_example.cc to do this. I would greatly appreciate some guidance or a minimal example on how one might approach this.

Thanks!

Sameer Agarwal

unread,
May 13, 2024, 12:28:25 PMMay 13
to ceres-...@googlegroups.com
This is possible in theory but will require some amount of template metaprogramming to deal with the fact that we instantiate the AutoDiffCostFunction with two different scalar types. 
What sized problem are you trying to solve and what is it that you are trying to do?
Sameer


--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/bf4e1dc1-ee3b-499f-b6b6-2c908033011bn%40googlegroups.com.

yhshi...@gmail.com

unread,
May 13, 2024, 10:43:33 PMMay 13
to Ceres Solver
Thanks for the quick response Sameer.

I'm trying to estimate the 3D trajectory and width/length/height of a vehicle, given ~1000 frames of segmentation masks from ~5-10 cameras (and some other inputs). I do this by constructing cuboid re-projection losses for each frame.

This does work reasonably well with some caveats but I'd like to push it further by adding some more expressive constraints.

My thought process is this:

1. I want to express multiple independent constraints (e.g. center error, width/height error, mask/bbox IOU) after the same "re-projection" step, but putting them in the same constraint couples them together in an undesirable way when applying robust loss functions.
2. I could separate them into separate constraints, but the cuboid "re-projection" step would be duplicated for each constraint, and this step is a bit compute-heavy in my problem due to some polygon operations.
3. It would therefore be useful if I could share the results of the re-projection step between multiple constraints.

I think this is probably not a terribly typical use case for Ceres, but maybe the ability to use the EvaluationCallback for AutoDiffCostFunction objects will be useful for others?

I would appreciate any input/advice.

Thanks again!

Sameer Agarwal

unread,
Jun 9, 2024, 12:55:30 PMJun 9
to ceres-...@googlegroups.com
Sorry for the late reply.
Your computation is of the form f1 + g, f2 + g, f3  + g, where g is the projection and then f1, f2, f3 are the variants you do on top of it.
There are three broad ways in which you can use evaluation callback.
1.  Given the value and jacobian of g if you are willing to compute the jacobian of f1 + g, f2 + g, f3 +g analytically, then you can use the evaluation callback + autodiff to compute g and read it into the cost function at evaluation time and do the composition with f1, f2, f3 as needed. This is the simplest approach and will work well as long as f1, f2, f3 are simple, which I suspect they are.
2. If you want to compute the composition of f1, f2, f3 also using autodiff, then you will have to do something a bit more complicated where the reading of the already computed g is wrapped inside a CostFunctionToFunctor object and then you evaluate the composition.
3. The third approach is to do this entire computation of the three variants in the evaluation callback using autodiff, store the residuals and jacobians in some datastructure and then read it in. This should be pretty much the same as the current evaluation callback example.

HTH,
Sameer


Reply all
Reply to author
Forward
0 new messages