8000 Enable verbose logging options through command-line flags by ahojnnes · Pull Request #77 · colmap/glomap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Enable verbose logging options through command-line flags #77

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

Merged
merged 2 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions glomap/controllers/global_mapper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ void ExpectEqualReconstructions(const colmap::Reconstruction& gt,

GlobalMapperOptions CreateTestOptions() {
GlobalMapperOptions options;
// Control the verbosity of the global sfm
options.opt_vgcalib.verbose = false;
options.opt_ra.verbose = false;
options.opt_gp.verbose = false;
options.opt_ba.verbose = false;

// Control the flow of the global sfm
options.skip_view_graph_calibration = false;
options.skip_relative_pose_estimation = false;
options.skip_rotation_averaging = false;
Expand Down
3 changes: 3 additions & 0 deletions glomap/controllers/option_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ OptionManager::OptionManager(bool add_project_options) {
Reset();

desc_->add_options()("help,h", "");

AddAndRegisterDefaultOption("log_to_stderr", &FLAGS_logtostderr);
AddAndRegisterDefaultOption("log_level", &FLAGS_v);
}

void OptionManager::AddAllOptions() {
Expand Down
4 changes: 2 additions & 2 deletions glomap/estimators/bundle_adjustment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ bool BundleAdjuster::Solve(const ViewGraph& view_graph,
options_.solver_options.linear_solver_type = ceres::SPARSE_SCHUR;
options_.solver_options.preconditioner_type = ceres::CLUSTER_TRIDIAGONAL;

options_.solver_options.minimizer_progress_to_stdout = options_.verbose;
options_.solver_options.minimizer_progress_to_stdout = VLOG_IS_ON(2);
ceres::Solve(options_.solver_options, problem_.get(), &summary);
if (options_.verbose)
if (VLOG_IS_ON(2))
LOG(INFO) << summary.FullReport();
else
LOG(INFO) << summary.BriefReport();
Expand Down
24 changes: 10 additions & 14 deletions glomap/estimators/global_positioning.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ bool GlobalPositioner::Solve(const ViewGraph& view_graph,
LOG(INFO) << "Solving the global positioner problem";

ceres::Solver::Summary summary;
options_.solver_options.minimizer_progress_to_stdout = options_.verbose;
options_.solver_options.minimizer_progress_to_stdout = VLOG_IS_ON(2);
ceres::Solve(options_.solver_options, problem_.get(), &summary);

if (options_.verbose) {
if (VLOG_IS_ON(2)) {
LOG(INFO) << summary.FullReport();
} else {
LOG(INFO) << summary.BriefReport();
Expand Down Expand Up @@ -143,8 +143,7 @@ void GlobalPositioner::InitializeRandomPositions(
image.cam_from_world.translation = image.Center();
}

if (options_.verbose)
LOG(INFO) << "Constrained positions: " << constrained_positions.size();
VLOG(2) << "Constrained positions: " << constrained_positions.size();
}

void GlobalPositioner::AddCameraToCameraConstraints(
Expand Down Expand Up @@ -178,10 +177,9 @@ void GlobalPositioner::AddCameraToCameraConstraints(
problem_->SetParameterLowerBound(&scale, 0, 1e-5);
}

if (options_.verbose)
LOG(INFO) << problem_->NumResidualBlocks()
<< " camera to camera constraints were added to the position "
"estimation problem.";
VLOG(2) << problem_->NumResidualBlocks()
<< " camera to camera constraints were added to the position "
"estimation problem.";
}

void GlobalPositioner::AddPointToCameraConstraints(
Expand All @@ -194,10 +192,9 @@ void GlobalPositioner::AddPointToCameraConstraints(
// Find the tracks that are relevant to the current set of cameras
const size_t num_pt_to_cam = tracks.size();

if (options_.verbose)
LOG(INFO) << num_pt_to_cam
<< " point to camera constriants were added to the position "
"estimation problem.";
VLOG(2) << num_pt_to_cam
<< " point to camera constriants were added to the position "
"estimation problem.";

if (num_pt_to_cam == 0) return;

Expand All @@ -211,8 +208,7 @@ void GlobalPositioner::AddPointToCameraConstraints(
static_cast<double>(num_cam_to_cam) /
static_cast<double>(num_pt_to_cam);
}
if (options_.verbose)
LOG(INFO) << "Point to camera weight scaled: " << weight_scale_pt;
VLOG(2) << "Point to camera weight scaled: " << weight_scale_pt;

if (loss_function_ptcam_uncalibrated_ == nullptr) {
loss_function_ptcam_uncalibrated_ =
Expand Down
22 changes: 8 additions & 14 deletions glomap/estimators/global_rotation_averaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ void RotationEstimator::SetupLinearSystem(
}
}

if (options_.verbose)
LOG(INFO) << "num_img: " << image_id_to_idx_.size()
<< ", num_dof: " << num_dof;

rotation_estimated_.conservativeResize(num_dof);

// Prepare the relative information
Expand Down Expand Up @@ -204,8 +200,7 @@ void RotationEstimator::SetupLinearSystem(
}
}

if (options_.verbose)
LOG(INFO) << counter << " image pairs are gravity aligned" << std::endl;
VLOG(2) << counter << " image pairs are gravity aligned" << std::endl;

std::vector<Eigen::Triplet<double>> coeffs;
coeffs.reserve(rel_temp_info_.size() * 6 + 3);
Expand Down Expand Up @@ -290,11 +285,11 @@ bool RotationEstimator::SolveL1Regression(
double curr_norm = 0;

ComputeResiduals(view_graph, images);
if (options_.verbose) LOG(INFO) << "ComputeResiduals done ";
VLOG(2) << "ComputeResiduals done";

int iteration = 0;
for (iteration = 0; iteration < options_.max_num_l1_iterations; iteration++) {
if (options_.verbose) LOG(INFO) << "L1 ADMM iteration: " << iteration;
VLOG(2) << "L1 ADMM iteration: " << iteration;

last_norm = curr_norm;
// use the current residual as b (Ax - b)
Expand All @@ -307,7 +302,7 @@ bool RotationEstimator::SolveL1Regression(
return false;
}

if (options_.verbose)
if (VLOG_IS_ON(2))
LOG(INFO) << "residual:"
<< (sparse_matrix_ * tangent_space_step_ -
tangent_space_residual_)
Expand All @@ -332,7 +327,7 @@ bool RotationEstimator::SolveL1Regression(
opt_l1_solver.max_num_iterations =
std::min(opt_l1_solver.max_num_iterations * 2, 100);
}
if (options_.verbose) LOG(INFO) << "L1 ADMM total iteration: " << iteration;
VLOG(2) << "L1 ADMM total iteration: " << iteration;
return true;
}

Expand All @@ -347,8 +342,7 @@ bool RotationEstimator::SolveIRLS(const ViewGraph& view_graph,
llt.analyzePattern(sparse_matrix_.transpose() * sparse_matrix_);

const double sigma = DegToRad(options_.irls_loss_parameter_sigma);
if (options_.verbose)
LOG(INFO) << "sigma: " << options_.irls_loss_parameter_sigma;
VLOG(2) << "sigma: " << options_.irls_loss_parameter_sigma;

Eigen::ArrayXd weights_irls(sparse_matrix_.rows());
Eigen::SparseMatrix<double> at_weight;
Expand All @@ -362,7 +356,7 @@ bool RotationEstimator::SolveIRLS(const ViewGraph& view_graph,
int iteration = 0;
for (iteration = 0; iteration < options_.max_num_irls_iterations;
iteration++) {
if (options_.verbose) LOG(INFO) << "IRLS iteration: " << iteration;
VLOG(2) << "IRLS iteration: " << iteration;

// Compute the weights for IRLS
for (auto& [pair_id, pair_info] : rel_temp_info_) {
Expand Down Expand Up @@ -416,7 +410,7 @@ bool RotationEstimator::SolveIRLS(const ViewGraph& view_graph,
break;
}
}
if (options_.verbose) LOG(INFO) << "IRLS total iteration: " << iteration;
VLOG(2) << "IRLS total iteration: " << iteration;

return true;
}
Expand Down
3 changes: 0 additions & 3 deletions glomap/estimators/global_rotation_averaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ struct RotationEstimatorOptions {

// Flag to use gravity for rotation averaging
bool use_gravity = false;

// Flag whether report the verbose information
bool verbose = false;
};

// TODO: Implement the stratified camera rotation estimation
Expand Down
5 changes: 1 addition & 4 deletions glomap/estimators/optimization_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
namespace glomap {

struct OptimizationBaseOptions {
// Logging control
bool verbose = false;

// The threshold for the loss function
double thres_loss_function = 1e-1;

Expand All @@ -24,7 +21,7 @@ struct OptimizationBaseOptions {
OptimizationBaseOptions() {
solver_options.num_threads = std::thread::hardware_concurrency();
solver_options.max_num_iterations = 100;
solver_options.minimizer_progress_to_stdout = verbose;
solver_options.minimizer_progress_to_stdout = false;
solver_options.function_tolerance = 1e-5;
}
};
Expand Down
17 changes: 5 additions & 12 deletions glomap/estimators/view_graph_calibration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ bool ViewGraphCalibrator::Solve(ViewGraph& view_graph,

// Solve the problem
ceres::Solver::Summary summary;
options_.solver_options.minimizer_progress_to_stdout = options_.verbose;
options_.solver_options.minimizer_progress_to_stdout = VLOG_IS_ON(2);
ceres::Solve(options_.solver_options, problem_.get(), &summary);

// Print the summary only if verbose
if (options_.verbose) {
LOG(INFO) << summary.FullReport();
}
VLOG(2) << summary.FullReport();

// Convert the results back to the camera
CopyBackResults(cameras);
Expand Down Expand Up @@ -132,10 +129,9 @@ void ViewGraphCalibrator::CopyBackResults(
// if the estimated parameter is too crazy, reject it
if (focals_[camera_id] / camera.Focal() > options_.thres_higher_ratio ||
focals_[camera_id] / camera.Focal() < options_.thres_lower_ratio) {
if (options_.verbose)
LOG(INFO) << "NOT ACCEPTED: Camera " << camera_id
<< " focal: " << focals_[camera_id]
<< " original focal: " << camera.Focal();
VLOG(2) << "Ignoring degenerate camera camera " << camera_id
<< " focal: " << focals_[camera_id]
<< " original focal: " << camera.Focal();
counter++;

continue;
Expand All @@ -147,9 +143,6 @@ void ViewGraphCalibrator::CopyBackResults(
// Update the focal length
for (const size_t idx : camera.FocalLengthIdxs()) {
camera.params[idx] = focals_[camera_id];
if (options_.verbose)
LOG(INFO) << "Camera " << idx << " focal: " << focals_[camera_id]
<< std::endl;
}
}
LOG(INFO) << counter << " cameras are rejected in view graph calibration";
Expand Down
0