feat: add optional random seed to the Python estimators - #48
Draft
f-dy wants to merge 1 commit into
Draft
Conversation
f-dy
added a commit
to f-dy/magsac
that referenced
this pull request
May 31, 2026
Adds a 'seed' argument (default -1 = nondeterministic) to all 14 find* estimators. When seed >= 0 the run is reproducible: a shared helper (applyMagsacSeed) sets UniformRandomGenerator::setGlobalSeed(seed) for all URG-based samplers and std::srand(seed) for the std::rand()/Eigen::Random solver paths. Bumps the graph-cut-ransac submodule to include setGlobalSeed/clearGlobalSeed. Combines danini#48 (seed for the pre-existing estimators) and danini/graph-cut-ransac#51 (the seed mechanism), extended to the new estimators added in danini#45 (incl. findPlane3D).
f-dy
marked this pull request as ready for review
May 31, 2026 22:22
f-dy
marked this pull request as draft
May 31, 2026 22:41
Adds a 'seed' argument (default -1 = nondeterministic) to findHomography, findFundamentalMatrix, findEssentialMatrix, findRigidTransformation and findLine2D. When seed >= 0 the run is reproducible: UniformRandomGenerator::setGlobalSeed(seed) makes all URG-based samplers (Uniform/PROSAC/P-NAPSAC/Importance) deterministic, and std::srand(seed) covers the samplers/solvers that use std::rand()/Eigen::Random. seed < 0 restores the previous std::random_device behavior. Depends on graph-cut-ransac#51 (adds UniformRandomGenerator::setGlobalSeed). The submodule bump to that commit is intentionally not included here; it should be applied once #51 is merged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add optional random seed to the Python estimators
What
Adds a
seedargument (default-1= nondeterministic, unchanged behavior) tothe five Python estimators in
bindings.cpp:findHomography,findFundamentalMatrix,findEssentialMatrix,findRigidTransformation,findLine2DWhy
There is currently no way to make MAGSAC/MAGSAC++ runs reproducible, which makes
debugging non-deterministic results difficult. A fixed seed gives repeatable
sampling.
How
A small helper sets the seed before the estimator builds its sampler:
setGlobalSeedmakes allUniformRandomGenerator-based samplers(Uniform / PROSAC / Progressive-NAPSAC / Importance) deterministic.
std::srand(seed)covers the samplers/solvers that usestd::rand()/Eigen::…::Random()(AdaptiveReorderingSampler, PnP bundle-adjustment,DLS/SIFT solvers).
seed < 0restores the previousstd::random_devicebehavior.This PR depends on danini/graph-cut-ransac#51
("add a process-wide random seed to
UniformRandomGenerator"), which introducesUniformRandomGenerator::setGlobalSeed/clearGlobalSeed.The submodule bump to the gcransac commit carrying #51 is intentionally not
included in this PR (to keep the diff minimal and avoid pinning a fork commit).
It should be applied once #51 is merged into
graph-cut-ransacmaster. Untilthen this branch will not compile against the currently-pinned submodule.
Scope / follow-up
Covers the five estimators present on
master. The additional estimators addedin #45 (plane, PnP, radial homography, affine/essential variants) get the same
seedparameter in a follow-up once #45 lands.