A simple PyTorch implementation of KTN ( Knowledge Transfer Network ) for FS ( Few-Shot Image Classification ).
(Peng et al., Few-Shot Image Recognition with Knowledge Transfer, ICCV2019)
NOTICE: This is NOT an official implementation by authors of FS-KTN. This version shown here is indicative only, please be subject to the official implementation which may be available soon.
This code is implemented on PyTorch and the experiments were done on a 1080Ti GPU ( batch_size = 64 ). So you may need to install
- Python==3.x
- torch==1.2.0 or above
- torchvision==0.4.0
- torchnet==0.0.4
- tqdm
-
-/Datasets/MiniImagenet/ └─── miniImageNet_category_split_train_phase_train.pickle └─── miniImageNet_category_split_train_phase_val.pickle └─── miniImageNet_category_split_train_phase_test.pickle └─── miniImageNet_category_split_val.pickle └─── miniImageNet_category_split_test.pickle
This repo contains FS-KTN with feature extractors using Conv64 / Conv128 in PyTorch form, see ./models/Conv_model.py.
git clonethis repo.- Prepare data files in
./Datasets/MiniImagenet/. - Set configurations in
Train_only_Vis.py( Training / Valing Config, Model Config, Dataset/Path Config): $ python Train_only_Vis.py --network Conv64/128for generating the weight of Vision-based Classifier. ( tqdm package is required. Other logs are written in<save_dir>/train_log.txt).$ python Test_only_Vis.py --network Conv64/128 --test_nExemplars 1/5for testing only using Vision-based Classifier (Baseline).- Download the following Knowledge Graph for MiniImageNet into
./mini-graphfolder. ( Now we only provide generated Knowledge Graph for MiniImageNet,please refer to DGP for more details about it ). $ python Train_GCN.pyfor generating the weight of Knowledge-based Classifier.$ python Test_Vis_Kno.py --network Conv64 --test_nExemplars 1/5for testing using Vision-Knowledge Classifier.
If this work is useful in your research, please cite
@InProceedings{Peng_2019_ICCV,
author = {Zhimao Peng and Zechao Li and Junge Zhang and Yan Li and Guo{-}Jun Qi and Jinhui Tang},
title = {Few-Shot Image Recognition With Knowledge Transfer},
booktitle = {{ICCV}},
pages = {441--449},
publisher = {{IEEE}},
year = {2019}
} @article{Li_2023_TNNLS,
title = {Knowledge-Guided Semantic Transfer Network for Few-Shot Image Recognition},
author = {Li, Zechao and Tang, Hao and Peng, Zhimao and Qi, Guo-Jun and Tang, Jinhui},
journal = {IEEE Transactions on Neural Networks and Learning Systems},
year = {2023},
publisher = {IEEE},
doi = {10.1109/TNNLS.2023.3240195}
}This implementation builds upon several open-source codes. Specifically, we have modified and integrated the following codes into this repository: