Home

Awesome

CoPrompt

Official implementation of our ICLR 2024 paper:

Consistency-guided Prompt Learning for Vision-Language Models <br> Shuvendu Roy, Ali Etemad<br> In Proceedings of the International Conference on Learning Representation (ICLR 2024)

paper

<hr />

Base-to-novel generalization:

PWC PWC PWC PWC PWC PWC PWC PWC PWC PWC PWC

Domain Generalization:

PWC PWC PWC

<hr /> <p align="center"> <img src="assets/overview.png" alt="Comparison between the CoPompt and existing prompting approach" width="500"/> </p>

Installation

# Installation borrowed from https://github.com/muzairkhattak/multimodal-prompt-learning
# Create a conda environment
conda create -y -n coprompt python=3.8

# Activate the environment
conda activate coprompt

# Install torch (requires version >= 1.8.1) and torchvision
# Please refer to https://pytorch.org/ if you need a different cuda version
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html


# Clone this repo
git clone https://github.com/KaiyangZhou/Dassl.pytorch.git
cd Dassl.pytorch/

# Install dependencies
pip install -r requirements.txt

# Install this library (no need to re-build if the source code is modified)
python setup.py develop
cd ..

# Clone CoPrompt code base
git clone https://github.com/ShuvenduRoy/CoPrompt

cd CoPrompt
# Install requirements

pip install -r requirements.txt

# Update setuptools package
pip install setuptools==59.5.0

Dataset

Please follow the CoOp repo to prepare the datasets. Set your data directory in the scripts/base2new_train_coprompt.sh and scripts/base2new_train_coprompt.sh file.

Running the experiments

exp_name=CoPrompt
trainer=CoPrompt
train_bash=scripts/base2new_train_coprompt.sh
test_bash=scripts/base2new_test_coprompt.sh

export PYTHONPATH="$PYTHONPATH:$PWD"


for seed in 1 2 3
do
  bash $train_bash fgvc_aircraft $seed $exp_name
  bash $test_bash fgvc_aircraft $seed $exp_name  8

  bash $train_bash dtd $seed $exp_name
  bash $test_bash dtd $seed $exp_name  8

  bash $train_bash ucf101 $seed $exp_name
  bash $test_bash ucf101 $seed $exp_name  8

  bash $train_bash eurosat $seed $exp_name
  bash $test_bash eurosat $seed $exp_name  8

  bash $train_bash caltech101 $seed $exp_name
  bash $test_bash caltech101 $seed $exp_name  8

  bash $train_bash oxford_pets $seed $exp_name
  bash $test_bash oxford_pets $seed $exp_name  8

  bash $train_bash stanford_cars $seed $exp_name
  bash $test_bash stanford_cars $seed $exp_name  8

  bash $train_bash oxford_flowers $seed $exp_name
  bash $test_bash oxford_flowers $seed $exp_name  8

  bash $train_bash food101 $seed $exp_name
  bash $test_bash food101 $seed $exp_name  5

  bash $train_bash sun397 $seed $exp_name
  bash $test_bash sun397 $seed $exp_name  8

  bash $train_bash imagenet $seed $exp_name
  bash $test_bash imagenet $seed $exp_name  8
done

Results

CoPrompt in comparison with existing methods

Results reported below show accuracy for base and novel classes for across 11 recognition datasets averaged over 3 seeds.

NameBase Acc.Novel Acc.HM
CLIP69.3474.2271.70
CoOp82.6963.2271.66
CoCoOp80.4771.6975.83
MaPLe82.2875.1478.55
PromptSRC84.2676.1079.97
CoPrompt84.0077.2380.48

Acknowledgements

Our code is based on MaPLe repository. We thank the authors for releasing their code. If you use our model and code, please consider citing these works as well.

Contact

If you have any questions, please create an issue on this repository or contact at shuvendu.roy@queensu.ca.

Citation

If you use our work, please consider citing:

@inproceedings{CoPrompt,
  title={Consistency-guided Prompt Learning for Vision-Language Models},
  author={Roy, Shuvendu and Etemad, Ali},
  booktitle=ICLR,
  year={2024}
}