Home

Awesome

CxGrad - Official PyTorch Implementation

Contextual Gradient Scaling for Few-Shot Learning<br> Sanghyuk Lee, Seunghyun Lee, and Byung Cheol Song<br> In WACV 2022.<br> Paper: https://arxiv.org/abs/2110.10353<br>

<!-- > **Abstract:** *Model-agnostic meta-learning (MAML) is a well-known optimization-based meta-learning algorithm that works well in various computer vision tasks, e.g., few-shot classification. MAML is to learn an initialization so that a model can adapt to a new task in a few steps. However, since the gradient norm of a classifier (head) is much bigger than those of backbone layers, the model focuses on learning the decision boundary of the classifier with similar representation. Furthermore, gradient norms of high-level layers are small than those of the other layers. So, the backbone of MAML usually learns task-generic features, which results in deteriorated adaptation performance in the inner-loop. To resolve or mitigate this problem, we propose contextual gradient scaling (CxGrad), which scales gradient norms of the backbone to facilitate learning task-specific knowledge in the inner-loop. Since the scaling factors are generated from task-conditioned parameters, gradient norms of the backbone can be scaled in a task-wise fashion. Experimental results show that CxGrad effectively encourages the backbone to learn task-specific knowledge in the inner-loop and improves the performance of MAML up to a significant margin in both same- and cross-domain few-shot classification.* -->

Installation

This code is based on PyTorch. Please make a virtual environment and use it by running the command below:

conda env create --file environment.yml -n CxGrad
conda activate CxGrad

Datasets

We provide instructions to download 4 datasets: miniImageNet, tieredImageNet, CUB, and CIFAR-FS. Download the datasets you want to use and move them to datasets.

  1. miniImageNet: Download mini_imagenet_full_size.tar.bz2 from this link, provided in MAML++. Note that by downloading and using the miniImageNet, you accept terms and conditions found in imagenet_license.md.

  2. tieredImageNet: Download tiered_imagenet.tar from this link.

  3. CIFAR-FS: Download cifar100.zip from this link. The splits and the download link are provided by Bertinetto.

  4. CUB: Download CUB_200_2011.tgz from this link. The classes of each split are randomly chosen. Thus, we provide the splits of our experiments: CUB_split_train.txt, CUB_split_val.txt, and CUB_split_test.txt in datasets/preprocess. These splits are done by a script written by Chen.

Then, run the command below to preprocess the datasets you downloaded.

python preprocess/preprocess.py --datasets DATASET1 DATASET2 ...

The structure should be like this:

CxGrad 
  ├── datasets
  |      ├── miniImageNet
  |      |        ├── train
  |      |        ├── val
  |      |        └── test
  |      |── tieredImageNet
  |      |         ├── train
  |      |         ├── val
  |      |         └── test
  |      ├── CIFAR-FS
  |      |       ├── train
  |      |       ├── val
  |      |       └── test
  |      └── CUB
  |           ├── train
  |           ├── val
  |           └── test
  ├── utils
  ├── README.md
  └── ...

Run experiments

Train

Test

Citation

@inproceedings{lee2022contextual,
  title={Contextual Gradient Scaling for Few-Shot Learning},
  author={Lee, Sanghyuk and Lee, Seunghyun and Song, Byung Cheol},
  booktitle={Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision},
  pages={834--843},
  year={2022}
}

Acknowledgments

Thanks to the authors of MAML++ and ALFA, which our work is based on, for their great implementations.