Catching ceres exceptions

689 views
Skip to first unread message

Luis-Jorge Romeo

unread,
Jan 10, 2014, 9:09:44 AM1/10/14
to ceres-...@googlegroups.com
Hi all,
I'm wondering how can I catch the exceptions throwed by Ceres. 

I'm unable to avoid the program termination, even using try/catch blocks, the program terminates inmediatly with a console message like for exmaple:

WARNING: Logging before InitGoogleLogging() is written to STDERR
F0110 14:29:18.278847 96696 problem_impl.cc:65] Check failed: it != parameter_map.end() Parameter block not found: 0
00012C40D08
*** Check failure stack trace: ***


Is there a way to avoid the program termination on Ceres errors? If there is any problem with optimization, I would like to detect it and keep the un-optimized solution.

Regards,
Jorge

Sameer Agarwal

unread,
Jan 10, 2014, 9:14:49 AM1/10/14
to ceres-...@googlegroups.com
Hi Jorge,

We do not use exceptions in ceres. This is a google-ism. But we are extremely careful about handling fatal failures in ceres. In the cases that ceres terminates like this, it is either a user error or a bug in ceres. The former you should fix the latter we are very interested in learning about and fixing. 

I do not think it makes any sense to try and work around programmatic errors like this. If you think I am wrong, I would be curious to see an example.

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/CAB_M7uWz8av2vtwDe28dcDgaj6Hzn3SoSFvRnZZnmB%2BQVEpyng%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Luis-Jorge Romeo

unread,
Jan 10, 2014, 10:32:51 AM1/10/14
to ceres-...@googlegroups.com
Hi Sameer, thanks for your answer. 

In my program I launch tens of small optimizations every few seconds. Every optimization corresponds to a possible solution, so if one fails during optimization, the lazy approximation was to skip it, since there is probably another good solution.

Indeed it is a user error, in some ill situations, all observations are discarded and that was causing the error. I replaced my try/catch block with and if{}/else{throw } and now I get the desired effect.

Anyway, I've been curious about the error management in ceres for some time and this case reminded me that, so I asked.

Regards and thanks for your time!
Jorge


2014/1/10 Sameer Agarwal <sameer...@google.com>

Sameer Agarwal

unread,
Jan 10, 2014, 10:43:03 AM1/10/14
to ceres-...@googlegroups.com
Hi Jorge,

In my program I launch tens of small optimizations every few seconds. Every optimization corresponds to a possible solution, so if one fails during optimization, the lazy approximation was to skip it, since there is probably another good solution.

Indeed it is a user error, in some ill situations, all observations are discarded and that was causing the error. I replaced my try/catch block with and if{}/else{throw } and now I get the desired effect.

so you were getting a problem of size zero and that was causing a crash? I think this has been fixed recently..

Sameer

 

Luis-Jorge Romeo

unread,
Jan 11, 2014, 11:57:37 AM1/11/14
to ceres-...@googlegroups.com
Hi Sameer,
here is the problem-building loop:

// Add a residual block per measured point
for (int i=0; i<measurements_L.size(); i++)
{
// left cam measurement
if ((measurements_L[i].x >= 0) && (measurements_L[i].y >= 0)) 
{
CoordinateTransformation3D T_C0_Ck = CoordinateTransformation3D(kp->Get_Camera_Pose()) * Calib_S->Get_Baseline();
CostFunction* cost_function;
Point3DReprojectionError *p_residual = new Point3DReprojectionError(T_C0_Ck, Calib_L, measurements_L[i], model_points3D[i], isBlob);
cost_function = new NumericDiffCostFunction<Point3DReprojectionError, CENTRAL, 2, 3, 4>(p_residual);

// Use loss function.
LossFunction* loss_function = new HuberLoss(Cfg->Get_Merger_RobustifierParameter());
// When using quaternions, we split the camera into two
// parameter blocks. One of size 3 and another of size 4 for the quaternion
problem.AddResidualBlock(cost_function,
loss_function,
parameters_,  
parameters_ + 3);
}

// right cam measurement
if ((measurements_R[i].x >= 0) && (measurements_R[i].y >= 0)) 
{
CoordinateTransformation3D T_C0_Ck = CoordinateTransformation3D(kp->Get_Camera_Pose());
CostFunction* cost_function;
Point3DReprojectionError *p_residual = new Point3DReprojectionError(T_C0_Ck, Calib_R, measurements_R[i], model_points3D[i], isBlob);
cost_function = new NumericDiffCostFunction<Point3DReprojectionError, CENTRAL, 2, 3, 4>(p_residual);
// Use loss function.
LossFunction* loss_function = new HuberLoss(Cfg->Get_Merger_RobustifierParameter());
// When using quaternions, we split the camera into two
// parameter blocks. One of size 3 and another of size 4 for the quaternion
problem.AddResidualBlock(cost_function,
loss_function,
parameters_,  
parameters_ + 3);
}
}

The fatal error is produced when neither of the if was true and so no  residual block were added. My ceres version:

version 1.8.0
abi_version 1.8.0
commit 1a041c35b780e60c3b497eb096b72ad20f47960e

Regards,
Jorge


2014/1/10 Sameer Agarwal <sameer...@google.com>

Sameer Agarwal

unread,
Jan 11, 2014, 12:59:45 PM1/11/14
to ceres-...@googlegroups.com
Could you try the latest git version and if you still get a crash can you also describe the solver configuration that you are using?

To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/CAB_M7uWHmMYUYucgay541txuyhg25d39X%2Bn2oby7pvu2AF5adQ%40mail.gmail.com.

Luis-Jorge Romeo

unread,
Jan 14, 2014, 3:01:08 AM1/14/14
to ceres-...@googlegroups.com
Hi,
I've tried the latest git version and now I don't get a crash. Now with 0-sized problem, solver terminates with:

termination_type = DID_NOT_RUN
error = "Problem contains no parameter blocks."


2014/1/11 Sameer Agarwal <sandwi...@gmail.com>

Sameer Agarwal

unread,
Jan 14, 2014, 3:25:17 AM1/14/14
to ceres-...@googlegroups.com

That termination message does not sound right. Since the DID_NOT_RUN enum does not exist anymore in the latest git version.

Sameer



Luis-Jorge Romeo

unread,
Jan 14, 2014, 7:03:36 AM1/14/14
to ceres-...@googlegroups.com
My fail, was executing the stable 1.8 version. The termination status for latest git version:

termination_type = CONVERGENCE
message = "Terminating: Function tolerance reached. No non-constant parameter blocks found."

Is that correct?

Jorge


2014/1/14 Sameer Agarwal <sameer...@google.com>

Sameer Agarwal

unread,
Jan 14, 2014, 11:01:33 AM1/14/14
to ceres-...@googlegroups.com
Yes that is correct.

On Tuesday, January 14, 2014 4:03:37 AM, Luis-Jorge Romeo <luis.jor...@gmail.com> wrote:

My fail, was executing the stable 1.8 version. The termination status for latest git version:

termination_type = CONVERGENCE

message = "Terminating: Function tolerance reached. No non-constant parameter blocks found."

Is that correct?

Jorge

2014/1/14 Sameer Agarwal <sameeragarwal@google.com>


That termination message does not sound right. Since the DID_NOT_RUN enum does not exist anymore in the latest git version.

Sameer


On Tue, Jan 14, 2014 at 12:01 AM, Luis-Jorge Romeo <luis.jorge.romeo@gmail.com> wrote:

Hi,

I've tried the latest git version and now I don't get a crash. Now with 0-sized problem, solver terminates with:

termination_type = DID_NOT_RUN

error = "Problem contains no parameter blocks."

2014/1/11 Sameer Agarwal <sandwichmaker@gmail.com>

To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/CAB_M7uUrbAZhaozK5gQ5JNnaDFmd_Tn1_Ru-hN8x53-%3Dt%2Bj8tg%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages