A pytorch implementation of Meta$^2$ Learning.
- Python >= 3.5
- Pytorch >= 1.3 and torchvision (https://pytorch.org/)
- You can use the
requirements.txt
file we provide to setup the environment via Anaconda.
conda create --name py36 python=3.6
conda install pytorch torchvision -c pytorch
pip3 install -r requirements.txt
Clone this repository:
git clone https://github.com/jiaxinchen666/Meta2Learning.git
cd CrossDomainFewShot
- Set
DATASET_NAME
to:cars
,cub
,miniImagenet
,flowers
,pets
,fungi
, orplantae
.
cd filelists
python process.py DATASET_NAME
cd ..
For datasets 'vegetable', 'food', and 'butterfly', download vegetable, butterfly, food and extract them into ./filelists/DATASET_NAME
cd filelists
python write_DATASET_filelist.py
cd ..
We adopt baseline++ for MatchingNet, and baseline from CloserLookFewShot for other metric-based frameworks.
Download the pre-trained feature encoders.
cd output/checkpoints
python download_encoder.py
cd ../..
--dataset A DATASET LIST CONSISTING OF TRAINING DOMAINS AND TEST DOMAIN
--n_shot 1/5, --method 'protonet'/'relationnet'/'gnnnet'/'matchingnet', --domain_specific 'True'/'False'(only for M2L)
Baseline
python train_baseline.py --n_shot 5 --testset DATASET_NAME --method METHOD --n_query 16 --mode 'onlytrain';
LFT (Cross-Domain Few-Shot Classification via Learned Feature-Wise Transformation)
python train.py --n_shot 5 --testset DATASET_NAME --method METHOD --n_query 16 --mode 'onlytrain';
M2L
python train_ours.py --n_shot 5 --testset DATASET_NAME --method METHOD --n_query 16 --mode 'onlytrain' --domain_specific 'True' --lr '0.1';
Baseline
python train_baseline.py --n_shot 5 --testset DATASET_NAME --method METHOD --n_query 16 --mode 'onlytest';
LFT (Cross-Domain Few-Shot Classification via Learned Feature-Wise Transformation)
python train.py --n_shot 5 --testset DATASET_NAME --method METHOD --n_query 16 --mode 'onlytest';
M2L
python train_ours.py --n_shot 5 --testset DATASET_NAME --method METHOD --n_query 16 --mode 'onlytest' --domain_specific 'True' --lr '0.1';
M2L (Further adaptation)
python finetune_test.py --n_shot 5 --testset DATASET_NAME --method METHOD --n_query 16;
- This code is built upon the implementation from CrossDomainFewShot and CloserLookFewShot.
- The dataset, model, and code are for non-commercial research purposes only.