Official code for the FGVC 2025 workshop paper:
📄 Fine-Grained Few-Shot Classification with Part Matching
This repository contains the official implementation of Simple Matching Parts Learner (SMPL), our proposed method for fine-grained few-shot classification using part-level feature matching. We currently provide code to replicate our experiments on the Hotels-8K dataset, with additional datasets to be released in the future.
We provide precomputed part features for the Hotels-8K dataset using either DINO or DINOv2 as the Part Encoder:
➡️ Dino
➡️ DinoV2
Extract to:
After downloading, extract the file to the following path:
data/
│ └── {dataset}/
│ └── features/
│ └── {dataset}_{part_encoder}.npy
{dataset}: e.g.,hotels{part_encoder}: eitherdinoordinov2
This .npy file is a serialized Python dictionary containing part features for the training, validation, and test sets. Each entry maps an image path to a nested dictionary with two keys:
part_features→ a NumPy array of shape(N + 1, D), whereNis the number of distinct parts in the image andDis the feature dimensionality. The last row is the global image feature.part_indices→ a NumPy array of shape(N + 1,), where each value corresponds to the part ID in the segmentation mask. The final value (for the global feature) is always1000.
You can download the original images and segmentation maps (generated using GroundedSAM) here:
➡️ Download Images and Segmentations
To train the Part Matcher model, run:
python train.py –data_dir data –dataset {dataset} –part_encoder {dino|dinov2}
Training episodes are generated stochastically, sampling between 5–20 ways and 1–5 shots per episode, as described in the paper. Class splits used for episode generation are located at:
data/{dataset}/splits/
By default, the best checkpoint will be saved to:
checkpoints/{dataset}/{part_encoder}/best.pt
To evaluate on 20-way classificatio tasks, run:
python evaluation.py
–dataset {dataset}
–part_encoder {dino|dinov2}
–checkpoint {path_to_model}
–n_shots {1|5}
Evaluation episodes are pre-generated and stored at:
data/{dataset}/test_episodes/20way_{n_shots}shots.json
If you use our work, please cite:
@InProceedings{Black_2025_CVPR,
author = {Black, Samuel and Souvenir, Richard},
title = {Fine-grained Few-Shot Classification with Part Matching},
booktitle = {Proceedings of the Computer Vision and Pattern Recognition Conference (CVPR) Workshops},
month = {June},
year = {2025},
pages = {2057-2067}
}

