DistillFSS: Synthesizing Few-Shot Knowledge into a Lightweight Segmentation Model
Official implementation of DistillFSS
- π Efficient Inference: No support images needed at test timeβknowledge is distilled directly into the model
- π― Strong Performance: Competitive or superior results compared to state-of-the-art CD-FSS methods
- π Comprehensive Benchmark: New evaluation protocol spanning medical imaging, industrial inspection, and agriculture
- β‘ Scalable: Handles large support sets without computational explosion
Cross-Domain Few-Shot Semantic Segmentation (CD-FSS) seeks to segment unknown classes in unseen domains using only a few annotated examples. This setting is inherently challenging: source and target domains exhibit substantial distribution shifts, label spaces are disjoint, and support images are scarceβmaking standard episodic methods unreliable and computationally demanding at test time.
DistillFSS addresses these constraints through a teacher-student distillation process that embeds support-set knowledge directly into the model's parameters. By internalizing few-shot reasoning into a dedicated layer, our approach eliminates the need for support images during inference, enabling fast, lightweight deployment while maintaining the ability to adapt to novel classes through rapid specialization.
DistillFSS consists of two main components:
- Teacher Network: Processes the support set and encodes class-specific knowledge
- Student Network: Learns to segment without direct access to support images by distilling knowledge from the teacher
The distillation process embeds support-set information into the student's parameters, allowing efficient inference without episodic sampling.
# Clone the repository
git clone https://github.com/pasqualedem/DistillFSS.git
cd DistillFSS
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies and create virtual environment
uv sync
# Activate the environment
source .venv/bin/activate # On Windows: .venv\Scripts\activateOur benchmark includes datasets from diverse domains. Follow the instructions below to download and prepare each dataset:
mkdir -p data/WeedMap
cd data/WeedMap
# Download the zip from the official source
unzip 0_rotations_processed_003_test.zipcd data
kaggle competitions download -c data-science-bowl-2018
unzip data-science-bowl-2018.zip -d data-science-bowl
unzip data-science-bowl/stage1_train.zip -d Nucleuscd data
wget https://datasets.simula.no/downloads/kvasir-seg.zip
unzip kvasir-seg.zipcd data
wget https://prod-dcd-datasets-cache-zipfiles.s3.eu-west-1.amazonaws.com/5rr22hgzwr-1.zip
unzip 5rr22hgzwr-1.zip
mv "lungcancer/Lung cancer segmentation dataset with Lung-RADS class/"* lungcancer
rm -r "lungcancer/Lung cancer segmentation dataset with Lung-RADS class/"mkdir -p data/ISIC
cd data/ISIC
wget https://isic-challenge-data.s3.amazonaws.com/2019/ISIC_2019_Training_GroundTruth.csv
wget https://isic-challenge-data.s3.amazonaws.com/2018/ISIC2018_Task1-2_Training_Input.zip
wget https://isic-challenge-data.s3.amazonaws.com/2018/ISIC2018_Task1_Training_GroundTruth.zip
unzip ISIC2018_Task1-2_Training_Input.zip
unzip ISIC2018_Task1_Training_GroundTruth.zipDownload from Mendeley Data
mkdir -p data/Industrial
cd data/Industrial
wget https://download.scidb.cn/download?fileId=6396c900bae2f1393c118ada -O data.zip
wget https://download.scidb.cn/download?fileId=6396c900bae2f1393c118ad9 -O data.json
unzip data.zip
mv data/* .
rm -r dataTo facilitate benchmarking, pre-trained baseline model checkpoints can be downloaded using the provided script:
Needed for DistillFSS experiments
bash scripts/download_dcama.shNeeded for comparison with other methods
bash scripts/download_baselines.shDistillFSS provides two main entry points for running grid search experiments:
Fine-tune a pre-trained model on support examples for improved performance.
# Sequential execution
python refine.py grid --parameters parameters/refine/DATASET_NAME.yaml
# Parallel execution (creates SLURM scripts)
python refine.py grid --parameters parameters/refine/DATASET_NAME.yaml --parallel
# Only create SLURM scripts without running
python refine.py grid --parameters parameters/refine/DATASET_NAME.yaml --parallel --only_createTrain a student model by distilling knowledge from a teacher network that processes support examples.
python distill.py grid --parameters parameters/distill/DATASET_NAME.yamlThe distillation process:
- Creates a teacher-student architecture
- Trains the student to mimic the teacher's outputs
- Embeds support-set knowledge into the student's parameters
- Evaluates on the test set after distillation
Evaluate the inference speed and efficiency of different models.
python distill.py grid --parameters parameters/speed.yamlThe repository includes pre-configured parameter files organized by experiment type:
Standard baseline experiments for each dataset:
Industrial.yaml- Industrial defect segmentationISIC.yaml- Skin lesion segmentationKVASIR.yaml- Gastrointestinal polyp segmentationLungCancer.yaml- Lung nodule segmentationNucleus.yaml/Nucleus_hdmnet.yaml- Cell nucleus segmentationPothole.yaml- Road defect detectionWeedMap.yaml- Weed segmentation
Teacher-student distillation experiments:
- Configurations for: Industrial, ISIC, KVASIR, LungCancer, Nucleus, Pothole, WeedMap
Fine-tuning experiments on support sets:
- Configurations for: Industrial, ISIC, KVASIR, LungCancer, Nucleus, Pothole, WeedMap, deepglobe
Benchmarking inference speed across models and datasets.
# Run baseline experiments on Industrial dataset
python refine.py grid --parameters parameters/baselines/Industrial.yaml
# Run distillation on KVASIR dataset
python distill.py grid --parameters parameters/distill/KVASIR.yaml
# Run refinement on WeedMap with parallel execution
python refine.py grid --parameters parameters/refine/WeedMap.yaml --parallel
# Run efficiency benchmarks
python distill.py grid --parameters parameters/speed.yaml
# Run experiments on additional datasets
python refine.py grid --parameters parameters/other/EVICAN.yamlDistillFSS achieves competitive or superior performance across multiple domains while significantly reducing computational costs:
Performance comparison (mIoU) against state-of-the-art methods on Medical and Industrial datasets.
| Dataset (Shot k) | Low Shot (k=5, 9, or 10) |
High Shot (k=50, 60, or 80) |
||||
|---|---|---|---|---|---|---|
| BAM | Transfer | Distill | BAM | Transfer | Distill | |
| Lung Nodule (5/50) | 0.17 | 3.43 | 3.31 | 0.19 | 2.51 | 4.87 |
| ISIC (9/60) | 9.67 | 14.35 | 13.31 | 8.69 | 22.15 | 23.41 |
| KVASIR-Seg (5/50) | 18.96 | 45.18 | 37.29 | 23.03 | 59.97 | 57.09 |
| Nucleus (5/50) | 11.03 | 73.12 | 69.57 | 11.05 | 79.39 | 79.96 |
| WeedMap (5/50) | 6.63 | 51.01 | 44.43 | 6.16 | 64.18 | 61.96 |
| Pothole (5/50) | 1.46 | 17.36 | 17.01 | 2.23 | 31.77 | 31.96 |
| Industrial (10/80) | 4.98 | 4.09 | 3.50 | 4.86 | 48.19 | 46.09 |
Detailed results and ablation studies are available in the paper.
DistillFSS/
βββ distill.py # Main distillation entry point
βββ refine.py # Main refinement entry point
βββ configs/ # Configuration files
βββ distillfss/
β βββ data/ # Dataset implementations
β βββ models/ # Model architectures
β βββ utils/ # Utilities (logging, tracking, etc.)
β βββ substitution.py # Support set substitution strategies
βββ data/ # Dataset storage
βββ out/ # Output directory (logs, models, results)
DistillFSS integrates with Weights & Biases for experiment tracking. Configure your W&B credentials before running:
wandb loginTraining metrics, predictions, and model checkpoints are automatically logged to W&B.
Access our collection of state-of-the-art checkpoints:
If you find this work useful for your research, please consider citing:
@misc{marinisDistillFSSSynthesizingFewShot2025,
title = {{DistillFSS}: {Synthesizing} {Few}-{Shot} {Knowledge} into a {Lightweight} {Segmentation} {Model}},
shorttitle = {{DistillFSS}},
url = {http://arxiv.org/abs/2512.05613},
doi = {10.48550/arXiv.2512.05613},
publisher = {arXiv},
author = {Marinis, Pasquale De and Blok, Pieter M. and Kaymak, Uzay and Brussee, Rogier and Vessio, Gennaro and Castellano, Giovanna},
month = dec,
year = {2025},
note = {arXiv:2512.05613 [cs]},This work builds upon several excellent open-source projects and datasets. We thank the authors for making their code and data publicly available.
This project is released under the MIT License. See LICENSE for details.
For questions or collaborations, please contact:
- Pasquale De Marinis - pasquale.demarinis@uniba.it
- GitHub Issues - For bug reports and feature requests
Made with β€οΈ for the Few-Shot Learning community