This is the code repository for "Task-Adaptive Negative Envision for Few-Shot Open-Set Recognition" (accepted by CVPR 2022).
This repo is tested with Python 3.6, Pytorch 1.8, CUDA 10.1. More recent versions of Python and Pytorch with compatible CUDA versions should also support the code.
MiniImageNet image data are provided by RFS, available at DropBox. We also provide the word embeddings for the class names here. For TieredImageNet, we use the image data and word embeddings provided by AW3, available at GoogleDrive. Download and put them under your <data_dir>.
We provide the pre-trained models for TieredImageNet and MiniImageNet, which can be downloaded here. Save the pre-trained model to <pretrained_model_path>.
An example of training command for 5-way 1-shot FSOR:
python train.py --dataset <dataset> --logroot <log_root> --data_root <data_dir> \
--n_ways 5 --n_shots 1 \
--pretrained_model_path <pretrained_model_path> \
--featype OpenMeta \
--learning_rate 0.03 \
--tunefeat 0.0001 \
--tune_part 4 \
--cosine \
--base_seman_calib 1 \
--train_weight_base 1 \
--neg_gen_type semang
An example of testing command for 5-way 1-shot FSOR:
python test.py --dataset <dataset> --data_root <data_dir> \
--n_ways 5 --n_shots 1 \
--pretrained_model_path <pretrained_model_path> \
--featype OpenMeta \
--test_model_path <test_model_path> \
--n_test_runs 1000 \
--seed <seed>
We also provide the code for the pre-training stage under pretrain
folder. An example of running command for pre-training on miniImageNet:
python batch_process.py --featype EntropyRot --learning_rate 0.05
If you find this repo useful for your research, please consider citing the paper:
@InProceedings{Huang_2022_CVPR,
author = {Huang, Shiyuan and Ma, Jiawei and Han, Guangxing and Chang, Shih-Fu},
title = {Task-Adaptive Negative Envision for Few-Shot Open-Set Recognition},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {June},
year = {2022},
pages = {7171-7180}
}