CLIPure: Purification in Latent Space via CLIP for Adversarially Robust Zero-Shot Classification

Mingkun Zhang, Keping Bi, Wei Chen, Jiafeng Guo, Xueqi Cheng · DOI

Introduction

Vision-Language Models (VLMs), most notably CLIP (Contrastive Language-Image Pre-training), have fundamentally changed the landscape of computer vision by enabling zero-shot classification. By aligning image and text representations in a shared latent space, these models can categorize images into arbitrary classes without task-specific fine-tuning. However, despite their versatility, CLIP-based systems remain vulnerable to adversarial attacks—carefully crafted, imperceptible perturbations that can lead to catastrophic misclassification.

Traditional defense strategies generally fall into two categories: Adversarial Training (AT) and Adversarial Purification. AT is computationally intensive and often fails to generalize to unseen attack types. Conversely, Adversarial Purification attempts to remove noise before the classification step. Most existing purification methods operate in the high-dimensional pixel space, often utilizing generative models like Diffusion. However, pixel-space purification is frequently slow and struggles to distinguish between subtle adversarial noise and essential image features.

Methodology: Purification in Latent Space

The core innovation of CLIPure is the shift from pixel-space purification to latent-space purification. By denoising the high-level embeddings produced by the CLIP image encoder rather than the raw pixels, the defense operates in a lower-dimensional, semantically dense environment.

The authors introduce two distinct implementations of this concept:

1. CLIPure-Diff (Generative)

CLIPure-Diff utilizes the DiffusionPrior (originally developed for DALL-E 2) to model the distribution of clean image embeddings. It employs a reverse-time Stochastic Differential Equation (SDE) to "pull" a perturbed embedding back toward the manifold of natural image representations. This generative approach effectively "washes" the embedding of adversarial noise by leveraging the learned distribution of valid latent vectors.

2. CLIPure-Cos (Discriminative)

CLIPure-Cos represents a significant departure from generative defenses. It leverages the multi-modal nature of CLIP by using a "blank" text prompt (e.g., "a photo of a .") as a semantic anchor. By maximizing the cosine similarity between the adversarial image embedding and this generic text embedding, the system pushes the noisy vector toward a "clean" semantic center. This method is remarkably efficient as it avoids the iterative sampling required by diffusion models.

A critical technical detail in both methods is the requirement for normalization. Since CLIP's classification logic relies on the direction of vectors rather than their magnitude, CLIPure normalizes embeddings to unit vectors during the purification process to ensure mathematical consistency.

Theoretical Advantages

The authors provide a theoretical justification for latent-space purification using KL divergence. They demonstrate that the distribution of clean and adversarial embeddings is more easily separable in the compressed latent space than in the sparse pixel space. This "latent advantage" allows for more effective denoising with significantly less computational overhead.

Experimental Evaluation

CLIPure was evaluated against a rigorous suite of benchmarks, including CIFAR-10, ImageNet, and a diverse "13 Datasets" suite (ranging from satellite imagery to medical scans like PCAM).

Robustness Gains

The performance improvements over previous state-of-the-art (SOTA) methods are substantial:

  • CIFAR-10: Under AutoAttack (the gold standard for robustness testing), CLIPure improved robust accuracy from 71.7% to 91.1%.
  • ImageNet: Robust accuracy increased from 59.6% to 72.6%.
  • Generalization: Across the 13 diverse datasets, CLIPure achieved a 108% relative improvement in average robustness compared to FARE, the previous leading defense.

Computational Efficiency

One of the most striking results is the speed of CLIPure-Cos. Because it does not rely on generative modeling, it is approximately 5,000x faster than pixel-space diffusion methods like DiffPure. In practice, CLIPure-Cos is only 1.14x slower than an undefended CLIP model, making it a viable candidate for real-time applications in autonomous systems or security filters.

Conclusion and Future Work

CLIPure demonstrates that the latent space of Vision-Language Models provides a superior environment for adversarial defense. By treating purification as a latent-space optimization problem, CLIPure achieves unprecedented levels of robustness and efficiency in zero-shot classification.

While CLIPure-Cos offers exceptional speed, CLIPure-Diff remains slower due to its iterative nature. Future research may explore extending latent-space purification to more complex vision tasks, such as object detection and segmentation, and investigating how the quality of the underlying VLM impacts the limits of purification.

Summary updated

BibTeX
@inproceedings{zhang2025clipure,
  author = {Mingkun Zhang and Keping Bi and Wei Chen and Jiafeng Guo and Xueqi Cheng},
  title = {{CLIPure: Purification in Latent Space via CLIP for Adversarially Robust Zero-Shot Classification}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=TQ2ZOy6miT},
}
Figure