Skip to content

CSer-Tang-hao/FS-KTN

Repository files navigation

FS-KTN.PyTorch

LICENSE Python PyTorch

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.

Performance

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

Usage

Dataset Directory

  • MiniImageNet

    -/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
    

Run

This repo contains FS-KTN with feature extractors using Conv64 / Conv128 in PyTorch form, see ./models/Conv_model.py.

  1. git clone this repo.
  2. Prepare data files in ./Datasets/MiniImagenet/.
  3. Set configurations in Train_only_Vis.py ( Training / Valing Config, Model Config, Dataset/Path Config):
  4. $ python Train_only_Vis.py --network Conv64/128 for generating the weight of Vision-based Classifier. ( tqdm package is required. Other logs are written in <save_dir>/train_log.txt).
  5. $ python Test_only_Vis.py --network Conv64/128 --test_nExemplars 1/5 for testing only using Vision-based Classifier (Baseline).
  6. Download the following Knowledge Graph for MiniImageNet into ./mini-graph folder. ( Now we only provide generated Knowledge Graph for MiniImageNet,please refer to DGP for more details about it ).
  7. $ python Train_GCN.py for generating the weight of Knowledge-based Classifier.
  8. $ python Test_Vis_Kno.py --network Conv64 --test_nExemplars 1/5 for testing using Vision-Knowledge Classifier.

Citation

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}
  }

References

This implementation builds upon several open-source codes. Specifically, we have modified and integrated the following codes into this repository:

About

[ICCV19&TNNLS23, Highly Cited Paper] Few-Shot Image Recognition with Knowledge Transfer

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages