This project implements experiemnts of A. Shekhovtosv "RANSAC Scoring Functions: Analysis and Reality Check" [link and bib to be added].
The project provides tools for training and evaluating learned quality measures for minimal solver hypotheses in the context of homography estimation from point correspondences.
- Python 3.8+
- CUDA-capable GPU (requires)
- PyTorch with CUDA support
- Git
-
Clone the repository:
git clone <repository-url> cd score_learn
-
Create and activate a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Linux/Mac # or venv\Scripts\activate # On Windows
-
Install Python dependencies:
pip install -r requirements.txt
Requirements include:
- matplotlib
- h5py
- opencv-python
- kornia
- scikit-learn
- ipykernel
The default dataset for homography evaluation experiments.
-
Download the HEB dataset:
Download from: https://polybox.ethz.ch/index.php/s/R5sPelZ8688It92 Further infor at: https://github.com/danini/homography-benchmark?tab=readme-ov-file
-
Create a symbolic link to the dataset:
# If dataset is located elsewhere ln -s /path/to/your/HEBHomographyDataset data/HEBHomographyDatasetOr place the dataset directly:
mkdir -p data # Copy/move dataset to data/HEBHomographyDataset/
For additional experiments:
-
Download HPatches:
cd data wget http://icvl.ee.ic.ac.uk/vbalnt/hpatches/hpatches-sequences-release.tar.gz tar -xzf hpatches-sequences-release.tar.gz cd ..
-
Or create symbolic link:
ln -s /path/to/hpatches-sequences-release data/hpatches-sequences-release
The experiments require a patched version of PoseLib with custom homography 4-point solver.
-
Clone PoseLib:
mkdir -p external cd external git clone https://github.com/PoseLib/PoseLib.git cd ../..
-
Apply the patch using the provided script:
# Make the script executable chmod +x apply_poselib_patch.sh # Run the patch script ./apply_poselib_patch.sh
The script will:
- Verify PoseLib directory exists
- Apply the
poselib_homography_4pt.patch - Build and install the patched PoseLib
-
Verify installation:
python -c "import poselib; print('homography_4pt available:', hasattr(poselib, 'homography_4pt'))"Expected output:
homography_4pt available: True
-
Apply patch manually:
cd external/PoseLib patch -p1 < ../../poselib_homography_4pt.patch
-
Build and install:
mkdir -p _build cd _build cmake .. -DCMAKE_BUILD_TYPE=Release make -j$(nproc) cd .. pip install -e . cd ../..
Run homography evaluation on the default dataset (HEB):
python evaluate_H.pyFor complete evaluation with variance analysis and large validation set:
python evaluate_H.py --var --largevalpython evaluate_H.py [OPTIONS]Key Options:
-
--data <dataset>: Dataset name (default:HEB)- Available:
HEB,KITTI,PhotoTourism,scannet,eth3d, etc.
- Available:
-
--var: Enable variance testing (multiple runs for statistical analysis) -
--largeval: Use large validation set for more robust results -
--validate/-V: Recompute validation metrics -
--recompute/-R: Recompute test results (ignore cached results) -
--batch_size <N>: Number of image pairs processed in parallel (default: 8) -
--val_samples <N>: Number of minimal samples for validation (default: 1000) -
--val_pairs <N>: Number of image pairs per scene for validation (default: 1000) -
--val_thresholds <N>: Grid of thresholds for validation (default: 200)
Full evaluation with variance analysis:
python evaluate_H.py --data HEB --var --largevalResults and Figures are saved in the results/<dataset>/ directory:
results/
├── HEB/ # Results for HEB dataset
└── [scene]/*.pkl # Cached evaluation data
└── training_size_*.pdf # Evaluaiton plots for small random validation set series
└── polish0/
└── validation*.pdf # Evaluaiton plots for large validatino set
The h_patches_residuals.py script computes and analyzes Sampson residual distributions from ground-truth inlier correspondences. This is useful for understanding the statistical properties of inliers and fitting mixture models.
Ensure the HPatches dataset is available:
ln -s /path/to/hpatches-sequences-release data/hpatches-sequences-releaseBasic usage:
python h_patches_residuals.pyThe script will:
- Load or process the PhotoTourism dataset residual histogram (if available)
- Process HPatches sequences to compute ground-truth correspondences
- Calculate Sampson residuals for both homography and essential matrix models
- Fit chi-squared mixture models to the residual distributions
- Generate distribution plots with fitted models
Key parameters can be adjusted in the script:
MAX_KEYPOINTS = 2000: Maximum number of SIFT keypoints per imageNN_DIST_THRESHOLD = 5: Maximum distance (pixels) to accept a matchDESCRIPTOR_DISTANCE_THRESHOLD = 400.0: Maximum L2 descriptor distanceHIST_BINS = 100: Number of bins for residual histogramsNUM_MIXTURE_COMPONENTS = 3: Number of chi-squared components in mixtureINCLUDE_I_SEQUENCES = False: Include illumination sequences (i_*)INCLUDE_V_SEQUENCES = True: Include viewpoint sequences (v_*)
Cached results:
data/hpatches-sequences-release/hpatches_symtransfer_stats.npz: Cached residual statistics
Generated figures:
fig/PhotoTourism_dist_F.pdf: Epipolar residual distribution from PhotoTourism datafig/HPatches_dist_H.pdf: Homography residual distribution from HPatchesfig/HPatches_dist_F.pdf: Epipolar residual distribution from HPatches
Console output includes:
- Fitted mixture model parameters (weights and scales)
- Residual statistics (min, median, max, mean, std, percentiles)
- Number of matched correspondences per sequence
Loading descriptor distances from PhotoTourism...
Reconstructed 10000 samples from normalized histogram
Fitted 3-component Chi(1) mixture (F-residuals):
Component 1: weight=0.6411, Chi(1, σ=0.1887)
Component 2: weight=0.2862, Chi(1, σ=0.1887)
Component 3: weight=0.0728, Chi(1, σ=0.1887)
Processing HPatches dataset...
Total matched correspondences: 125483
Sampson residuals summary: {'min': 0.001, 'median': 0.15, 'max': 2.98}
To force recomputation (ignore cache):
# Edit the script and set:
RECOMPUTE_RES = TrueThen run:
python h_patches_residuals.pyFor the epipolar geometry experiments, we used an external data preprocessing. It would be eaasy to replace with a proper loader of the original data and keypoint detector / matcher. The evaluation code has been changing over time and might not be fully funcitonal. It would be possible to fix and document on request.
If you use this code in your research, please cite:
@article{shekhovtsov-25-RANSACA,
title={RANSAC Scoring Functions: Analysis and Reality Check},
author={Shekhovtsov},
booktitle={IJCV},
year={2025},
note={under review}
}Research Use Only License
This software is provided for research and educational purposes only.
- ✅ Permitted: Use, modification, and distribution for academic research and educational purposes
- ✅ Share-Alike: Any modifications or derivative works must be distributed under the same license terms
- ✅ Attribution: You must cite the original work (see Citation section)
- ❌ Not Permitted: Commercial use without explicit permission
For commercial licensing or any commercial applications, please contact the author(s) at:
- Email: [author email address]
- Institution: [author institution]
This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
This project uses PoseLib, which has its own license terms. Please refer to the PoseLib repository for its licensing information.