Skip to content

Commit 78cc729

Browse files
authored
Fix default prior_position_loss_scale to sqrt(chi2_95_3dof) (colmap#4936)
## Problem `IncrementalPipelineOptions::prior_position_loss_scale` and `IncrementalMapper::Options::prior_position_loss_scale` default to `7.815` ($\chi^2_{0.95, 3}$), drifting from `CeresPosePriorBundleAdjustmentOptions::prior_position_loss_scale` (`std::sqrt(kChiSquare95ThreeDof)` $\approx 2.795$) and overriding it in `IncrementalMapper::AdjustGlobalBundle`. Because Ceres loss functions (`CauchyLoss(a)`, `HuberLoss(a)`, `SoftLOneLoss(a)`) apply `a` to the whitened residual norm ($\rho(s)$ at $s = \|r\|^2$ with scale $a^2$), passing $a = 7.815$ moves the robust transition to $\approx 7.8\sigma$ instead of the intended 95% 3-DOF threshold $\sqrt{\chi^2_{0.95, 3}} \approx 2.795$. ## Fix - Align the default `prior_position_loss_scale` in `IncrementalPipelineOptions` and `IncrementalMapper::Options` with `CeresPosePriorBundleAdjustmentOptions` (`std::sqrt(kChiSquare95ThreeDof)`). - Update the comments and `pycolmap` docstrings (including the stale `CeresPosePriorBundleAdjustmentOptions` docstring) to match `2.795`. ## Tests - `IncrementalPipelineOptions.DefaultPriorPositionLossScale` (`src/colmap/controllers/incremental_pipeline_test.cc`) verifies that the pipeline, mapper, and Ceres pose-prior BA defaults match `std::sqrt(kChiSquare95ThreeDof)`. <sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
1 parent 2a6f695 commit 78cc729

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎src/colmap/controllers/incremental_pipeline.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
#pragma once
44

5+
#include "colmap/math/math.h"
56
#include "colmap/scene/camera.h"
67
#include "colmap/scene/reconstruction_manager.h"
78
#include "colmap/sfm/incremental_mapper.h"
89
#include "colmap/util/base_controller.h"
910
#include "colmap/util/hash_containers.h"
1011

12+
#include <cmath>
1113
#include <filesystem>
1214
#include <memory>
1315
#include <string>
@@ -139,8 +141,8 @@ struct IncrementalPipelineOptions {
139141
bool use_robust_loss_on_prior_position = false;
140142

141143
// Threshold on the residual for the robust position prior loss
142-
// (chi2 for 3DOF at 95% = 7.815).
143-
double prior_position_loss_scale = 7.815;
144+
// (sqrt of chi2 for 3DOF at 95% = 2.795).
145+
double prior_position_loss_scale = std::sqrt(kChiSquare95ThreeDof);
144146

145147
// Path to a folder with reconstruction snapshots during incremental
146148
// reconstruction. Snapshots will be saved according to the specified

‎src/colmap/controllers/incremental_pipeline_test.cc‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,17 @@ TEST(IncrementalPipeline, PriorBasedSfMWithRandomSeedStability) {
698698
ReconstructionEq(*reconstruction_manager1->Get(0)));
699699
}
700700

701+
TEST(IncrementalPipelineOptions, DefaultPriorPositionLossScale) {
702+
const IncrementalPipelineOptions options;
703+
EXPECT_DOUBLE_EQ(options.prior_position_loss_scale,
704+
std::sqrt(kChiSquare95ThreeDof));
705+
EXPECT_DOUBLE_EQ(IncrementalMapper::Options().prior_position_loss_scale,
706+
std::sqrt(kChiSquare95ThreeDof));
707+
EXPECT_DOUBLE_EQ(
708+
CeresPosePriorBundleAdjustmentOptions().prior_position_loss_scale,
709+
std::sqrt(kChiSquare95ThreeDof));
710+
}
711+
701712
TEST(IncrementalPipelineOptions, DefaultSolverThresholds) {
702713
const IncrementalPipelineOptions options;
703714
const CeresBundleAdjustmentOptions defaults;

‎src/colmap/sfm/incremental_mapper.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
#pragma once
44

55
#include "colmap/estimators/bundle_adjustment.h"
6+
#include "colmap/math/math.h"
67
#include "colmap/scene/camera.h"
78
#include "colmap/scene/database_cache.h"
89
#include "colmap/scene/reconstruction.h"
910
#include "colmap/sfm/incremental_triangulator.h"
1011
#include "colmap/sfm/observation_manager.h"
1112
#include "colmap/util/hash_containers.h"
1213

14+
#include <cmath>
15+
1316
namespace colmap {
1417

1518
// Class that provides all functionality for the incremental reconstruction
@@ -123,8 +126,8 @@ class IncrementalMapper {
123126
bool use_robust_loss_on_prior_position = false;
124127

125128
// Threshold on the residual for the robust loss
126-
// (chi2 for 3DOF at 95% = 7.815)
127-
double prior_position_loss_scale = 7.815;
129+
// (sqrt of chi2 for 3DOF at 95% = 2.795).
130+
double prior_position_loss_scale = std::sqrt(kChiSquare95ThreeDof);
128131

129132
// Number of threads.
130133
int num_threads = -1;

‎src/pycolmap/estimators/bundle_adjustment.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ void BindBundleAdjuster(py::module& m) {
371371
"Loss function for prior position loss.")
372372
.def_readwrite("prior_position_loss_scale",
373373
&CeresPosePriorBAOpts::prior_position_loss_scale,
374-
"Threshold on the residual for the robust loss (chi2 "
375-
"for 3DOF at 95% = 7.815).")
374+
"Threshold on the residual for the robust loss (sqrt "
375+
"of chi2 for 3DOF at 95% = 2.795).")
376376
.def("check", &CeresPosePriorBAOpts::Check);
377377
MakeDataclass(PyCeresPosePriorBundleAdjustmentOptions);
378378

‎src/pycolmap/sfm/incremental_mapper.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void BindIncrementalPipeline(py::module& m) {
204204
.def_readwrite("prior_position_loss_scale",
205205
&Opts::prior_position_loss_scale,
206206
"Threshold on the residual for the robust position prior "
207-
"loss (chi2 for 3DOF at 95% = 7.815).")
207+
"loss (sqrt of chi2 for 3DOF at 95% = 2.795).")
208208
.def_readwrite("snapshot_path",
209209
&Opts::snapshot_path,
210210
"Path to a folder in which reconstruction snapshots will "

0 commit comments

Comments
 (0)