A comprehensive comparative study of vision foundation models (DINOv2, DINOv3, SAM, CLIP) for semantic correspondence, evaluating their effectiveness in matching keypoints across images with different object instances from the same category.
This project implements and evaluates four state-of-the-art vision foundation models on the semantic correspondence task:
- DINOv2 (Self-supervised Vision Transformer)
- DINOv3 (Enhanced DINO with improved pretraining)
- SAM (Segment Anything Model)
- CLIP (Vision-Language Model)
- Baseline Evaluation: Training-free correspondence using direct feature matching
- Fine-tuning: Selective layer fine-tuning with keypoint supervision using Gaussian Cross-Entropy Loss
- Multiple Matching Strategies:
- Argmax: Direct peak similarity matching
- Windowed Soft-argmax: Refined prediction with local smoothing
- Comprehensive Metrics: PCK (Percentage of Correct Keypoints) evaluation by image and by point
- Three Benchmark Datasets: SPair-71k, PF-PASCAL, PF-WILLOW
The project follows a standard evaluation protocol with four phases:
- Phase 1: Baseline evaluation with pretrained models (argmax matching)
- Phase 2: Fine-tuning of models with keypoint supervision
- Phase 3: Evaluation of baseline and fine-tuned models with windowed soft-argmax matching
- Phase 4: Cross-dataset generalization evaluation
pip install -r requirements.txtDownload the datasets you need under the asset/dataset/ folder.
Use the automated script to download all datasets:
python tools/download_datasets.pyOr download specific datasets:
python tools/download_datasets.py --dataset spair
python tools/download_datasets.py --dataset pfpascal
python tools/download_datasets.py --dataset pfwillow- Download SPair-71k dataset from the official link.
- Extract to
asset/dataset/SPair-71k/
- Download PF-PASCAL dataset from link.
- Rename the outermost directory from
PF-dataset-PASCALtopf-pascal. - Download lists for image pairs from link.
- Place the lists for image pairs under
pf-pascaldirectory.
- Download PF-Willow dataset from the link.
- Rename the outermost directory from
PF-datasettopf-willow. - Download lists for image pairs from link.
- Place the lists for image pairs under
pf-willowdirectory.
asset/
├── dataset/
│ ├── SPair-71k/
│ │ ├── ImageAnnotation/
│ │ ├── JPEGImages/
│ │ ├── Layout/
│ │ ├── PairAnnotation/
│ │ └── ...
│ ├── pf-pascal/
│ │ ├── PF-dataset-PASCAL/
│ │ │ ├── Annotations/
│ │ │ └── JPEGImages/
│ │ ├── test_pairs.csv
│ │ ├── trn_pairs.csv
│ │ └── val_pairs.csv
│ └── pf-willow/
│ ├── PF-dataset/
│ └── test_pairs.csv
└── weights/
├── dinov2/
├── dinov3/
├── sam/
└── clip/
Use the automated script to download all weights:
python tools/download_weights.pyOr download specific models:
python tools/download_weights.py --model dinov2
python tools/download_weights.py --model sam
python tools/download_weights.py --model clipNote: DINOv3 weights must be downloaded manually from the official repository as they require authentication or are not available through direct download links.
Weights can be manually downloaded from the official repositories:
- DINOv2: facebookresearch/dinov2 →
asset/weights/dinov2/ - DINOv3: facebookresearch/dinov3 →
asset/weights/dinov3/ - SAM: facebookresearch/segment-anything →
asset/weights/sam/ - CLIP: openai/CLIP →
asset/weights/clip/
Pre-trained fine-tuned weights (trained on SPair-71k) are available for download:
- Fine-tuned models (DINOv2, SAM, CLIP): Download Link →
asset/weights/{model}/trained/
Note: Fine-tuned DINOv3 weights cannot be publicly distributed due to Meta AI's licensing restrictions on the pretrained model.
All supported models and their variants (including fine-tuned versions with 2, 4, or 6 layers) are defined in their respective adapter classes:
- DINOv2:
src/dinov2_adapter.py- Vision Transformer variants (vits14, vitb14, vitl14) - DINOv3:
src/dinov3_adapter.py- Vision Transformer variants (vits16, vitb16, vitl16) - SAM:
src/sam_adapter.py- Segment Anything Model variants (vitb16, vitl16, vith16) - CLIP:
src/clip_adapter.py- Vision-Language Model variants (vitb32, vitb16, vitl14)
Fine-tuned model architectures are specified using the suffix _ft2, _ft4, or _ft6 (e.g., vits14_ft2) to indicate the number of last layers fine-tuned.
Evaluate pretrained models with argmax matching:
python evaluate.py \
--phase 1 \
--model dinov2 \
--model_arch vits14 \
--dataset spair \
--split test \
--match_method argmaxFor all available evaluation parameters, run:
python evaluate.py --helpAll evaluation configurations are available in config/base.py.
Train models with keypoint supervision using Gaussian Cross-Entropy Loss:
python train.py \
--model dinov2 \
--model_arch vits14 \
--fine_tune_layers 2 \
--dataset spair \
--epochs 3For all available training parameters, run:
python train.py --helpAll training configurations are available in config/base.py.
Fine-tuned weights are saved to: asset/weights/{model}/trained/
After training, evaluate fine-tuned models with argmax matching:
python evaluate.py \
--phase 2 \
--model dinov2 \
--model_arch vits14_ft2 \
--dataset spair \
--split test \
--match_method argmaxEvaluate baseline and fine-tuned models with windowed soft-argmax matching:
# Baseline
python evaluate.py \
--phase 3 \
--model dinov2 \
--model_arch vits14 \
--dataset spair \
--split test \
--match_method windowed_softargmax
# Fine-tuned
python evaluate.py \
--phase 3 \
--model dinov2 \
--model_arch vits14_ft2 \
--dataset spair \
--split test \
--match_method windowed_softargmaxEvaluate baseline and fine-tuned models on PF-Pascal and PF-Willow datasets:
# Baseline
python evaluate.py \
--phase 4 \
--model dinov2 \
--model_arch vits14 \
--dataset pfpascal \
--split test \
--match_method windowed_softargmax
# Fine-tuned
python evaluate.py \
--phase 4 \
--model dinov2 \
--model_arch vits14_ft2 \
--dataset pfwillow \
--split test \
--match_method windowed_softargmaxResults Location: asset/results/{model}/phase{phase}/{arch}/{dataset}/
Generated Reports:
phase{X}_{method}_image_report.txt: PCK by imagephase{X}_{method}_kpt_report.txt: PCK by keypoint
Generate visualizations of semantic correspondence predictions:
python visualization_pairs.py \
--model dinov2 \
--model_arch vitb14 \
--model_arch_tuned vitb14_ft2 \
--dataset spair \
--split test \
--sample_idx 1644 \
--match_method argmax \
--match_method_tuned windowed_softargmaxThis will generate visualizations showing:
- Source and target images
- Ground truth correspondences
- Predicted correspondences (baseline and/or tuned)
Parts of this codebase (dataset loaders, loss function, and evaluation utilities) are adapted from the SD4Match repository.
Paper: "SD4Match: Learning to Prompt Stable Diffusion Model for Semantic Matching" (CVPR 2024)
This project uses the following foundation models:
- DINOv2: facebookresearch/dinov2
- DINOv3: facebookresearch/dinov3
- SAM: facebookresearch/segment-anything
- CLIP: openai/CLIP
This project is for academic and educational purposes only.
Last Updated: January 2026