README.md

February 18, 2025 · View on GitHub

Adversarially Robust CLIP Models Can Induce Better (Robust) Perceptual Metrics


[Paper] [BibTex]

This repository contains code for the paper "Adversarially Robust CLIP Models Can Induce Better (Robust) Perceptual Metrics". We demonstrate that robust CLIP models induce state-of-the-art zero-shot perceptual similarity metrics both in terms of clean performance and adversarial robustness. Moreover, we show that clean fine-tuning on the NIGHTS dataset further improves these perceptual metrics in both aspects.

Comparison with other perceptual metrics

We compare our proposed models against SOTA perceptual metrics on the NIGHTS dataset (Fu et al. (2023)). We evaluate clean performance as well as robustness against adversarial attacks using threat models ,ϵ=4/255\ell_\infty, \epsilon=4/255 and 2,ϵ=3\ell_2, \epsilon=3. More evaluations can be found in the paper.

MethodSourceBackboneFTclean\ell_\infty2\ell_2
LipSim PretrainedGhazanfari et al. (2024)SLL86.68.626.5
LipSim Margin0.2Ghazanfari et al. (2024)SLL88.523.146.6
LipSim Margin0.5Ghazanfari et al. (2024)SLL85.132.853.1
R-LPIPSGhazanfari et al. (2023)AlexNet71.616.226.9
DreamsimFu et al. (2023)Ensemble*90.8--
Dreamsim + MLPFu et al. (2023)Ensemble*93.4--
Dreamsim + LoRAFu et al. (2023)Ensemble*96.20.50.9
OpenCLIPCherti et al. (2023)ConvNeXt-B87.20.00.0
R-CLIPTOursConvNeXt-B92.381.978.5
R-CLIPT + MLPOursConvNeXt-B94.584.479.8
R-CLIPT + LoRAOursConvNeXt-B95.087.284.5

*Dreamsim uses an ensemble of ViT-B/16 models obtained from CLIP, OpenCLIP, and DINO. Pretrained models for "Dreamsim" and "Dreamsim + MLP" were not available, however the robustness is expected to be similarly low as "Dreamsim + LoRA".

Example usage

2AFC tasks: to test a model on the NIGHTS dataset (either split), one can use

python3 eval.py \
	--shortname <model_id> \
	--split [test_no_imagenet | test_imagenet] --dataset nights \
	--n_ex -1 --batch_size 100 --device 'cuda:0' \
	--model_dir <model_dir> --data_dir <data_dir> \
	#
	# Attacks flags (skip for clean accuracy only).
	--norm Linf --eps 4 \
	--n_iter 100 --attack_name apgd \
	--n_restarts 1 --use_rs

with a model_id from the pre-trained models after downloading the relative checkpoint.

List of pre-trained models

Model IDBackboneRobust FT MethodNIGHTS FTNIGHTS cleanNIGHTS \ell_\inftyCheckpoint
convnext_base_wConvNeXt-B----87.20.0HF
convnext_base_w-fareConvNeXt-BFARE--90.674.3Link
convnext_base_w-tecoaConvNeXt-BTeCoA--92.381.9Link
mlp-convnext_base_w-fareConvNeXt-BFAREMLP92.578.2Link
mlp-convnext_base_w-tecoaConvNeXt-BTeCoAMLP94.584.4Link
lora-convnext_base_w-fareConvNeXt-BFARELoRA95.385.6Link
lora-convnext_base_w-tecoaConvNeXt-BTeCoALoRA95.087.2Link
vit-b-16ViT-B/16----85.10.0HF
vit-b-16-fareViT-B/16FARE--90.671.5Link
vit-b-16-tecoaViT-B/16TeCoA--91.979.4Link
mlp-vit-b-16-fareViT-B/16FAREMLP92.775.9Link
mlp-vit-b-16-tecoaViT-B/16TeCoAMLP93.782.1Link
lora-vit-b-16-fareViT-B/16FARELoRA95.780.9Link
lora-vit-b-16-tecoaViT-B/16TeCoALoRA94.681.5Link

Our zero-shot models are also available on HuggingFace and can directly be loaded with the OpenClip library. The model used in the teaser figure above is convnext_base_w-tecoa.

Citation

If you find this work useful, please consider citing our paper:

@inproceedings{croce2024adversarially,
  title={Adversarially Robust CLIP Models Can Induce Better (Robust) Perceptual Metrics},
  author={Croce, Francesco and Schlarmann, Christian and Singh, Naman Deep and Hein, Matthias},
  year={2025},
  booktitle={SaTML}
}