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

more then 5348 nodes,optimize crash on window #1827

Open
luyuanxunnuli opened this issue Sep 7, 2024 · 2 comments
Open

more then 5348 nodes,optimize crash on window #1827

luyuanxunnuli opened this issue Sep 7, 2024 · 2 comments

Comments

@luyuanxunnuli
Copy link

luyuanxunnuli commented Sep 7, 2024

I found that when the number of nodes is large, such as more then 6000 points, the same data and code can run normally on Ubuntu, but crash on Windows 10, so I built some test data. After testing, it was found that the system crashes when the number of nodes more then 8478. The system is running on Win10 and has 16GB of memory,qt creator 13.0.0,base on msvc2019, both gtsam 4_2a9 boost1-86-0 and gtsam 4.1.1 boost1-72-0 crash。when crach:
larget_data_gtsam_opitmize_crash

code in gtsam example Pose3Localization:

int main(const int argc, const char* argv[]) {
// Read graph from file
string g2oFile;
if (argc < 2)
//g2oFile = findExampleDataFile("pose3Localizationexample.txt");
g2oFile = findExampleDataFile("data.txt");
else
g2oFile = argv[1];

NonlinearFactorGraph::shared_ptr graph;
Values::shared_ptr initial;
bool is3D = true;
boost::tie(graph, initial) = readG2o(g2oFile, is3D);

// Add prior on the first key
auto priorModel = noiseModel::Diagonal::Variances(
(Vector(6) << 1e-6, 1e-6, 1e-6, 1e-4, 1e-4, 1e-4).finished());
Key firstKey = 0;
for (const auto key : initial->keys()) {
std::cout << "Adding prior to g2o file " << std::endl;
firstKey = key;
graph->addPrior(firstKey, Pose3(), priorModel);
break;
}

std::cout << "Optimizing the factor graph" << std::endl;
GaussNewtonParams params;
params.setVerbosity("TERMINATION"); // show info about stopping conditions
LevenbergMarquardtOptimizer/GaussNewtonOptimizer/ optimizer(*graph, *initial, params);//GaussNewtonOptimizer crash too
Values result = optimizer.optimize();
std::cout << "Optimization complete" << std::endl;

return 0;

std::cout << "initial error=" << graph->error(*initial) << std::endl;
std::cout << "final error=" << graph->error(result) << std::endl;

if (argc < 3) {
result.print("result");
} else {
const string outputFile = argv[2];
std::cout << "Writing results to file: " << outputFile << std::endl;
NonlinearFactorGraph::shared_ptr graphNoKernel;
Values::shared_ptr initial2;
boost::tie(graphNoKernel, initial2) = readG2o(g2oFile);
writeG2o(*graphNoKernel, result, outputFile);
std::cout << "done! " << std::endl;
}

// Calculate and print marginal covariances for all variables
Marginals marginals(*graph, result);
for (const auto& key_pose : result.extract()) {
std::cout << marginals.marginalCovariance(key_pose.first) << endl;
}
return 0;
}

data.txt is my data,like this:
VERTEX_SE3:QUAT 0 0 0 0 0 0 0 0
VERTEX_SE3:QUAT 1 1 0 0 0 0 0 0
VERTEX_SE3:QUAT 2 2 0 0 0 0 0 0
VERTEX_SE3:QUAT 3 3 0 0 0 0 0 0
VERTEX_SE3:QUAT 4 4 0 0 0 0 0 0
VERTEX_SE3:QUAT 5 5 0 0 0 0 0 0
VERTEX_SE3:QUAT 6 6 0 0 0 0 0 0
VERTEX_SE3:QUAT 7 7 0 0 0 0 0 0
VERTEX_SE3:QUAT 8 8 0 0 0 0 0 0
VERTEX_SE3:QUAT 9 9 0 0 0 0 0 0
VERTEX_SE3:QUAT 10 10 0 0 0 0 0 0
VERTEX_SE3:QUAT 11 11 0 0 0 0 0 0
VERTEX_SE3:QUAT 12 12 0 0 0 0 0 0
VERTEX_SE3:QUAT 13 13 0 0 0 0 0 0
VERTEX_SE3:QUAT 14 14 0 0 0 0 0 0
VERTEX_SE3:QUAT 15 15 0 0 0 0 0 0
........
EDGE_SE3:QUAT 0 1 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 1 2 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 2 3 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 3 4 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 4 5 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 5 6 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 6 7 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 7 8 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 8 9 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 9 10 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 10 11 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 11 12 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 12 13 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 13 14 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 14 15 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 15 16 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 16 17 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
EDGE_SE3:QUAT 17 18 1 0 0 0.01 0.01 0.01 0.01 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
.....

10000 nodes 9999 edges

@luyuanxunnuli luyuanxunnuli changed the title more then 5348 nodes,optimize crash more then 5348 nodes,optimize crash on window Sep 9, 2024
@luyuanxunnuli
Copy link
Author

First of all, I do a apologize. Today, I debugged and ran the official Pose3Localization directly on Visual Studio, only replacing loacal.txe with my own data.txt and setting the stack size to be larger. It did indeed crash, but when I replaced the GaussNewtonOptimizer with the LM optimizer, it run normally. I replied to you yesterday that The LM optimizer with larger stack size crash was incorrect.GaussNewtonOptimizer crashes even if the data is small. @ProfFan

@ProfFan
Copy link
Collaborator

ProfFan commented Sep 12, 2024

So it's the G-N optimizer that is failing? @hunkyu is this the same case for you?

I am thinking about an undefined behavior somewhere in the G-N code as it is indeed less battle-tested. But I have no bandwidth now with paper deadlines, so any help is appreciated. Ideally if you could run with ASAN and put the log here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants