Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check failed: size == existing_size Core dumped #434

Closed
riematrix opened this issue Jul 6, 2018 · 10 comments
Closed

Check failed: size == existing_size Core dumped #434

riematrix opened this issue Jul 6, 2018 · 10 comments

Comments

@riematrix
Copy link

riematrix commented Jul 6, 2018

Core dumped at structure from motion step.
BUG

Problem

[13:57:31.642496][info] AutomaticInitialPairChoice, test I: 2130908429, J: 2146485851, nbCommonTracks: 308
*
[13:57:31.643868][info] AutomaticInitialPairChoice, test I: 2140548709, J: 2146485851, nbCommonTracks: 140
[13:57:31.682983][info] Initial pair is:
A - view id: 77159844 - filepath: /home/zj/data/szyl_segment/images/DJI_0158.JPG
B - view id: 793985669 - filepath: /home/zj/data/szyl_segment/images/DJI_0160.JPG
[13:57:31.683931][info] 802 matches in the image pair for the initial pose estimation.
problem_impl.cc:101 Check failed: size == existing_size Tried adding a parameter block with the same double pointer, 0x165d370, twice, but with different block sizes. Original size was 7 but new size is 3
Aborted (core dumped)

Conditions

Prepare data set with more than 100 images. Problem may not occur if the amount of images is small.
I've tried with amount 3, 29 and 120, only the 120 dataset failed with image size 5472x3648.

Steps to Reproduce

  1. PYTHONPATH=$PWD python meshroom/ui
  2. Compute StructureFromMotion

Versions

  • AliceVision branch/version: develop head
  • OS: ubuntu14.04
  • C++ compiler: gcc
@riematrix
Copy link
Author

riematrix commented Jul 30, 2018

After some code analysis I added two logs in BundleAdjustmentCeres.cpp at about line 283 and line 404.
Seems that there is a mistake of using ceres-solver, just as the error log shows.

283
double * parameter_block = &map_intrinsics[idIntrinsics][0];
problem.AddParameterBlock(parameter_block, map_intrinsics[idIntrinsics].size());

ALICEVISION_LOG_DEBUG("--------------------AddParameterBlock ");
ALICEVISION_LOG_DEBUG( parameter_block );
ALICEVISION_LOG_DEBUG(" Size ");
ALICEVISION_LOG_DEBUG( map_intrinsics[idIntrinsics].size());
ALICEVISION_LOG_DEBUG( " & " );
ALICEVISION_LOG_DEBUG(&parameter_block);
ALICEVISION_LOG_DEBUG("--------------------" );

404
ceres::CostFunction* costFunction = createCostFunctionFromIntrinsics(sfm_data.intrinsics[view->getIntrinsicId()].get(), observationIt.second.x);

    ALICEVISION_LOG_DEBUG("--------------------start AddResidualBlock int " );
    ALICEVISION_LOG_DEBUG( &map_intrinsics[view->getIntrinsicId()][0] );
    ALICEVISION_LOG_DEBUG( " pose ");
    ALICEVISION_LOG_DEBUG( &map_poses[view->getPoseId()][0] );
    ALICEVISION_LOG_DEBUG( " x " );
    ALICEVISION_LOG_DEBUG( landmarkIt.second.X.data());
    ALICEVISION_LOG_DEBUG("--------------------" );

Here is the out put:

[11:51:58.207050][debug] 518993753, 1782016916 |        +27452.1 |         +1218.0 |           +22.5 |            1214
[11:51:58.207238][info] Initial pair is:
  A - view id: 319589866 - filepath: /home/zj/data/szyl_segment/images/DJI_0181.JPG
  B - view id: 1845795821 - filepath: /home/zj/data/szyl_segment/images/DJI_0183.JPG
