Easonyesheng/A2PM-MESA
关于
[CVPR'24 & TPAMI'26 & PR'26] Area to Point Matching Framework
人工智能与机器学习实测星标增长
- 24小时
- 0
- 7天
- 正在收集历史
- 15天
- 正在收集历史
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文
A2PM: Area to Point Matching
Match areas first, then points.
A training-free, plug-and-play framework that boosts any point matcher on high-resolution images and large viewpoint or scale changes.

Resizing the whole image (top) distorts it and loses local detail. A2PM (bottom) first matches areas, runs the point matcher (PM) on each cropped pair, and fuses the results.
This repository is the official, Hydra-based implementation of the A2PM family:
| Method | Venue | Area matching | Links |
|---|---|---|---|
| SGAM | Pattern Recognition 2026 | Semantic prior + geometric consistency | paper · arXiv · early code |
| MESA | CVPR 2024 | SAM area graph + graph-cut energy minimization (this repo ships a training-free variant, MESA-free) |
paper · project |
| DMESA | TPAMI 2026 | Dense area-matching distributions (GMM + EM), ~5× faster than MESA | paper · arXiv · project |
Highlights
- 🔌 Plug-and-play: matcher-agnostic — any point matcher that outputs 2D correspondences can be wrapped as a thin adapter, with no retraining. 7 integrations ship in this repo (SP+SG, LoFTR, ASpanFormer, ELoFTR, DKM, DUSt3R, MASt3R), covering sparse, semi-dense and dense matching.
- 📈 Consistent gains: e.g. +11.2 Pose AUC@5 on MegaDepth-1500 for MASt3R (46.34 → 57.58) with DMESA. See Results.
- 🧩 Modular: every component is a
class+yamlpair, so you can combine area matchers, point matchers and fusion modules with one line of config.
📰 News
- 2025-11: MASt3R can now serve as the coarse matcher for DMESA and MESA-free area matching:
demo_dmesa_mast3r.yaml,demo_mesaf_mast3r.yaml. It significantly improves generalization. Note that MESA-free is relatively slow with MASt3R. - 2025-10: Added support for MASt3R, DUSt3R and ELoFTR, with expected results.
- 2025-01: Added a Windows 11 manual (中文). Thanks @MY-QY!
- 2024-11: Added a single image-pair demo.
- 2024-09: Added SAM2 support for segmentation preprocessing.
🖼️ Qualitative Results

Continuous matching of SGAM (top to bottom: SGAM, SGAM + ASpan, ASpan)

Contents
🛠 Installation
# 1. Clone with submodules (point matchers, SAM and MASt3R are git submodules)
git clone --recursive https://github.com/Easonyesheng/A2PM-MESA
cd A2PM-MESA
# already cloned without --recursive? -> git submodule update --init --recursive
# 2. Create the environment
conda create -n A2PM python=3.8 -y
conda activate A2PM
# 3. Install PyTorch (tested with 2.0.0 + CUDA 11.8; other versions should also work)
pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 torchaudio==2.0.1 \
--index-url https://download.pytorch.org/whl/cu118
# 4. Install the remaining dependencies
pip install -r requirements.txt
[!TIP] On Windows 11, see the step-by-step manual (中文).
MASt3R and DUSt3R need their own environment. See MASt3R & DUSt3R notes.
Pre-trained weights are not included. Download the weights for the point matcher you use and set the path in its conf/point_matcher/*.yaml.
🚀 Quick Start
A sample pair from ETH3D, with SAM results and intrinsics, is included in demo/.
cd scripts
python demo.py +experiment=demo out_path=/path/to/save/results
- Entry point:
scripts/demo.py. Config:conf/experiment/demo.yaml(DMESA + EGAM + SP/SG by default). - Other ready-made pipelines:
conf/experiment/demo_*.yaml, for examplepython demo.py +experiment=demo_eloftr. - Use
geo_area_matcher: gamto draw the matching results.egamneeds camera intrinsics (demo/intrins/). Without intrinsics, usegam. - Your own images need SAM results in
samres/. See Segmentation Preprocessing.
Which part of this README do I need?
| I want to… | Go to |
|---|---|
| check that my environment works | Quick Start |
| reproduce numbers on ScanNet / MegaDepth | Segmentation Preprocessing → Benchmark |
| plug in my own point / area matcher | Configuration Guide |
Segmentation Preprocessing
The area matchers rely on SAM masks, so these must be computed first.
- A forked SAM is provided as a submodule in
SAM/. Install it:cd SAM && pip install -e . && cd .. pip install opencv-python pycocotools matplotlib onnxruntime onnx - Download
sam_vit_h_4b8939.pthintoSAM/. Otherwise, editsam_model_pathinsegmentor/ImgSAMSeg.py. - Run segmentation following the examples in
segmentor/sam_seg.sh.
Using SAM2
- Set
--sam_name SAM2insegmentor/sam_seg.shand set the checkpoint path insegmentor/ImgSAMSeg.py. - SAM2 is faster but tends to produce fewer masks than SAM (issue).
- If you hit a Hydra initialization error, add this to
SAM2/sam2/__init__.py:from hydra.core.global_hydra import GlobalHydra GlobalHydra.instance().clear()
⚙️ Configuration Guide
The code uses Hydra. Each component is a Python class instantiated from a yaml file with the same name, and an experiment file in conf/experiment/ composes them:
conf/
├── dataset/ # ScanNet1500, MegaDepth1500, demo pair → dataloader/
├── area_matcher/ # sem_area_matcher (SGAM), mesa-f, dmesa → area_matchers/
├── point_matcher/ # spsg, loftr, aspan, eloftr, dkm, dust3r, mast3r → point_matchers/
├── geo_area_matcher/ # gam, egam → geo_area_matchers/
├── evaler/ # instance_eval → metric/
└── experiment/ # full pipelines: a2pm_{AM}_{GAM}_{PM}_{dataset}.yaml, demo*.yaml
To add a new component, add a class in the code folder and a yaml with the same name in the config folder.
Dataset
- Dataloaders are provided for ScanNet1500 and MegaDepth1500. Download them following LoFTR and set the paths in
conf/dataset/. - Set the segmentation fields as well:
sem_mode:SAM,SEEMorGTsem_folder: folder containing the segmentation resultssem_post: file extension (ScanNet:npyforSAM,pngforSEEM/GT)
- Add a new dataset with a loader in
dataloader/and a config inconf/dataset/.
Area matching: the core of A2PM
Area matching finds semantic area correspondences, reducing matching redundancy before point matching.
| Area matcher | Code | Config | Notes |
|---|---|---|---|
| SGAM | area_matchers/sem_am.py |
conf/area_matcher/sem_area_matcher.yaml |
paper, early code |
| MESA-free | area_matchers/mesa.py |
conf/area_matcher/mesa-f.yaml |
Training-free MESA. Replaces the learned area similarity with off-the-shelf patch matching (as in DMESA). Easier to use, slightly lower accuracy than the original MESA |
| DMESA | area_matchers/dmesa.py |
conf/area_matcher/dmesa.yaml |
Dense counterpart of MESA, more efficient and flexible |
Point matching
| Type | Matchers |
|---|---|
| Sparse | SuperPoint + SuperGlue |
| Semi-dense | ASpanFormer, LoFTR, ELoFTR |
| Dense | DKM, MASt3R, DUSt3R |
- Adapters live in
point_matchers/(each subclassesAbstractPointMatcherand implements a singlematch()method) with their configs inconf/point_matcher/. The table lists the 7 integrations that ship here, not a closed set — any matcher that outputs 2D correspondences can be added without touching the rest of the pipeline. - The submodules are forks with their internal import paths already fixed, so clone with
--recursive. - Download the pre-trained weights and set their paths in the corresponding
yaml.
MASt3R & DUSt3R notes
- Fetch the nested submodules: run
git submodule update --init --recursiveinsidereconer/mast3r/to getdust3randdust3r/croco. - Create the environment following the MASt3R repo, then:
pip install loguru hydra-core seaborn kornia yacs pytorch-lightning PyMaxFlow - Weights:
conf/point_matcher/mast3r.yamlanddust3r.yamluse the Hugging Face model idsnaver/MASt3R_ViTLarge_BaseDecoder_512_catmlpdpt_metricandnaver/DUSt3R_ViTLarge_BaseDecoder_512_dptby default. These are downloaded automatically the first time you run them. To use local checkpoints (download), setweight_pathto the.pthfile. For MASt3R as the area matcher, also setmast3r_weight_path(an HF id or a local path) in: - Run:
cd scripts && python demo.py +experiment=demo_dmesa_mast3r
Match fusion (Geometry Area Matching)
Matches from all area pairs are fused by geometry area matching:
| Module | Code | Config |
|---|---|---|
| GAM (from SGAM) | geo_area_matchers/gam.py |
conf/geo_area_matcher/gam.yaml |
| EGAM (more effective, needs intrinsics) | geo_area_matchers/egam.py |
conf/geo_area_matcher/egam.yaml |
Evaluation
- Metrics in
metric/: pose estimation AUC, mean matching accuracy (MMA) and area matching accuracy. metric/instance_eval.pyevaluates each pair and is called fromscripts/test_a2pm.py.metric/eval_ratios.pyaggregates the results of a whole benchmark run.
📊 Benchmark
Scripts follow the naming scheme scripts/{area-matcher}-{point-matcher}-{dataset}.sh:
cd scripts
./dmesa-dkm-md.sh # DMESA + DKM on MegaDepth1500
# aggregate metrics; --root_folder is ${project_name}-res from the shell script
python ../metric/eval_ratios.py --root_folder dmesa-dkm-md-eval-res
[!IMPORTANT] Before running a benchmark script, set
exp_root_pathin the.shfile to your clone of this repo, and setout_pathin the correspondingconf/experiment/*.yaml.eval_ratios.pyreads results from<repo>/resby default. If yourout_pathpoints elsewhere, pass--root_path /your/output/root.
The full pipeline is scripts/test_a2pm.py. Switch methods by changing +experiment=... in the shell script.
Results
Relative pose AUC (%) produced by the scripts in this repo. Bold marks the best result in each row.
| Point matcher | Dataset (input size) | Metric | Baseline | + MESA-free | + DMESA |
|---|---|---|---|---|---|
| DKM | ScanNet1500 (640×480) | AUC@5 | 30.26 | 31.64 | 30.96 |
| AUC@10 | 51.51 | 52.80 | 52.41 | ||
| AUC@20 | 69.43 | 70.08 | 69.74 | ||
| MegaDepth1500 (832×832) | AUC@5 | 63.61 | 63.85 | 65.65 | |
| AUC@10 | 76.75 | 77.38 | 78.46 | ||
| AUC@20 | 85.72 | 86.47 | 86.97 | ||
| MASt3R | ScanNet1500 (512×512) | AUC@5 | 28.25 | 32.79 | 34.23 |
| AUC@10 | 51.01 | 55.13 | 56.23 | ||
| AUC@20 | 69.69 | 72.60 | 73.42 | ||
| MegaDepth1500 (512×512) | AUC@5 | 46.34 | 53.98 | 57.58 | |
| AUC@10 | 63.02 | 69.99 | 72.00 | ||
| AUC@20 | 76.50 | 81.80 | 82.86 | ||
| DUSt3R | ScanNet1500 (512×512) | AUC@5 | 15.84 | 20.72 | 23.01 |
| AUC@10 | 32.69 | 39.14 | 42.89 | ||
| AUC@20 | 49.36 | 56.62 | 60.86 | ||
| MegaDepth1500 (512×512) | AUC@5 | 15.99 | 25.94 | 24.48 | |
| AUC@10 | 33.69 | 44.04 | 42.37 | ||
| AUC@20 | 53.51 | 61.83 | 61.04 | ||
| ELoFTR | ScanNet1500 (640×480) | AUC@5 | 22.15 | 23.62 | 23.07 |
| AUC@10 | 41.08 | 42.37 | 41.66 | ||
| AUC@20 | 57.91 | 58.66 | 58.27 |
Configs: conf/experiment/a2pm_{mesa|dmesa}_egam_{dkm|mast3r|dust3r|eloftr}_{megadepth|scannet}.yaml. MASt3R and DUSt3R use 512×512 inputs and ELoFTR uses 640×480, matching their training resolutions. ELoFTR was evaluated on ScanNet1500 only, with official weights.
Notes on reproducibility
- These numbers were obtained before a GAM bug fix in
200e33a. Results from later commits may differ slightly, andalpha_listmay need retuning. - The random seed is fixed to
2(seescripts/test_a2pm.py), whereas the paper did not fix it. DMESA numbers therefore differ slightly from the paper, but the trends are the same. - MESA-free is a little less accurate than the paper version of MESA, but it still improves on the baselines.
- Default parameters are not tuned for each area matcher + point matcher combination. Tuning for a specific dataset or task can improve results further.
📖 Citation
If you find this work useful, please consider citing:
@article{zhang2026dmesa,
title = {MESA: Effective Matching Redundancy Reduction by Semantic Area Segmentation},
author = {Zhang, Yesheng and Shen, Shuhan and Zhao, Xu},
journal = {IEEE Transactions on Pattern Analysis and Machine Intelligence},
volume = {48},
number = {4},
pages = {4454--4472},
year = {2026},
doi = {10.1109/TPAMI.2025.3644296}
}
@inproceedings{zhang2024mesa,
title = {MESA: Matching Everything by Segmenting Anything},
author = {Zhang, Yesheng and Zhao, Xu},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
pages = {20217--20226},
year = {2024}
}
@article{zhang2026sgam,
title = {Searching from Area to Point: A Semantic Guided Framework with Geometric Consistency for Accurate Feature Matching},
author = {Zhang, Yesheng and Zhao, Xu},
journal = {Pattern Recognition},
volume = {179},
pages = {113920},
year = {2026},
doi = {10.1016/j.patcog.2026.113920}
}
🙏 Acknowledgement
This project builds on these excellent works: SAM, SuperPoint + SuperGlue, ASpanFormer, LoFTR, ELoFTR, DKM, DUSt3R, MASt3R and SGAM.
探索相关项目
加载中…