CLIP Surgery for Better Explainability with Enhancement in Open-Vocabulary Tasks

Yi Li, Hualiang Wang, Yiqun Duan, Xiaomeng Li · OpenReview

Abstract

Contrastive Language-Image Pre-training (CLIP) is a powerful multimodal large vision model that has demonstrated significant benefits for downstream tasks, including zero-shot learning and text-guided vision tasks. However, severe problems regarding the model's explainability undermine its credibility. Specifically, CLIP often prefers background regions over foregrounds in similarity maps and exhibits noisy activations at irrelevant positions. To address these issues, we propose CLIP Surgery, a method enabling training-free modifications to the inference architecture and features. CLIP Surgery significantly improves explainability for both convolutional networks and vision transformers and demonstrates remarkable improvements in open-vocabulary segmentation and multi-label recognition. For example, mIoU on Cityscapes open-vocabulary semantic segmentation surpasses state-of-the-art methods by 8.74% without additional training.

Introduction: The Explainability Crisis in CLIP

While CLIP has revolutionized multimodal learning, its internal "reasoning" is often counter-intuitive. Standard explainability tools like Class Attention Maps (CAM) reveal two major issues: "opposite visualization" and "noisy activations." In many cases, when prompted with an object (e.g., "horse"), the raw model highlights background regions like fences or trees instead of the object itself. Additionally, random, irrelevant pixels often light up, creating noise that undermines the model's utility for precise localization tasks.

Visual comparison of raw CLIP explainability issues (opposite visualization and noise) versus the clean results achieved by CLIP Surgery.

Methods: Architecture and Feature Surgery

CLIP Surgery addresses these flaws through a two-pronged, training-free approach applied during the inference phase:

1. Architecture Surgery

  • Consistent Self-Attention: The authors discovered that standard self-attention builds relations between inconsistent semantic regions. By using homogeneous parameters—specifically using the Value ($V$) features to compute the attention matrix—tokens are forced to attend to semantically similar neighbors.
  • Dual Paths: Analysis revealed that Feed-Forward Networks (FFNs) in later layers actually push image features toward "negative" labels, degrading localization. CLIP Surgery introduces a parallel path that skips these FFNs, aggregating only the beneficial self-attention modules.

2. Feature Surgery

  • The "noise" in CLIP's maps stems from redundant features shared across many categories. By identifying these common features (using an empty text string as a reference) and subtracting them from class-specific features, the activation maps are effectively "denoised."
Overview of the CLIP Surgery framework, detailing modifications to the self-attention architecture and the data flow for feature denoising.

Key Insights and Results

A critical finding of this work is that FFNs, while essential for global contrastive learning, can sabotage local precision. Furthermore, redundancy in the feature space acts as a common bias that can be removed to reveal the true semantic signal.

CLIP Surgery achieves significant performance gains across various benchmarks:

  • Explainability Leap: On VOC 2012, mIoU improved from ~17% to over 55% using a ViT-B/16 backbone.
  • Open-Vocabulary Segmentation: The method outperformed specialized models like GroupViT on PASCAL Context, achieving 29.3 mIoU without any training.
  • Multi-label Recognition: On the NUS-Wide dataset, mAP improved by 4.41%.
  • Interactive Segmentation: CLIP Surgery can provide high-quality "points" for the Segment Anything Model (SAM), enabling text-to-segmentation without manual human input.

Conclusion

CLIP Surgery demonstrates that the "knowledge" for precise object localization is already present within CLIP; it simply requires better extraction techniques. While the method does not change the top-1 classification rank for single-label tasks, it significantly enhances explainability and performance in open-vocabulary segmentation and multi-label recognition. These insights into FFN behavior and feature redundancy provide a roadmap for designing more inherently explainable vision-language models in the future.

Summary updated

BibTeX
@article{li2025clip,
  author = {Yi Li and Hualiang Wang and Yiqun Duan and Xiaomeng Li},
  title = {{CLIP Surgery for Better Explainability with Enhancement in Open-Vocabulary Tasks}},
  journal = {Pattern Recognition},
  year = {2025},
  url = {https://openreview.net/forum?id=pnhwewWTLe},
}
Figure