[11:51:58.215213][info] 853 matches in the image pair for the initial pose estimation.
[11:52:11.374769][debug] A-Contrario initial pair residual: 52.6677
[11:52:11.647555][debug] BundleAdjustmentCeres: DENSE_SCHUR
[11:52:11.647591][debug] Global BundleAdjustment dense
[11:52:11.647603][debug] BundleAdjustmentCeres: DENSE_SCHUR
[11:52:11.647908][debug] --------------------AddParameterBlock 
[11:52:11.647928][debug] 0x627b950
[11:52:11.647942][debug]  Size 
[11:52:11.647951][debug] 7
[11:52:11.647960][debug]  & 
[11:52:11.647970][debug] 0x7ffe014a7030
[11:52:11.647980][debug] --------------------
[11:52:11.648010][debug] --------------------start AddResidualBlock int 
[11:52:11.648021][debug] 0x627b950
[11:52:11.648032][debug]  pose 
[11:52:11.648040][debug] 0x627bc00
[11:52:11.648049][debug]  x 
[11:52:11.648057][debug] 0x7fe4a4003bc8
[11:52:11.648066][debug] --------------------
problem_impl.cc:101 Check failed: size == existing_size Tried adding a parameter block with the same double pointer, 0x627b950, twice, but with different block sizes. Original size was 7 but new size is 3
The program has unexpectedly finished.
/home/zj/exp/photogrammetry/build-AliceVision-Desktop-Default/Linux-x86_64/aliceVision_incrementalSfM crashed

@riematrix
Copy link
Author

riematrix commented Jul 31, 2018

Some more info about the gdb stack trace and the code analytics.

#0 0x00007f010397cc37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007f0103980028 in __GI_abort () at abort.c:89
#2 0x00007f010597f415 in MessageLogger::~MessageLogger() () from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#3 0x00007f0105a319c6 in ceres::internal::ProblemImpl::InternalAddParameterBlock(double*, int) () from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#4 0x00007f0105a3225c in ceres::internal::ProblemImpl::AddResidualBlock(ceres::CostFunction*, ceres::LossFunction*, std::vector<double*, std::allocator<double*> > const&) ()
from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#5 0x00007f0105a32c18 in ceres::internal::ProblemImpl::AddResidualBlock(ceres::CostFunction*, ceres::LossFunction*, double*, double*, double*) ()
from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#6 0x00007f010597955b in aliceVision::sfm::BundleAdjustmentCeres::createProblem(aliceVision::sfm::SfMData&, aliceVision::sfm::BA_Refine, ceres::Problem&) ()
from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#7 0x00007f010597b358 in aliceVision::sfm::BundleAdjustmentCeres::Adjust(aliceVision::sfm::SfMData&, aliceVision::sfm::BA_Refine) ()
from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#8 0x00007f010593c56e in aliceVision::sfm::ReconstructionEngine_sequentialSfM::BundleAdjustment(bool) ()
from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#9 0x00007f010594d4a7 in aliceVision::sfm::ReconstructionEngine_sequentialSfM::makeInitialPair3D(std::pair<unsigned int, unsigned int> const&) ()
from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#10 0x00007f010594ea18 in aliceVision::sfm::ReconstructionEngine_sequentialSfM::createInitialReconstruction(std::vector<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int> > > const&) () from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#11 0x00007f010595188b in aliceVision::sfm::ReconstructionEngine_sequentialSfM::process() () from /home/zj/exp/photogrammetry/AliceVision/build/external/aliceVision_build/lib/libaliceVision_sfm.so.0
#12 0x0000000000453161 in main ()

Analysis

The error occurs at ceres problem_impl.cc line 101.
This size check happens while calling:

ParameterBlock* ProblemImpl::InternalAddParameterBlock(double* values, int size)

So the size compare is between the size of stored params in parameter_block_map_(existing_size) and the second param (int size) which is passed in.

Trace of those two values:

1. BundleAdjustmentCeres.cpp at about line 282
[11:52:11.647908][debug] --------------------AddParameterBlock

Pointer 0x627b950 which points to one of sfm_data's intrinsic params, was the first added to map_intrinsics.
At the same time this pointer(parameter_block) was added to ceres's Problem at line 283:

problem.AddParameterBlock(parameter_block, map_intrinsics[idIntrinsics].size());

