[CVPR-2025] R-TPT: Improving Adversarial Robustness of Vision-Language Models through Test-Time Prompt Tuning
Our implementation is based on TPT and adversarial-attacks-pytorch.
- python == 3.8.5
- pytorch == 1.12.1
- torchvision == 0.13.1
Please follow CoOp and manually download the require datasets. Replace /path/to/dataset with your dataset folder root in below commands and check the path of json file in fewshot_datasets.py.
-
python rtpt.py /path/to/dataset --test_sets DTD -a RN50 -b 64 --gpu 0 --ctx_init a_photo_of_a -p 50 --eps 0.0 --output_dir 'output_results/rtpt'
-
python rtpt.py /path/to/dataset --test_sets DTD -a RN50 -b 64 --gpu 0 --ctx_init a_photo_of_a -p 50 --eps 1.0 --step 7 --output_dir 'output_results/rtpt'
-
If you want to load TeCoA pretrained encoder, please download the TeCoA from this repo and copy it into
pretrain/tecoa
folder, and the command is:python rtpt.py /path/to/dataset --test_sets DTD -a RN50 -b 64 --gpu 0 --ctx_init a_photo_of_a -p 50 --eps 1.0 --step 7 --output_dir 'output_results/rtpt' --load_tecoa 'RN50-eps1'