Optimize large scale CostFunction memory allocation on heap

94 views
Skip to first unread message

f2020 l_

unread,
Apr 20, 2021, 6:03:58 AM4/20/21
to Ceres Solver
Hi,
I am using Ceres for direct method bundle adjustment. When I learn from the tutorials, I have a question:
For each observation, a cost function is allocated on the heap by the "new" operator. I am wondering if it is not efficient to allocate memory for each observation?

For example, if I have millions of observations, it might be very slow to allocate millions of cost functions on the heap and then add them to Ceres Problem.
Is there any good solution for direct method bundle adjustment? 
My idea is to integrate all observations on the same keyframe as one residual block. Is it possible?

Sameer Agarwal

unread,
Apr 20, 2021, 9:31:17 AM4/20/21
to ceres-...@googlegroups.com
You can create a single cost function for an entire frame, but that will also mean that the part of the Jacobian corresponding to it will be completely dense. Which may or may not work for you.
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/d00c6794-b29a-40fe-8311-355533e32413n%40googlegroups.com.

f2020 l_

unread,
Apr 20, 2021, 10:11:36 AM4/20/21
to Ceres Solver
Is the overhead of heap memory allocation high? 
To my knowledge, allocating heap memory is an expensive operation.
For the direct method bundle adjustment, if I have over millions of points and hundreds of camera poses to optimize, is it okay to allocate a cost function for each individual observation?
I can't imagine how slow if the CPU needs to execute millions of times heap memory allocation.
Is there a solution to allocate the memory at one time? Like the idea of a memory pool?

Sameer Agarwal

unread,
Apr 20, 2021, 10:12:57 AM4/20/21
to ceres-...@googlegroups.com
the cost of constructing a problem however large is almost always dwarfed by the time to solve it. I suggest trying this out before worrying about allocation costs.
Sameer


f2020 l_

unread,
Apr 20, 2021, 10:25:41 AM4/20/21
to Ceres Solver
Yes, I have understood. Thank you for your time!
Reply all
Reply to author
Forward
0 new messages