This repository contains the pytorch code for the paper: "Efficient-PrototypicalNet with self knowledge distillation for few-shot learning" Jit Yan Lim, Kian Ming Lim, Shih Yin Ooi, Chin Poo Lee
The code is tested on Windows 10 with Anaconda3 and following packages:
- python 3.7.4
- pytorch 1.3.1
-
Change the path value in the following files to yours:
datasets/mini_imagenet.py
datasets/tiered_imagenet.py
datasets/cifarfs.py
datasets/fc100.py
datasets/omniglot.py
(only change the path in OmniglotFeatures class for extracted features)
-
[Optional] Download the original datasets and put them into corresponding folders:
-
miniImageNet: download from https://drive.google.com/open?id=0B3Irx3uQNoBMQ1FlNXJsZUdYWEE and put in
data/miniImageNet/images
folder. -
tieredImageNet: download from RFS and put in
data/tieredImageNet
folder. -
CIFARFS: download from MetaOptNet and put in
data/cifarfs
folder. -
FC100: download from MTL, extract them into train, val, and test folders and put in
data/fc100
folder. -
Omniglot: the download for Omniglot is automatic when the script executed.
-
-
The extracted features can be downloaded from here or
-
[Optional] The pretrained weights for EfficientNet-B0 can be downloaded from here: miniImageNet, tieredImageNet, and other datasets. Run the below command extract the feature vectors, NAME decide the dataset and PATH define the location to store the extracted features.
python preprocess.py --dataset NAME --save-path PATH
To train on 30-way 1-shot miniImageNet:
python train.py --dataset mini --train-way 30 --shot 1 --save-path ./save/mini_30w1s
To train the 30-way 1-shot miniImageNet with SSKD:
python train_distill.py --dataset mini --train-way 30 --shot 1 --pretrain-path ./save/mini_30w1s --save-path ./save/mini_30w1s_distill
To evaluate on 5-way 1-shot miniImageNet:
python evaluate.py --dataset mini --test-way 5 --shot 1 --save-path ./save/mini_30w1s_distill
To train on N-way 5-shot Omniglot:
python omniglot_train.py --shot 5 --mode 0
python omniglot_train_distill.py --shot 5 --mode 0
To evaluate on N-way 5-shot Omniglot:
python omniglot_train_distill.py --shot 5 --mode 1
If you find this repo useful for your research, please consider citing the paper:
@article{LIM2021327,
title = {Efficient-PrototypicalNet with self knowledge distillation for few-shot learning},
journal = {Neurocomputing},
volume = {459},
pages = {327-337},
year = {2021},
issn = {0925-2312},
doi = {https://doi.org/10.1016/j.neucom.2021.06.090},
url = {https://www.sciencedirect.com/science/article/pii/S0925231221010262},
author = {Jit Yan Lim and Kian Ming Lim and Shih Yin Ooi and Chin Poo Lee}
}
For any questions, please contact:
Jit Yan Lim ([email protected])
Kian Ming Lim ([email protected])
This repo is based on Prototypical Networks, EfficientNet, MetaOptNet, and MTL.