Run time error : double free or corruption (out) with BiCubicInterpolator

716 views
Skip to first unread message

Manohar Kuse

unread,
Aug 5, 2016, 3:12:31 AM8/5/16
to Ceres Solver
Hello Again,

My cost function is a 2D grid, as discussed in a previous thread (https://groups.google.com/forum/#!topic/ceres-solver/JBPk9Aj0qio).

As I run my program my program crashes
*** Error in `/path/to/myprogram': double free or corruption (out): 0x000000000409d900 ***
Aborted (core dumped)


My GDB stack
Program received signal SIGABRT, Aborted.
0x00007ffff2f48cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) where
#0  0x00007ffff2f48cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff2f4c0d8 in __GI_abort () at abort.c:89
#2  0x00007ffff2f85394 in __libc_message (do_abort=do_abort@entry=1, 
    fmt=fmt@entry=0x7ffff3093b28 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff2f9166e in malloc_printerr (ptr=<optimized out>, str=0x7ffff3093c58 "double free or corruption (out)", 
    action=1) at malloc.c:4996
#4  _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3840
#5  0x00000000004632f3 in ceres::internal::AutoDiff<EAResidue, double, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0>::Differentiate(EAResidue const&, double const* const*, int, double*, double**) ()
#6  0x000000000047a5e3 in ceres::internal::ResidualBlock::Evaluate(bool, double*, double*, double**, double*) const ()
#7  0x00000000004952d0 in ceres::internal::ProgramEvaluator<ceres::internal::ScratchEvaluatePreparer, ceres::internal::DenseJacobianWriter, ceres::internal::NullJacobianFinalizer>::Evaluate(ceres::internal::Evaluator::EvaluateOptions const&, double const*, double*, double*, double*, ceres::internal::SparseMatrix*) [clone ._omp_fn.3] ()
#8  0x000000000049b88e in ceres::internal::ProgramEvaluator<ceres::internal::ScratchEvaluatePreparer, ceres::internal::DenseJacobianWriter, ceres::internal::NullJacobianFinalizer>::Evaluate(ceres::internal::Evaluator::EvaluateOptions const&, double const*, double*, double*, double*, ceres::internal::SparseMatrix*) ()
#9  0x00000000004abeac in ceres::internal::TrustRegionMinimizer::EvaluateGradientAndJacobian() ()
#10 0x00000000004ac643 in ceres::internal::TrustRegionMinimizer::IterationZero() ()
#11 0x00000000004b0796 in ceres::internal::TrustRegionMinimizer::Minimize(ceres::internal::Minimizer::Options const&, double*, ceres::Solver::Summary*) ()
#12 0x000000000048974f in ceres::Solver::Solve(ceres::Solver::Options const&, ceres::Problem*, ceres::Solver::Summary*)
#13 0x0000000000489de9 in ceres::Solve(ceres::Solver::Options const&, ceres::Problem*, ceres::Solver::Summary*) ()
#14 0x000000000045a953 in SolveEA::setAsCERESProblem() ()
#15 0x00000000004512bc in main ()


Number of residues is 8322. With 2 optimization variable a quaternion and another 3d translation.

Most relevant part of my program:
    double q_cap[4] = {1,0,0,0};
    double t_cap[3] = {0,0,0};

    Problem problem;
    // make interpolator
    ceres::Grid2D<double,2> grid( now_dist_transform_eig.data(), 0, now_dist_transform_eig.rows(), 0, now_dist_transform_eig.cols());
    BiCubicInterpolator< Grid2D<double,2> > interpolated_cost_function(grid);


    problem.AddResidualBlock( new AutoDiffCostFunction<EAResidue,8322,4,3>( new EAResidue(list_edge_ref, interpolated_cost_function, K) ),
                              NULL,
                              q_cap,
                              t_cap
                              );



    // local parameterization
    LocalParameterization* local_parameterization = new ceres::QuaternionParameterization;
    problem.SetParameterization(q_cap, local_parameterization);

    // setting the solver
    Solver::Options options;
    //    options.max_num_iterations = 25;
    options.max_solver_time_in_seconds = 5;
    options.linear_solver_type = ceres::DENSE_QR;
    options.minimizer_progress_to_stdout = true;


    options.minimizer_type = ceres::TRUST_REGION;
    options.trust_region_strategy_type = ceres::DOGLEG;
    options.dogleg_type = ceres::SUBSPACE_DOGLEG;



    Solver::Summary summary;
    Solve(options, &problem, &summary);
    //    std::cout << summary.BriefReport() << "\n";
    std::cout << summary.FullReport() << "\n";


What could possibly be going wrong?

Sameer Agarwal

unread,
Aug 5, 2016, 3:16:46 AM8/5/16
to Ceres Solver
that is a huge residual. 
consider creating one cost function for each residual.

--
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/957436ec-4b35-4ece-a544-40c88e20f550%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Manohar Kuse

unread,
Aug 5, 2016, 4:03:10 AM8/5/16
to Ceres Solver
I now make multiple calls to AddResidueBlock
// now_dist_transform_eig is about 300x300 matrix
ceres::Grid2D<double,2> grid( now_dist_transform_eig.data(), 0, now_dist_transform_eig.rows(), 0, now_dist_transform_eig.cols());
//    ceres::Grid2D<double,1> grid( now_dist_transform_eig.data(), now_dist_transform_eig.rows(), now_dist_transform_eig.cols());
    BiCubicInterpolator< Grid2D<double,2> > interpolated_cost_function(grid);

    for( int ir=0 ; ir<list_edge_ref.cols() ; ir++ )
    {
        double curX, curY, curZ;
        curX = list_edge_ref(0,ir);
        curY = list_edge_ref(1,ir);
        curZ = list_edge_ref(2,ir);

        problem.AddResidualBlock( new AutoDiffCostFunction<EAResidue,1,4,3>( new EAResidue(curX,curY,curZ, interpolated_cost_function, K) ),
                                  NULL,
                                  q_cap,
                                  t_cap
                                  );
    }

The EAResidue class operator() evaluates 1 residue at a time.

Following gets thrown up. 
W0805 15:58:14.552080  4914 residual_block.cc:131] 

Error in evaluating the ResidualBlock.

There are two possible reasons. Either the CostFunction did not evaluate and fill all    
residual and jacobians that were requested or there was a non-finite value (nan/infinite)
generated during the or jacobian computation. 

Residual Block size: 2 parameter blocks x 1 residuals

For each parameter block, the value of the parameters are printed in the first column   
and the value of the jacobian under the corresponding residual. If a ParameterBlock was 
held constant then the corresponding jacobian is printed as 'Not Computed'. If an entry 
of the Jacobian/residual array was requested but was not written to by user code, it is 
indicated by 'Uninitialized'. This is an error. Residuals or Jacobian values evaluating 
to Inf or NaN is also an error.  

Residuals:     2.13187e+304 

Parameter Block 0, size: 4

           1 |            0 
           0 | 3.73428e+306 
           0 |         -inf 
           0 | -5.10628e+307 

Parameter Block 1, size: 3

           0 |          inf 
           0 | -6.77713e+305 
           0 | 2.31114e+307 


E0805 15:58:14.552326  4914 trust_region_minimizer.cc:72] Terminating: Residual and Jacobian evaluation failed.

Solver Summary (v 1.12.0-eigen-(3.2.6)-lapack-suitesparse-(4.2.1)-openmp)

                                     Original                  Reduced
Parameter blocks                            2                        2
Parameters                                  7                        7
Effective parameters                        6                        6
Residual blocks                          8322                     8322
Residual                                 8322                     8322

Minimizer                        TRUST_REGION

Dense linear algebra library            EIGEN
Trust region strategy                  DOGLEG (TRADITIONAL)

                                        Given                     Used
Linear solver                        DENSE_QR                 DENSE_QR
Threads                                     1                        1
Linear solver threads                       1                        1

Cost:
Initial                         -1.000000e+00

Minimizer iterations                        0
Successful steps                            0
Unsuccessful steps                          0

Time (in seconds):
Preprocessor                           0.0009

  Residual evaluation                  0.0000
  Jacobian evaluation                  0.0040
  Linear solver                        0.0000
Minimizer                              0.0040

Postprocessor                          0.0002
Total                                  0.0051

Termination:                          FAILURE (Residual and Jacobian evaluation failed.)




    bool operator()(const T* const Q, const T* const t, T* residual) const
    {
        T R[9];
        ceres::QuaternionToRotation(Q, R); //use `ceres::QuaternionRotatePoint`

            T _x = T(lx);
            T _y = T(ly);
            T _z = T(lz);

            // xd = R*x + t
            T _xd = t[0] + R[0] * _x + R[3] * _y + R[6] * _z;
            T _yd = t[1] + R[1] * _x + R[4] * _y + R[7] * _z;
            T _zd = t[2] + R[2] * _x + R[5] * _y + R[8] * _z;

            // de-homegenous and project
            T _u = T(fx) * _xd / (_zd+.001) + T(cx);
            T _v = T(fy) * _yd / (_zd+.001) + T(cy);

            cost.Evaluate(_u, _v, &residual[0] );


        return true;
    }



Sameer Agarwal

unread,
Aug 5, 2016, 4:05:29 AM8/5/16
to Ceres Solver
The error message says it all. You are getting infinities in your derivatives.
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.
Reply all
Reply to author
Forward
0 new messages