Enhancing CLIP Robustness via Cross-Modality Alignment

Xingyu Zhu, Beier Zhu, Shuo Wang, Kesen Zhao, Hanwang Zhang

Abstract

Vision-Language Models (VLMs) like CLIP have set new standards for zero-shot classification, yet they remain remarkably vulnerable to adversarial perturbations. Small, imperceptible changes to input images can cause a total collapse in predictive accuracy. This paper introduces COLA (CrOss-modaLity Alignment), a training-free, "plug-and-play" defense mechanism designed to restore the semantic connection between images and text at inference time. By projecting perturbed features onto a text-induced subspace and utilizing Optimal Transport to align multi-view distributions, COLA significantly boosts adversarial robustness without requiring model retraining or additional parameters.

Introduction

The rise of CLIP (Contrastive Language-Image Pre-training) has enabled models to generalize to new visual concepts using natural language. However, these models possess a "glass jaw": adversarial attacks exploit the inherent misalignment between the image and text encoders. Even in clean settings, visual and textual features reside in slightly different neighborhoods of the embedding space; adversarial noise amplifies this gap, scattering image features away from their corresponding semantic text prototypes.

Existing defenses, such as adversarial training or prompt tuning, often involve high computational costs, require retraining, or introduce significant latency. COLA addresses these challenges as a mathematically grounded, test-time defense that is both efficient and model-agnostic.

The COLA Framework

COLA operates through two primary stages designed to filter noise and enforce structural consistency between modalities.

1. Global Feature Alignment: Subspace Projection

The researchers observed that adversarial noise typically pushes image features into "non-semantic" directions—regions of the embedding space that do not correspond to valid textual concepts. To mitigate this, COLA utilizes the class text embeddings of a given dataset to define a "text-induced subspace" via Singular Value Decomposition (SVD).

By projecting adversarial image features onto this subspace, the framework effectively filters out components that do not align with the textual domain. This projection acts as a semantic filter, preserving discriminative information while discarding the high-frequency noise introduced by attackers.

2. Local Structural Alignment: Optimal Transport

Rather than relying on a single point-to-point comparison (e.g., standard cosine similarity), COLA treats the classification task as a distribution alignment problem.

  • Visual Distribution: The model generates multiple augmented views of the input image (e.g., crops and flips).
  • Textual Distribution: Using a Large Language Model (LLM), the framework generates multiple fine-grained descriptions for each class.
  • Alignment: COLA employs Optimal Transport (OT)—specifically the Sinkhorn algorithm—to calculate the minimal cost required to align these two distributions.

This approach ensures that the model evaluates the "structural consistency" of a concept. While an attacker might successfully shift a single image view, shifting an entire distribution of views to match a distribution of textual descriptions is significantly more difficult, providing a robust layer of protection.

Experimental Evaluation

The authors evaluated COLA across 14 zero-shot classification benchmarks, including diverse datasets like Oxford Pets, Flowers, and Eurosat, as well as ImageNet and its robustness variants (ImageNet-A, ImageNet-V2, ImageNet-R, and ImageNet-Sketch).

Key Results

  • Robustness Recovery: On a 9-dataset benchmark, standard CLIP’s accuracy dropped to a mere 1.0% under adversarial attack. COLA successfully recovered this to 77.2% robust accuracy.
  • ImageNet Performance: On ImageNet and its variants, COLA improved robust accuracy under PGD attacks by an average of 6.7%.
  • Efficiency: COLA is significantly faster than other test-time defenses. For instance, it completed ImageNet evaluation in 28 minutes, compared to 40 minutes for the Test-Time Clustering (TTC) method, while achieving superior accuracy.
  • Clean Accuracy Preservation: Unlike adversarial training, which often results in a "robustness-accuracy trade-off," COLA maintains (and occasionally improves) performance on unperturbed, clean images.

Discussion and Insights

The core innovation of COLA lies in the realization that the subspace spanned by text features serves as a reliable proxy for the "clean" visual space. The theoretical backing provided by the authors suggests that this projection strictly reduces cosine similarity distortion and enlarges decision margins, which are classic indicators of improved generalization.

Furthermore, because COLA is training-free, it can be applied to any pre-trained CLIP backbone or even models that have already undergone adversarial fine-tuning (like TeCoA), providing an additive layer of defense.

Limitations and Future Work

While COLA is highly effective, it is not without limitations. As a training-free method, it inherits the underlying biases of the pre-trained CLIP encoders. Additionally, the defense is currently "dataset-aware," as the subspace is constructed using specific class names. Future research may explore making the subspace projection more resilient to adaptive attacks—where an attacker specifically targets the projection mechanism—and extending the method to unconstrained, open-vocabulary tasks.

Summary updated

BibTeX
@inproceedings{zhu2025enhancing,
  author = {Xingyu Zhu and Beier Zhu and Shuo Wang and Kesen Zhao and Hanwang Zhang},
  title = {{Enhancing CLIP Robustness via Cross-Modality Alignment}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=t77EZLjvd5},
}
Figure