Function AddParameterBlock will call ceres's function InternalAddParameterBlock.
So I guess map_intrinsics[idIntrinsics].size() with value 7 is the first value which is stored in ceres's parameter_block_map_?

2. BundleAdjustmentCeres.cpp at about line 404
[11:52:11.648010][debug] --------------------start AddResidualBlock

  problem.AddResidualBlock(
      costFunction,
      p_LossFunction,
      &map_intrinsics[view->getIntrinsicId()][0],
      &map_poses[view->getPoseId()][0],
      landmarkIt.second.X.data()); //Do we need to copy 3D point to avoid false motion, if failure ?
  }

The third param &map_intrinsics[view->getIntrinsicId()][0] is just the same pointer 0x627b950, which is the former intrinsic params.
The InternalAddParameterBlock was called again at ceres problem_impl.cc line 276:

  InternalAddParameterBlock(parameter_blocks[i],
                              parameter_block_sizes[i]);

So from the error we know the parameter_block_sizes[i] is 3. Trace back the second param parameter_block_sizes[i], it was somethig about
the passed in cost function at line 245:

const vector<int32>& parameter_block_sizes =
  cost_function->parameter_block_sizes();

The cost function was created by BundleAdjustmentCeres.cpp at about line 403:

 ceres::CostFunction* costFunction = createCostFunctionFromIntrinsics(sfm_data.intrinsics[view->getIntrinsicId()].get(), observationIt.second.x);

If the trace is correct, parameter_block_sizes() will return one internal value which is initalized during the definition of the cost function.

I'm sure we are using the PINHOLE_CAMERA modal across all images. So the value 3 is the intrinsics size, i.e. the second number at line 26:

case PINHOLE_CAMERA:
  return new ceres::AutoDiffCostFunction<ResidualErrorFunctor_Pinhole, 2, 3, 6, 3>(
    new ResidualErrorFunctor_Pinhole(observation.data()));

Finally, seems that those two values should not match proberbly because they have different meanning. Perhaps one is the real size of intrinsics and the other is the size of target intrinsics to be optimized? I have no idea which is correct during BundleAdjustment.

The same problem may exist in LocalBundleAdjustmentCeres.cpp. Hope this info will hlep. Thx.

@gregoire-dl
Copy link
Member

Hi,

Thank you for your detail analysis.
It's a great start for our investigation.
Is it possible to send us your images and meshroom scene file?
(you can do it privately using alicevision-team@googlegroups.com)

@riematrix
Copy link
Author

riematrix commented Aug 1, 2018

Hi,
I've already shared the data via email.

PS
File cameraInit.sfm in MeshroomCache contains "intrinsics": [
{
"intrinsicId": "2851613064",
"width": "5472",
"height": "3648",
"type": "pinhole",
"serialNumber": "c9dbe393a1e134e2cd33ae245d5e1ceb",
"pxInitialFocalLength": "-1",
"pxFocalLength": "8.8000000000000007",
"principalPoint": [
"2736",
"1824"
],
"distortionParams": [
"0",
"0",
"0",
"0"
],
"locked": "false"
}
]

Although distortionParams are zeros, they are add to camera model at Pinhole.hpp line 112

params.insert(params.end(), _distortionParams.begin(), _distortionParams.end());

so the result vector size of getParams() will return 7, which will not match size 3 defined by the pinhole cost function?

@fabiencastan
Copy link
Member

Do you manually changed the camera model on the CameraInit to Pinhole in Meshroom?

@riematrix
Copy link
Author

riematrix commented Aug 1, 2018

@fabiencastan yes, is it should remains to be unchanged?

@fabiencastan
Copy link
Member

No, you are correct, it is definitely a bug! There is an old PR to fix it that has never been merged.
I just updated it:
#347
Can you try it?

@fabiencastan
Copy link
Member

I just tried your dataset and it works for me with the PR.

@fabiencastan
Copy link
Member

It's now merged in the "develop" branch.

@riematrix
Copy link
Author

Fixed with #347

@natowi natowi added the linux label Jun 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants