This repository contains the code for our project "Test-Time Adversarial Defense in Vision-Language Models via Dual Adaptive Caching". The goal of this project is to build a lightweight, data-free test-time defense against adversarial attacks for vision-language models (VLMs) like CLIP.
Our implementation is motivated by the TDA framework, that does zero-shot classification accuarcy increase of different domains. We propose a new solution for Test-time adversarial defense by incorporating an MLP-based adversarial detector and a dual-cache system for logit correction of pre-trained CLIP.
First, clone the repository and install the required dependencies:
pip install -r requirements.txtTo train the MLP for detecting adversarial and clean samples at test time, run the following script
python mlp_adversarial_detector.pyThis will train and save the detector locally
Our current implementation is focused on defending FGSM attack on CLIP zero-shot model. To run the test time defense code, please run the following command
bash scripts/run_fgsm_rn50.shRahim Hossain (ramsRahim), Mohaiminul Al Nahian (alnahian37)
- Both contributed equally to reproduce main result from TDA paper
- For literature survey, Rahim contributed on Test-time adaptation and Nahian contributed on adversarial defense
- Both contributed equally on theory and hypothesis development fot the project
- Both contributed for setting up code base for the test-time adversarial defense
- Both prepared the presentation and write the report
- Overall contribution: Rahim 50%, Nahian 50%