stereo_matching
A unified Python library for stereo depth estimation
Inference - CLI - 3D Visualization - ONNX - Quantization
stereo_matching provides a single, consistent API across 8 model families and 31 registered variant IDs. You can swap RAFT-Stereo, CREStereo, AANet, FoundationStereo, IGEV-Stereo, IGEV++, S2M2, and UniMatch without rewriting your preprocessing or postprocessing code.
It is built around the practical stereo workflow: run inference with one line, inspect models from the CLI, and turn calibrated disparity into depth maps and point clouds with the same library.
Current scope: inference, model/config loading, preprocessing, postprocessing, CLI prediction, reduced-precision inference, ONNX export and quantization, and visualization are implemented. Dataset loaders, a packaged evaluator, trainer classes, and built-in losses are not included yet. Their documentation pages describe custom integration patterns and clearly mark reserved APIs.
Installation
pip install stereo_matching
See docs/dependencies.md for runtime, development, and model-specific dependencies.
Quickstart
The pipeline API is the fastest way to run any registered stereo model:
from stereo_matching import pipeline
pipe = pipeline("stereo-matching", model="raft-stereo")
result = pipe("left.png", "right.png", focal_length=721.5, baseline=0.54)
disparity = result.disparity # np.ndarray, float32, (H, W)
depth_map = result.depth # np.ndarray, float32, (H, W) or None
colored = result.colored_disparity # np.ndarray, uint8, (H, W, 3)
For full control over preprocessing, forward pass, and postprocessing, use Auto Classes:
from stereo_matching import AutoStereoModel, AutoProcessor
import torch
model = AutoStereoModel.from_pretrained("igev-stereo", device="cuda")
processor = AutoProcessor.from_pretrained("igev-stereo")
inputs = processor("left.png", "right.png")
with torch.no_grad():
disparity = model(inputs["left_values"].cuda(), inputs["right_values"].cuda())
result = processor.postprocess(disparity, inputs["original_sizes"], colorize=True)
Or from the command line:
stereo-matching predict --left left.png --right right.png --model raft-stereo
Why use stereo_matching?
1. One API, every model.
Switch from RAFT-Stereo to FoundationStereo or UniMatch by changing a single string. pipeline(), AutoStereoModel, and AutoProcessor keep the calling pattern consistent across families.
2. Consistent model loading.
Registered variants resolve through the same pipeline(), AutoStereoModel, and AutoProcessor entry points, so model selection stays simple even as the registry grows.
3. Self-contained model packages.
Each family lives under src/stereo_matching/models/<family>/ with a config file, a single vendored modeling file, and lazy self-registration in the global registry.
4. Calibrated outputs beyond disparity.
Pass focal_length and baseline once and the library can return metric depth, colorized disparity, and point clouds for export or interactive viewing.
5. Deployment workflows. Cast PyTorch models to FP16/BF16, dynamically quantize linear layers to INT8, or export a two-input ONNX graph and quantize it with ONNX Runtime.
Supported Models
8 model families - 31 registered IDs - see docs/models.md for the full list and per-variant notes.
All families support pipeline(), Auto Classes, and CLI prediction.
| Family | Variants |
|---|---|
| RAFT-Stereo | raft-stereo, raft-stereo-middlebury, raft-stereo-eth3d, raft-stereo-realtime |
| CREStereo | crestereo |
| AANet | aanet, aanet-kitti2012, aanet-sceneflow |
| FoundationStereo | foundation-stereo, foundation-stereo-large |
| IGEV-Stereo | 6 registered IDs (igev-stereo*) |
| IGEV++ | 6 registered IDs (igev-plusplus*) |
| S2M2 | s2m2, s2m2-m, s2m2-l, s2m2-xl |
| UniMatch | 5 registered IDs (unimatch*) |
What can you do?
Inference - single pair, batch, or local script
# Single stereo pair
result = pipe("left.png", "right.png")
# Batch
results = pipe(
["left0.png", "left1.png"],
["right0.png", "right1.png"],
batch_size=2,
)
# CLI prediction
stereo-matching predict --left left.png --right right.png --model raft-stereo --output-dir results/
# Run the demo after selecting variants in its MODELS list
python examples/demo.py
Precision and ONNX - FP16, BF16, INT8, export, and ONNX quantization
from stereo_matching import AutoStereoModel, export_onnx, quantize_onnx
model = AutoStereoModel.from_pretrained("raft-stereo", device="cuda")
export_onnx(model, "raft_stereo.fp32.onnx", input_height=384, input_width=640)
quantize_onnx("raft_stereo.fp32.onnx", "raft_stereo.int8.onnx")
fp16_model = model.quantize("fp16") # direct reduced-precision PyTorch inference
PyTorch dynamic INT8 and ONNX quantization are separate paths. See docs/quantization.md and docs/export.md before deploying reduced-precision models.
Auto Classes - registry-based loading for registered variants
from stereo_matching import AutoStereoModel, AutoProcessor
model = AutoStereoModel.from_pretrained("foundation-stereo", device="cuda")
processor = AutoProcessor.from_pretrained("foundation-stereo")
Use stereo-matching list-models to inspect the full registry and stereo-matching info --model <id> to print a model config from the terminal.
3D Visualization - point clouds, PLY, and GLB export
from stereo_matching import pipeline, viz
import numpy as np
from PIL import Image
pipe = pipeline("stereo-matching", model="raft-stereo")
result = pipe("left.png", "right.png", focal_length=721.5, baseline=0.54)
left_rgb = np.array(Image.open("left.png").convert("RGB"))
viz.point_cloud(
result,
image=left_rgb,
focal_length=721.5,
baseline=0.54,
save_ply="scene.ply",
save_glb="scene.glb",
)
open3d is currently a core dependency and is imported only when its viewer
backend is selected. See docs/pipeline.md for output details.
Model Comparison Demo - hosted Hugging Face Space and local Gradio app
Hosted demo: StereoMatching Compare Demo
pip install gradio gradio_sync3dcompare
python examples/compare_demo.py
The demo runs two stereo models on the same pair and shows disparity and 3D outputs side-by-side in a synchronized viewer.
Documentation
- docs/models.md - families, variants, and checkpoint sources
- docs/pipeline.md -
pipeline(),StereoOutput, and processing details - docs/export.md - two-input ONNX export and runtime inference
- docs/quantization.md - FP16, BF16, PyTorch INT8, and ONNX quantization
- docs/cli.md - implemented commands and the reserved evaluation interface
- docs/dependencies.md - runtime, development, and model-specific requirements
- docs/data.md - custom dataset integration; no bundled loaders yet
- docs/training.md - manual PyTorch training and current limitations
- docs/evaluation.md - metrics and a custom evaluation loop
- docs/adding_a_model.md - registry and package structure
- docs/release_notes.md - released and unreleased changes
Development checks
pip install -e ".[dev]"
ruff check .
pytest tests -m "not slow"
python -m build
twine check dist/*
Mypy is currently advisory. Real pretrained-model inference runs in the weekly slow workflow; see CONTRIBUTING.md.
Adding a New Model
- Create
src/stereo_matching/models/your_model/ - Add
configuration_your_model.py - Add
modeling_your_model.py - Add
__init__.pywithMODEL_REGISTRY.register(...) - Import the package in
src/stereo_matching/__init__.py
AutoStereoModel, AutoProcessor, and pipeline() resolve the new model automatically. See docs/adding_a_model.md for the full pattern.
Acknowledgments
This library builds on the work of 8 stereo matching research families. See docs/models.md#citations for the citation block.
License
MIT
Metadata
Release files for stereo-matching 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| stereo_matching-0.2.0.tar.gz | 119.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stereo_matching-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 246.3 kB
Release files / stereo_matching-0.2.0.tar.gz
| Download URL | stereo_matching-0.2.0.tar.gz |
|---|---|
| Size | 119.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61ab4f68403a2ab9f094c17e77a7476d6e6467e8774a5c6b0339eb0c13c28a15
|
|
BLAKE2b-256 checksum How to use checksums |
df4366b76e77e1618aa2723ab69c7f0e1dd6d000110ab1b6907142f371a1974b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.
Transparency logRelease files / stereo_matching-0.2.0-py3-none-any.whl
| Download URL | stereo_matching-0.2.0-py3-none-any.whl |
|---|---|
| Size | 127.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46bad3ea437d1ad45b99542780049a4e4953b11fbc01b57238ff7954b3378e97
|
|
BLAKE2b-256 checksum How to use checksums |
d8fb1b62c4f40f4f95508f438e3a89af93eedb596a2c280fd47b5126672238ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.
Transparency log