hanlu-nju / revisiting-UML

The official code repository for "Revisiting Unsupervised Meta-Learning via the Characteristics of Few-Shot Tasks" (TPAMI 2023) in PyTorch.
7 stars 2 forks source link

Revisiting Unsupervised Meta-Learning via the Characteristics of Few-Shot Tasks

The code repository for "Revisiting Unsupervised Meta-Learning via the Characteristics of Few-Shot Tasks"

Overview

We first analyze the factors to meta-train a UML method and propose SES and SNS as two key ingredients towards a strong UML baseline. Then, we propose HMS and TSP-Head to further utilize the characteristic of tasks from different aspects, which additionally improve either lower or higher shots scenarios.

figure of method

Unsupervised Meta Learning Results

Experimental results on few-shot learning datasets with ResNet-12 backbone (Same as this repo). We report average results with 10,000 randomly sampled few-shot learning episodes for stablized evaluation.

MiniImageNet Dataset with ConvNet

(way,shot) (5,1) (5,5) (5,20) (5,50)
baseline 47.43 64.11 72.52 74.72
TSP-Head 47.35 65.10 74.45 77.03
HMS 48.12 65.33 73.31 75.49

MiniImageNet Dataset with ResNet-12

(way,shot) (5,1) (5,5) (5,20) (5,50) checkpoint
baseline 56.74 74.05 81.24 83.04 google drive
TSP-Head 56.99 75.89 83.77 85.72 google drive
HMS 58.20 75.77 82.69 84.41 google drive

Prerequisites

The following packages are required to run the scripts:

Dataset

MiniImageNet Dataset

The MiniImageNet dataset is a subset of the ImageNet that includes a total number of 100 classes and 600 examples per class. We follow the previous setup, and use 64 classes as SEEN categories, 16 and 20 as two sets of UNSEEN categories for model validation and evaluation, respectively.

CUB Dataset

Caltech-UCSD Birds (CUB) 200-2011 dataset is initially designed for fine-grained classification. It contains in total 11,788 images of birds over 200 species. On CUB, we randomly sampled 100 species as SEEN classes, and another two 50 species are used as two UNSEEN sets. We crop all images with given bounding boxes before training. We only test CUB with the ConvNet backbone in our work.

TieredImageNet Dataset

TieredImageNet is a large-scale dataset with more categories, which contains 351, 97, and 160 categoriesfor model training, validation, and evaluation, respectively. The dataset can also be download from here. We only test TieredImageNet with ResNet backbone in our work.

Check this for details of data downloading and preprocessing.

Code Structures

To reproduce our experiments with FEAT, please use train_fsl.py. There are four parts in the code.

Model Training and Evaluation

Please use train.py and follow the instructions below. FEAT meta-learns the embedding adaptation process such that all the training instance embeddings in a task is adapted, based on their contextual task information, using Transformer. The file will automatically evaluate the model on the meta-test set with 10,000 tasks after given epochs.

Arguments

The train.py takes the following command line options (details are in the model/utils.py):

Task Related Arguments

Optimization Related Arguments

Model Related Arguments

Arguments for TSP-Head:

Arguments for HMS:

Other Arguments

Running the command without arguments will train the models with the default hyper-parameter values. Loss changes will be recorded as a tensorboard file.

Training scripts

For example, to train UML baseline with ResNet-12 backbone on MiniImageNet:

$ python train.py --eval_all --unsupervised --batch_size 32 --augment 'AMDIM' --num_tasks 256 --max_epoch 200 --model_class ProtoNet --backbone_class Res12 --dataset MiniImageNet --way 5 --shot 1 --query 5 --eval_query 15 --temperature 1 --temperature2 1 --lr 0.03 --lr_scheduler cosine --gpu 0 --eval_interval 2 --similarity sns

to train TSP-Head with ResNet-12 backbone on MiniImageNet

$ python train.py --eval_all --unsupervised --batch_size 32 --augment 'AMDIM' --num_tasks 256 --max_epoch 200 --model_class TSPHead --backbone_class Res12 --dataset MiniImageNet --way 5 --shot 1 --query 5 --eval_query 15 --temperature 1 --temperature2 1 --lr 0.03 --lr_mul 10 --lr_scheduler cosine --gpu 0 --eval_interval 2 --similarity sns --t_heads 8

to train HMS with ResNet-12 backbone on MiniImageNet

$ python train.py --eval_all --unsupervised --batch_size 32 --augment 'AMDIM' --num_tasks 256 --max_epoch 200 --model_class ProtoNet --backbone_class Res12 --dataset MiniImageNet --way 5 --shot 1 --query 5 --eval_query 15 --balance 0 --temperature 1 --temperature2 1 --lr 0.03 --lr_mul 1 --lr_scheduler cosine --gpu 0 --eval_interval 2 --similarity sns --additional HMS --strength 0.5

Acknowledgment

We thank the following repos providing helpful components/functions in our work.