In the realm of few-shot learning, where the challenge lies in training models with limited data, innovative techniques are constantly emerging. One such promising approach is Frequency Guidance, and its impact on improving model performance is significant. This article introduces the code repository associated with the research paper “Frequency Guidance Matters in Few-shot Learning,” accepted at the prestigious International Conference on Computer Vision (ICCV) 2023. For researchers and practitioners interested in implementing and exploring frequency guidance in their few-shot learning projects, this repository on GitHub provides a valuable resource.
This repository offers a PyTorch implementation of the Frequency Guided Few-shot Learning (FGFL) method detailed in the research paper. By leveraging frequency domain information, FGFL enhances the ability of models to generalize from a few examples to novel classes. This approach is particularly relevant in scenarios where data is scarce, a common bottleneck in many real-world applications of machine learning.
If you utilize the code or concepts from this repository in your research or projects, please acknowledge the original work by citing the following BibTeX entry:
@inproceedings{cheng2023frequency, title={Frequency guidance matters in few-shot learning}, author={Cheng, Hao and Yang, Siyuan and Zhou, Joey Tianyi and Guo, Lanqing and Wen, Bihan}, booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision}, pages={11814--11824}, year={2023} }
Overall Framework of FGFL
The FGFL framework integrates frequency guidance into the few-shot learning process. It aims to improve feature representation and meta-learning by incorporating frequency domain information. The architecture is designed to be modular and adaptable, allowing for integration with various existing few-shot learning methods.
This framework image visually represents the key components and flow of the FGFL method. It highlights how frequency guidance is incorporated to enhance feature learning and improve generalization in few-shot scenarios.
Prerequisites for Running the Code
To ensure smooth execution of the provided scripts, the following software packages are required. Please install these prerequisites before attempting to run the code:
- [List of required Python packages and versions – This section would be populated with the actual list from the original repo’s README or requirements file. For now, placeholders like
PyTorch (>=version)
,torchvision (>=version)
,numpy (>=version)
,scipy (>=version)
, etc. would be listed based on common ML project needs. Assume these are standard packages for a PyTorch based project.]- PyTorch (>= 1.8)
- torchvision (>= 0.9)
- numpy (>= 1.18)
- scipy (>= 1.6)
- [Add any other specific libraries mentioned in the original repo documentation]
Detailed installation instructions for these packages can typically be found on their respective official websites or through package managers like pip
or conda
.
Datasets for Few-Shot Learning Experiments
This repository supports experiments on several benchmark datasets commonly used in few-shot learning research. Before running the code, please download the necessary datasets and organize them in the specified directory structure.
Download the datasets to the "./data/[name of the dataset]"
folder. Ensure to update the data paths within the 'dataloader'
directory in the code to reflect your local setup.
MiniImageNet Dataset
MiniImageNet, a widely used dataset for few-shot learning, is a subset of ImageNet. It comprises 100 classes, with 600 examples per class. Following established protocols in few-shot learning, the dataset is split into training, validation, and testing sets. Specifically, 64 classes are designated as SEEN categories for training, while 16 and 20 classes are reserved as UNSEEN categories for validation and evaluation, respectively. This split ensures rigorous testing of a model’s ability to generalize to novel categories.
CUB Dataset (Caltech-UCSD Birds 200-2011)
The Caltech-UCSD Birds (CUB) 200-2011 dataset is designed for fine-grained image classification, featuring 11,788 bird images across 200 species. For few-shot learning experiments, a specific split is utilized: 100 randomly selected species form the SEEN classes, and two sets of 50 species each are used as UNSEEN sets for validation and testing. Prior to training, all images are preprocessed by cropping them using provided bounding box annotations, focusing the model on the relevant bird regions. The data split used in the paper is available on Google Drive, facilitating reproducibility of the research findings.
TieredImageNet Dataset
TieredImageNet is a larger-scale dataset designed to address the limitations of MiniImageNet by offering a greater number of categories. It includes 351 categories for training, 97 for validation, and 160 for evaluation. The increased scale and diversity of categories in TieredImageNet provide a more challenging and realistic benchmark for evaluating few-shot learning algorithms. The dataset can be downloaded from the provided GitHub repository, making it readily accessible for researchers.
FS-DomainNet Dataset
FS-DomainNet is derived from the DomainNet dataset, specifically reorganized for few-shot domain generalization studies. It includes 299 sub-classes with a minimum of 20 samples per class across six distinct domains: Sketch, Quickdraw, Real, Painting, Clipart, and Infograph. This dataset is particularly valuable for evaluating the robustness of few-shot learning models across different visual domains. The split into training (191 classes), validation (47 classes), and evaluation (61 classes) is designed to assess cross-domain few-shot learning capabilities. Data splits are available through both BaiduYun and Google Drive for convenient access.
The expected dataset directory structure should be as follows:
├── data
├── mini-imagenet
├── split
├── train.csv
├── test.csv
├── val.csv
├── images
├── tiered-imagenet
├── test_images.npz
├── test_labels.pkl
├── train_images.npz
├── train_labels.pkl
├── val_images.npz
├── val_labels.pkl
├── cub
├── split
├── train.csv
├── test.csv
├── val.csv
├── images
├── domainnet
├── split
├── xxx_train.txt
├── xxx_test.txt
├── xxx_val.txt ... xxx={clipart, infograph, painting, quickdraw, real, sketch}
├── images
├── sketch
├── quickdraw
├── real
├── painting
├── clipart
├── infograph
This structured directory ensures that the data loading scripts can correctly locate and access the datasets during training and evaluation.
Model Training and Evaluation Procedures
The primary script for training and evaluating models is train_fsl.py
. Follow the instructions below to execute training and evaluation runs.
Training Scripts for FGFL (using FEAT as the base few-shot method)
The following are example commands to train FGFL models, specifically using FEAT (Few-shot Embedding Adaptation for Transfer Learning) as the base few-shot learning method. These examples demonstrate training on MiniImageNet and TieredImageNet datasets with a ResNet-12 backbone.
Training FGFL with FEAT on MiniImageNet:
For 1-shot, 5-way few-shot learning:
python train_fsl.py --model_class GAIN_Feat --shot 1 --lr 0.0002 --step_size 20 --eval_shot 1 --init_weights2 ./saves/mini_proto_freq/1-shot.pth --use_euclidean --init_weights ./saves/mini_feat/feat-1-shot.pth --tag 1s
For 5-shot, 5-way few-shot learning:
python train_fsl.py --model_class GAIN_Feat --shot 5 --lr 0.00005 --step_size 10 --eval_shot 5 --init_weights2 ./saves/mini_proto_freq/5-shot.pth --use_euclidean --init_weights ./saves/mini_feat/feat-5-shot.pth --max_epoch 200 --lr_mul 1 --temperature2 32 --balance 0.01 --tag 5s
Training FGFL with FEAT on TieredImageNet:
For 1-shot, 5-way few-shot learning:
python train_fsl.py --model_class GAIN_Feat --shot 1 --lr 0.0001 --step_size 10 --eval_shot 1 --init_weights2 ./saves/tiered_proto_freq/tiered-pre.pth --use_euclidean --init_weights ./saves/tiered_feat/feat-1-shot.pth --dataset TieredImageNet --balance 0.01 --tag 1s
For 5-shot, 5-way few-shot learning:
python train_fsl.py --model_class GAIN_Feat --shot 5 --lr 0.0001 --step_size 20 --eval_shot 5 --init_weights2 ./saves/tiered_proto_freq/tiered-pre.pth --use_euclidean --init_weights ./saves/tiered_feat/feat-5-shot.pth --dataset TieredImageNet --balance 0.1 --temperature2 32 --tag 5s
These commands illustrate how to train FGFL models with different shot settings, learning rates, and datasets. Users can adapt these scripts and parameters for further experimentation and fine-tuning based on their specific needs and computational resources. Key parameters include --model_class
to specify the model architecture, --shot
for the number of support examples, --lr
for the learning rate, and --dataset
to choose the dataset.
Acknowledgment of Resources
This research code builds upon publicly available codebases. We gratefully acknowledge the developers and contributors of these repositories for providing valuable components and functions that have aided in this work. [Specific repositories or papers that the code builds upon could be listed here, if mentioned in the original README or paper. For example: “We thank the authors of [Repo 1 link] and [Repo 2 link] for their publicly available code which we have adapted and utilized in this project.” ]