PETAL: Projection-based Episodic Training for Adaptive Learning in Fine-Grained Few-Shot Pollen Fossil Classification
Reference implementation accompanying the PETAL submission. It fine-tunes a light projection head on top of frozen DINOv2 features for few-shot pollen fossil recognition across PF40/PF80 benchmarks.
PETAL(DINOv2-based).py— CLI entry point for training + evaluation.pollen_fewshot/— reusable components (config, data, models, training, evaluation, utilities).Dataset/— PF40 / PF80 JSON specifications and image folders (few-shot splits underOurMethod/few_shot).
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txtThe code automatically downloads the dinov2_vits14_reg backbone from the official Torch Hub repo on first use. Ensure outbound network access the first time you run the script.
-
Prepare specs
JSON files describing the few-shot splits must live underDataset/<benchmark>/OurMethod/few_shot/{train,val,test}.jsonand point to class-specific image directories (relative or absolute). The repo already includes PF40/PF80 specs; adjust or replace as needed. -
Train + evaluate
python PETAL(DINOv2-based).py \ --specs-dir Dataset/PF40/OurMethod/few_shot \ --checkpoint-path checkpoints/pf40_dinov2.pth- Defaults target PF40; switch to PF80 by passing
--specs-dir Dataset/PF80/OurMethod. - Runtime overrides exist for all hyper-parameters (
--n-way,--n-shot,--epochs, etc.). - Use
--skip-spec-checkto skip the post-run inspection that verifies JSON/image consistency.
- Defaults target PF40; switch to PF80 by passing
-
Resume / Evaluate only
Reuse--checkpoint-pathto load the best projection head weights and re-run testing:python PETAL(DINOv2-based).py \ --specs-dir Dataset/PF40/OurMethod/few_shot \ --checkpoint-path checkpoints/pf40_dinov2.pth \ --epochs 0 \ --train-tasks 0
Environment variables POLLEN_FOSSIL_SPECS_DIR and POLLEN_FOSSIL_CHECKPOINT provide alternative defaults when CLI flags are not supplied.
- Training and evaluation automatically run on GPU when CUDA is available; CPU fallback is supported but slow.
- Specs inspection prints the number of classes and a sample of image counts, helping catch broken paths before long experiments.
- The code assumes RGB images; extend
pollen_fewshot/data.pytransforms for other modalities if needed.
Please cite the PETAL paper when referencing this implementation. (BibTeX placeholder)