Similarity Transformation

76 views
Skip to first unread message

Alan Buchanan

unread,
Jan 6, 2017, 12:36:18 AM1/6/17
to Ceres Solver

Hello,

I am trying to write a similarity transformation using ceres.

My observations are points in two different coordinate systems which I call control and observations
The parameters I want to solve are the seven parameters of a similarity transformation (translation,rotation and scale.

I calculate approximate parameters prior to calling ceres solver.

I am finding that using the cost function for calculation the residuals ( below) results in a single iteration which says it has converged.
I use the same settings that I have used previously for a bundle adjustment for the problem class.

   bool operator()(const T* const transform,
  T* residuals) const 
{
T  dx = transform[0];
T  dy = transform[1];
T  dz = transform[2];
T  w = transform[3];
T  p = transform[4];
T  k = transform[5];
T  sc = transform[6];

T  sw = sin(w);
T  cw = cos(w);
T  sp = sin(p);
T  cp = cos(p);
T  sk = sin(k);
T  ck = cos(k);
T  r[9];

r[0] = cp * ck;
r[1] = -cp * sk;
r[2] = sp;

r[3] = (cw*sk)+(ck*sw*sp);
r[4] = (cw*ck)-(sw*sp*sk);  
r[5] = -(cp*sw);

r[6] = (sw*sk) - (cw*ck*sp);
r[7] = (cw*sp*sk) + (ck*sw);
r[8] = cw * cp;
residuals[0] = -(control(0)-(dx + sc * (r[0]*observation(0) + r[1]*observation(1) + r[2]*observation(2))));
residuals[1] = -(control(1)-(dy + sc * (r[3]*observation(0) + r[4]*observation(1) + r[5]*observation(2))));
residuals[2] = -(control(2)-(dz + sc * (r[6]*observation(0) + r[7]*observation(1) + r[8]*observation(2))));
        return true;
    }


Any advice available

Regards,

Alan









Sameer Agarwal

unread,
Jan 6, 2017, 12:50:28 AM1/6/17
to Ceres Solver

Alan,
For stuff like this it is helpful to see the output of summary::fullreport()
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/43f810f7-0674-422c-a498-cd4a6a46cdc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alan Buchanan

unread,
Jan 6, 2017, 4:44:22 AM1/6/17
to Ceres Solver
Sameer,

Output and settings below


Solver Summary (v 1.12.0-eigen-(3.3.0)-no_lapack-openmp)
                                     Original                  Reduced
Parameter blocks                            1                        1
Parameters                                  7                        7
Residual blocks                             5                        5
Residual                                   30                       30
Minimizer                        TRUST_REGION
Trust region strategy     LEVENBERG_MARQUARDT
                                        Given                     Used
Linear solver                 ITERATIVE_SCHUR          ITERATIVE_SCHUR
Preconditioner                   SCHUR_JACOBI             SCHUR_JACOBI
Threads                                     1                        1
Linear solver threads                       1                        1
Linear solver ordering              AUTOMATIC                        1
Use inner iterations                     True                    False
Cost:
Initial                         1.814380e+005
Final                           1.814380e+005
Change                          0.000000e+000
Minimizer iterations                       16
Successful steps                            1
Unsuccessful steps                         15
Time (in seconds):
Preprocessor                           0.0255
  Residual evaluation                  0.0149
  Jacobian evaluation                  8.2648
  Linear solver                        0.0116
Minimizer                              8.3368
Postprocessor                          0.0002
Total                                  8.3625
Termination:                      CONVERGENCE (Minimum trust region radius reached. Trust region radius: 7.523164e-033 <= 1.000000e-032)


Here are my settings

 ceres::Solver::Options options;
 options.use_nonmonotonic_steps = true;
 options.preconditioner_type = ceres::SCHUR_JACOBI;
 options.linear_solver_type = ceres::ITERATIVE_SCHUR;
 options.gradient_tolerance = 1e-6;
 options.function_tolerance = 1e-6;
 options.use_inner_iterations = true;
 options.max_num_iterations = 750;
 options.minimizer_progress_to_stdout = true;
 //    options.linear_solver_type = ceres::DENSE_SCHUR;
 options.minimizer_progress_to_stdout = true;
 //   options.max_num_iterations = 500;
 options.eta = 1e-2;
 options.max_solver_time_in_seconds = 600;
 options.logging_type = ceres::LoggingType::SILENT;
 ceres::Solver::Summary summary;
 ceres::Solve(options, &problem, &summary);
 

Sameer Agarwal

unread,
Jan 6, 2017, 9:59:36 AM1/6/17
to Ceres Solver
Thanks Alan.
what happens if you solve it with the default solver options? 
can you also share the solver output, run with -logtostderr -v=2
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.

Alan Buchanan

unread,
Jan 6, 2017, 10:29:26 AM1/6/17
to Ceres Solver
Sameer,

I ran with this with out any differences.

ceres::Solver::Options options;
options.logging_type = ceres::LoggingType::SILENT;
ceres::Solver::Summary summary;
ceres::Solve(options, &problem, &summary);

How do I run with   -logtostderr -v=2.
Is this a ceres command or a command line argument.

I use boost::program_options to parse my command line options and not sure how I would implement

Alan

Sameer Agarwal

unread,
Jan 6, 2017, 10:32:51 AM1/6/17
to Ceres Solver
do you get the same result with the default options? what is the output of summary::fullreport in this case?
I want to see the execution log, so don't turn the log to silent
the two flags I mentioned are glog flags so as to enable extra logging inside ceres.
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.

Alan Buchanan

unread,
Jan 6, 2017, 10:46:55 AM1/6/17
to Ceres Solver
Sameer,

Output is below.

I have just noticed something that is wrong in the output.

My test data has 5 sets of data (that is 5 common points with two sets of coordinates.

The residuals should therefore be 15 ( 3 x 5). The output shows 30 which looks strange.

This is my cost function which I am assuming must be the wrong. Does Ceres expect a residual for each observation ?

    static ceres::CostFunction* Create(const Vec3 observation, const Vec3 control) {
        return (new ceres::AutoDiffCostFunction<SimilarityTransformError, 6, 7>(
                new SimilarityTransformError(observation, control)));
    }



Solver Summary (v 1.12.0-eigen-(3.3.0)-no_lapack-openmp)
                                     Original                  Reduced
Parameter blocks                            1                        1
Parameters                                  7                        7
Residual blocks                             5                        5
Residual                                   30                       30
Minimizer                        TRUST_REGION
Dense linear algebra library            EIGEN
Trust region strategy     LEVENBERG_MARQUARDT
                                        Given                     Used
Linear solver                        DENSE_QR                 DENSE_QR

Threads                                     1                        1
Linear solver threads                       1                        1
Linear solver ordering              AUTOMATIC                        1
Cost:
Initial                         1.814380e+005
Final                           1.814380e+005
Change                          0.000000e+000
Minimizer iterations                       16
Successful steps                            1
Unsuccessful steps                         15
Time (in seconds):
Preprocessor                           0.0020
  Residual evaluation                  0.0166
  Jacobian evaluation                  0.0032
  Linear solver                        0.0200
Minimizer                              0.0541
Postprocessor                          0.0002
Total                                  0.0563

Sameer Agarwal

unread,
Jan 6, 2017, 10:54:10 AM1/6/17
to Ceres Solver
yes the way you are creating the cost function is wrong. The first argument is the number of residuals, which should be three, not 7.

ceres::AutoDiffCostFunction<SimilarityTransformError, 3, 7>

so this is another argument to use glog properly. Ceres has been telling you in the logs that the cost function evaluation is failing because not all coordinates of the residual are being assigned to, you were assigning to 3 when saying it had 6.

changing the 6 to 3 should fix things.

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.

Alan Buchanan

unread,
Jan 6, 2017, 10:55:50 AM1/6/17
to Ceres Solver
Sameer,

It works after I changed the cost function to 3 (first input) rather than 6. I was confused because I thought this was the number of data points passed to the create function !

    static ceres::CostFunction* Create(const Vec3 observation, const Vec3 control) {
        return (new ceres::AutoDiffCostFunction<SimilarityTransformError, 3, 7>(
                new SimilarityTransformError(observation, control)));
    }

Thanks for your help. it is a slow process but I am gradually learning more as I go along.

Alan

Sameer Agarwal

unread,
Jan 6, 2017, 11:41:06 AM1/6/17
to Ceres Solver
Happy help Alan.
This also indicates a problem with the solver status that is being returned though. We should likely do something special in the case where the very first evaluation of the cost function fails like this. 
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.

Sameer Agarwal

unread,
Jan 15, 2017, 6:59:59 PM1/15/17
to Ceres Solver
Alan,

Looking at his more closely revealed a problem with the AutoDiffCostFunction was defined and was able to sidestep some checks ceres has for partially evaluated cost fuctions. 

https://ceres-solver-review.googlesource.com/#/c/9360/ is out for review, which should cause the improperly defined AutoDiffCostFunctions to trigger an evaluation error.

Sameer

Alan Buchanan

unread,
Jan 16, 2017, 9:10:48 AM1/16/17
to Ceres Solver
Thanks  Sameer for all your help.

I am currently looking at openMVG and openMVS which is keeping me budy !

At some point in the future I will be having another crack at Ceres and no doubt will have more questions.

Regards,

Alan 
Reply all
Reply to author
Forward
0 new messages