Skip to content

This repository is the code of the paper "Sparse Spatial Transformers for Few-Shot Learning" (SCIENCE CHINA Information Sciences).

License

Notifications You must be signed in to change notification settings

chenhaoxing/SSFormers

Repository files navigation

🌟 Sparse Spatial Transformers for Few-Shot Learning

This code implements the Sparse Spatial Transformers for Few-Shot Learning(SSFormers).

PWC PWC PWC PWC PWC PWC PWC PWC

🔖 Citation

If you find our work useful, please consider citing our work using the bibtex:

@Article{ssformers,
	author  = {Chen, Haoxing and Li, Huaxiong and Li, Yaohui and Chen, Chunlin},
	title   = {Sparse Spatial Transformers for Few-Shot Learning},
	journal = {Sci. China Inf. Sci.},
	year    = {2023},
}

🌴 Prerequisites

  • Linux
  • Python 3.8
  • Pytorch 1.9.1
  • GPU + CUDA CuDNN
  • pillow, torchvision, scipy, numpy

📑 Datasets

Dataset download link:

  • miniImageNet It contains 100 classes with 600 images in each class, which are built upon the ImageNet dataset. The 100 classes are divided into 64, 16, 20 for meta-training, meta-validation and meta-testing, respectively.
  • tieredImageNet TieredImageNet is also a subset of ImageNet, which includes 608 classes from 34 super-classes. Compared with miniImageNet, the splits of meta-training(20), meta-validation(6) and meta-testing(8) are set according to the super-classes to enlarge the domain difference between training and testing phase. The dataset also include more images for training and evaluation (779,165 images in total).
  • CIFAR-FS CIFAR-FS is divided from CIFAR-100, which consists of 60,000 images in 100 categories. The CIFAR-FS is divided into 64, 16 and 20 for training, validation, and evaluation, respectively.
  • FC-100 FC-100 is also divided from CIFAR-100, which is more difficult because it is more diverse. The FC100 uses a split similar to tieredImageNet, where train, validation, and test splits contain 60, 20, and 20 classes. Note: You need to manually change the dataset directory.

Pre-trained backbone

We provide pre-trained backbones at https://pan.baidu.com/s/1v2k-mdCpGLtKnKG5ijYXMw keys: 334q

🍀 Few-shot Classification

  • Train a 5-way 1-shot SSFormers model based on Conv-64F (on miniImageNet dataset):
 python experiments/run_trainer.py  --cfg ./configs/miniImagenet/ST_N5K1_R12.yaml --device 0

Test model on the test set:

python experiments/run_evaluator.py --cfg ./configs/miniImagenet/ST_N5K1_R12.yaml -c ./checkpoint/*/*.pth --device 0

and semi-supervised few-shot learning tasks (with trial t=1).

python experiments/run_semi_trainer.py --cfg ./configs/miniImagenet/ST_N5K1_semi_with_extractor.yaml --device 0 -t 1

python experiments/run_semi_evaluator.py --cfg ./configs/miniImagenet/ST_N5K1_semi_with_extractor.yaml -c ./checkpoints/*/*.pth --device 0

Our code is based on MCL and FEAT.

📧 Contacts

Please feel free to contact us if you have any problems.

Email: haoxingchen@smail.nju.edu.cn

About

This repository is the code of the paper "Sparse Spatial Transformers for Few-Shot Learning" (SCIENCE CHINA Information Sciences).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages