Create a conda environment and install dependencies:
conda create -y -n torch180 python=3.8
conda activate torch180
pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu111
pip install -r requirements.txt
Follow DATASETS.md to install the datasets from CoOp. Or run the following script(11 datasets, include ImageNet):
bash scripts/data.shDownload the pretrained prompt from the link
And decompress it under the folder prompt_adapter/prompt_tensor_init.
tar -xvf prompt_tensor_init.tarThe running configurations can be modified in configs/dataset.yaml, including shot numbers, visual encoders, and hyperparamters.
For our evauation of 1shot, 2shots, 4shots, 8shots, 16shots, 20shots, YOU NEED to change the shots first and then running the follow script.
Note that the default load_cache and load_pre_feat are False for the first running, which will store the cache model and val/test features in configs/dataset/. For later running, they can be set as True for faster hyperparamters tuning.
For ImageNet dataset:
CUDA_VISIBLE_DEVICES=0 python main_imagenet.py --config configs/imagenet.yamlFor other 10 datasets:
CUDA_VISIBLE_DEVICES=2 python main.py --config configs/oxford_pets.yaml
CUDA_VISIBLE_DEVICES=2 python main.py --config configs/stanford_cars.yaml
CUDA_VISIBLE_DEVICES=3 python main.py --config configs/caltech101.yaml
CUDA_VISIBLE_DEVICES=1 python main.py --config configs/oxford_flowers.yaml
CUDA_VISIBLE_DEVICES=0 python main.py --config configs/fgvc.yaml
CUDA_VISIBLE_DEVICES=3 python main.py --config configs/food101.yaml
CUDA_VISIBLE_DEVICES=1 python main.py --config configs/sun397.yaml
CUDA_VISIBLE_DEVICES=2 python main.py --config configs/ucf101.yaml
CUDA_VISIBLE_DEVICES=1 python main.py --config configs/dtd.yaml
CUDA_VISIBLE_DEVICES=2 python main.py --config configs/eurosat.yamlThis repo benefits from Tip-Adapter and CoOp. Thanks for their wonderful works.