This repository contains implementation of ICML 2023 paper: A Closer Look at Few-shot Classification Again, as well as a Pytorch implementation of Meta-Dataset without any component of TensorFlow. Some features of our implementation of Meta-Dataset:
- Unlike original Meta-Dataset, no dataset conversion to TFrecord is needed; instead we use raw images. This is beneficial for anyone who wants to inspect the dataset manually.
- Unlike other versions of pytorch implementations of Meta-Dataset, we support multi-dataset training for both episodic/non-episodic methods.
- We completely fix the data shuffling problem arised in the original tensorflow implementation of Meta-Dataset (see issue #54), which strongly influences the evaluation results of ILSVRC, Aircraft, Traffic Signs, MSCOCO and Fungi. We solve this problem by randomly selecting data from all images in every episode, which cannot be done easily using the original Meta-Dataset implementation.
Install packages using pip:
$ pip install -r requirements.txt
If you want to use pre-trained CLIP as the feature extractor, then run
$ pip install ftfy regex tqdm
$ pip install git+https://github.com/openai/CLIP.git
All pre-trained models of Table 1 in the ICML 2023 paper can be found here.
Download all datasets of Meta-Dataset and convert some of them (due to change of image file forms, change of color or usage of bounding boxes).
-
Download
ilsvrc2012_img_train.tar
, from the ILSVRC2012 website -
Extract it into
ILSVRC2012_img_train/
, which should contain 1000 files, namedn????????.tar
-
Extract each of
ILSVRC2012_img_train/n????????.tar
in its own directory (expected time: ~30 minutes), for instance:for FILE in *.tar; do mkdir ${FILE/.tar/}; cd ${FILE/.tar/}; tar xvf ../$FILE; cd ..; done
-
Download
images_background.zip
andimages_evaluation.zip
, and extract them into the same directory. -
Launch the conversion script:
python -m prepare_datasets.py \ --data_src_path=<omniglot_source_path> \ --data_dst_path=<omniglot_target_path> \ --process_omniglot=1
where
omniglot_source_path
refers to the directory of raw dataset, andomniglot_target_path
refers to the directory of new converted dataset.
- Download
fgvc-aircraft-2013b.tar.gz
and extract it into a directory. - Launch the conversion script:
python -m prepare_datasets.py \ --data_src_path=<aircraft_source_path> \ --data_dst_path=<aircraft_target_path> \ --process_aircraft=1
where aircraft_source_path
refers to the directory of raw dataset, and aircraft_target_path
refers to the directory of new converted dataset.
Download CUB_200_2011.tgz
and extract it.
Download dtd-r1.0.1.tar.gz
and extract it.
-
Download all 345
.npy
files hosted on Google Cloud into the same directory. You can usegsutil
to download them:```bash gsutil -m cp gs://quickdraw_dataset/full/numpy_bitmap/*.npy $DATASRC/<quickdraw_source_path> ```
-
Launch the conversion script:
python -m prepare_datasets.py \ --data_src_path=<quickdraw_source_path> \ --data_dst_path=<quickdraw_target_path> \ --process_DuickD=1
where
quickdraw_source_path
refers to the directory of raw dataset, andquickdraw_target_path
refers to the directory of new converted dataset.
Download fungi_train_val.tgz
and
train_val_annotations.tgz
, then extract them into the same directory. It should contain one
images/
directory, as well as train.json
and val.json
.
Download 102flowers.tgz
and
imagelabels.mat
, then extract 102flowers.tgz
, it will create a jpg/
sub-directory
- Download
GTSRB_Final_Training_Images.zip
If the link happens to be broken, browse the GTSRB dataset website for more information. Then extract it, which will create aGTSRB/
sub-directory. - Launch the conversion script:
where
python -m prepare_datasets.py \ --data_src_path=<traffic_source_path> \ --data_dst_path=<traffic_target_path> \ --process_traffic=1
traffic_source_path
refers to the directory of raw dataset, andtraffic_target_path
refers to the directory of new converted dataset.
- Download
train2017.zip
andannotations_trainval2017.zip
and extract them into the same directory. - Launch the conversion script:
where
python -m prepare_datasets.py \ --data_src_path=<coco_source_path> \ --data_dst_path=<coco_target_path> \ --process_coco=1
coco_source_path
refers to the directory of raw dataset, andcoco_target_path
refers to the directory of new converted dataset.
- Download
t10k-images-idx3-ubyte.gz
andt10k-labels-idx1-ubyte.gz
into the same directory. - Launch the conversion script:
where
python -m prepare_datasets.py \ --data_src_path=<mnist_source_path> \ --data_dst_path=<mnist_target_path> \ --process_mnist=1
mnist_source_path
refers to the directory of raw dataset, andmnist_target_path
refers to the directory of new converted dataset.
- Download
cifar-10-python.tar.gz
and extract it. - Launch the conversion script:
where
python -m prepare_datasets.py \ --data_src_path=<cifar10_source_path> \ --data_dst_path=<cifar10_target_path> \ --process_CIFAR10=1
cifar10_source_path
refers to the directory of raw dataset, andcifar10_target_path
refers to the directory of new converted dataset.
- Download
cifar-100-python.tar.gz
and extract it. - Launch the conversion script:
where
python -m prepare_datasets.py \ --data_src_path=<cifar100_source_path> \ --data_dst_path=<cifar100_target_path> \ --process_CIFAR100=1
cifar100_source_path
refers to the directory of raw dataset, andcifar100_target_path
refers to the directory of new converted dataset.
Download miniImageNet.zip and extract it.
Experiments are defined via yaml files with the help of YACS package, following Swin Transformer. The basic configurations are defined in config.py
, overwritten by yaml files. yaml files can be written by python files, and we give examples for training CE models, training PN models, testing a pre-trained model, and seaching for hyperparameters for finetuning methods in write_yaml_CE.py
, write_yaml_PN.py
, write_yaml_test.py
and write_yaml_search.py
, respectively. Exemplar running scripts can be found in train.sh
.
If you find our work useful in your research please consider citing:
@inproceedings{
Luo2023closerlook,
title={A Closer Look at Few-shot Classification Again},
author={Luo, Xu and Wu, Hao and Zhang, Ji and Gao, Lianli and Xu, Jing and Song, Jingkuan},
booktitle={International Conference on Machine Learning},
year={2023},
}
Part of the code is from SwinTransformer, DeepEMD, RFS, LightningFSL, S2M2, eTT, URL and TSA and BiT.