[ECCV 2024] Official PyTorch Implementation of "How Many Unicorns Are in This Image? A Safety Evaluation Benchmark for Vision LLMs"
How many
Are in This Image? A Safety Evaluation Benchmark for Vision LLMs
Haoqin Tu, Chenhang Cui, Zijun Wang, Yiyang Zhou, Bingchen Zhao, Junlin Han, Wangchunshu Zhou, Huaxiu Yao, Cihang Xie (equal contribution)
Our paper is online now: https://arxiv.org/abs/2311.16101
Installation
For different VLLMs, please refer to their specific envirnments for installation.- LLaVA: https://github.com/haotian-liu/LLaVA
- MiniGPT4: https://github.com/Vision-CAIR/MiniGPT-4
- InstructBLIP: https://huggingface.co/Salesforce/instructblip-vicuna-7b
- LLaMA-Adapter: https://github.com/OpenGVLab/LLaMA-Adapter
- mPLUG-Owl1&2: https://github.com/X-PLUG/mPLUG-Owl
- PandaGPT: https://github.com/yxuansu/PandaGPT
- Qwen-VL-Chat: https://huggingface.co/Qwen/Qwen-VL-Chat
- CogVLM: https://github.com/THUDM/CogVLM
- InternLM-Xcomposer: https://huggingface.co/internlm/internlm-xcomposer-7b
- Fuyu: https://huggingface.co/adept/fuyu-8b
Datasets
We host our datasets here, containing both OOD and redteaming attack datasets. The full dataset should looks like this:.
โโโ ./safetyevaluationbenchmark_datasets//
โโโ gpt4vchallengingset # Contains the challenging test data for GPT4V
โโโ attack_images
โโโ sketchy_images
โโโ oodcv_images
โโโ misleading-attack.json
โโโ sketchy-vqa-challenging.json
โโโ oodcv-vqa-counterfactual.json
โโโ redteaming # Contains the test data for redteaming tasks
โโโ misleading_attack
โโโ gaussian_noise
โโโ mixattack_eps32
โโโ mixattack_eps64
โโโ sinattackeps64dog
โโโ sinattackeps64coconut
โโโ sinattackeps64spaceship
โโโ annotation.json
โโโ jailbreak_vit # adversarial images for jailbreaking VLLM through ViT
โโโ jailbreak_llm # adversarial suffixes for jailbreaking VLLM through LLM
โโโ ood # Contains the test data for OOD scenarios
โโโ sketchy-vqa
โโโ sketchy-vqa.json
โโโ sketchy-challenging.json
โโโ oodcv-vqa
โโโ oodcv-vqa.json
โโโ oodcv-counterfactual.json
Out-of-Distribution Scenario
For $\texttt{OODCV-VQA}$ and its counterfactual version, please download images from OODCV, and put all images inood/oodcv-vqa.
For $\texttt{Sketchy-VQA}$ and its challenging version, please first download images from here, put the zip file into ood/sketchy-vqa/skechydata/, then unzip it.
Redteaming Attack
For the proposed misleading attack, the full datasets and all trained adversarial examples are inredteaming/misleading_attack, including images with gaussian noise, Sin.Attack and MixAttack with two pertubation budgets $\epsilon=32/255$ (eps32) or $\epsilon=64/255$ (eps64).
For jailbreaking methods, please refer to their respective repositories for more dataset details: Jailbreak through ViT, Jailbreak through LLM.
Testing
Before you start, make sure you have modified theCACHEDIR (where you store all your model weights) and DATADIR (where you store the benchmark data) in baselines/config.json according to your local envirnment.
cd baselines
python ../modeltestingzoo.py --model_name LLaVA
Choose --modelname from ["LlamaAdapterV2", "MiniGPT4", "MiniGPT4v2", "LLaVA", "mPLUGOwl", "mPLUGOwl2", "PandaGPT", "InstructBLIP2", "Flamingo", "LLaVAv1.5", "LLaVAv1.5-13B", "LLaVAllama2-13B", "MiniGPT4llama2", "Qwen-VL-Chat", "MiniGPT413B", "InstructBLIP2-FlanT5-xl", "InstructBLIP2-FlanT5-xxl", "InstructBLIP2-13B", "CogVLM", "Fuyu", "InternLM"].
$\texttt{OODCV-VQA}$ and its Counterfactual Variant
For $\texttt{OODCV-VQA}$:
cd baselines python ../safetyevaluations/oodscenarios/evaluation.py --modelname LLaVA --evaloodcv
For the counterfactual version:
cd baselines
python ../safetyevaluations/oodscenarios/evaluation.py --modelname LLaVA --evaloodcv_cf
$\texttt{Sketchy-VQA}$ and its Challenging Variant
For $\texttt{Sketchy-VQA}$:
cd baselines python ../safetyevaluations/oodscenarios/evaluation.py --modelname LLaVA --evalsketch
For the challenging version:
cd baselines
python ../safetyevaluations/oodscenarios/evaluation.py --modelname LLaVA --evalsketch_challenging
Misleading Attack
For training the misleading adversarial images:cd safetyevaluations/redteaming/misleadingvision_attack
python misleadingvisattack.py --lr 1e-3 --misleadingobj dog --inputfolder path/to/attack-bard/NIPS2017 --outputfolder ./misleadingadversarial_attack
Change --inputfolder to the path of adversarial examples you want to test. If you want to use the MixAttack, add --mixobj argument to the command.
For testing the VLLMs:
cd baselines
python ../safetyevaluations/redteaming/misleadingvisionattack/testmisleading.py --imagefolder redteaming/misleadingattack/mixattackeps64 --outputname misleadingattackeps64 --humanannotpath redteaming/misleading_attack/annotation.json
Jailbreaking Methods
Please refer to these two repositories for detailed attack settings: Jailbreak through ViT, Jailbreak through LLM. We give our trained adversarial images and suffixes for jailbreaking ViTs and LLMs in redteaming/jailbreakvit and redteaming/jailbreakllm in the data folder.
Usage and License Notices
The data, code and checkpoint is intended and licensed for research use only. The dataset is CC BY NC 4.0 (allowing only non-commercial use) and models trained using the dataset should not be used outside of research purposes.Citation
If you find our work useful to your research and applications, please consider citing the paper and staring the repo :)@article{tu2023how,
title={How Many Unicorns Are In This Image? A Safety Evaluation Benchmark For Vision LLMs},
author={Tu, Haoqin and Cui, Chenhang and Wang, Zijun and Zhou, Yiyang and Zhao, Bingchen and Han, Junlin and Zhou, Wangchunshu and Yao, Huaxiu and Xie, Cihang},
journal={arXiv preprint arXiv:2311.16101},
year={2023}
}