Knowledge Regularized Negative Feature Tuning of Vision-Language Models for Out-of-Distribution Detection

Wenjie Zhu, Yabin Zhang, Xin Jin, Wenjun Zeng, Lei Zhang

Abstract

Vision-Language Models (VLMs) like CLIP have demonstrated remarkable zero-shot capabilities, yet adapting them for specific tasks like Out-of-Distribution (OOD) detection remains a challenge. Current fine-tuning approaches, particularly prompt tuning, often suffer from a "generalization gap" where the model overfits to the training distribution and loses the robust, broad-based knowledge acquired during pre-training. We present Knowledge Regularized Negative Feature Tuning (KR-NFT), a framework that replaces heavy prompt tuning with efficient, image-conditional feature transformations. By incorporating a knowledge regularization loss, KR-NFT prevents the erosion of pre-trained representations while significantly improving the model's ability to distinguish between In-Distribution (ID) and OOD samples across unseen classes and styles.

Introduction

In real-world machine learning deployment, the ability to identify Out-of-Distribution (OOD) samples—inputs belonging to classes not seen during training—is critical for safety and reliability. While pre-trained Vision-Language Models (VLMs) are naturally adept at this, researchers have sought to "fine-tune" them to sharpen their decision boundaries.

However, a significant flaw has emerged in existing tuning methods: they often prioritize performance on a specific training set at the expense of general robustness. This phenomenon, termed "knowledge forgetting," occurs when the tuning process overwrites the diverse representations learned during the VLM's original pre-training. Consequently, while a model might improve at detecting OOD samples for classes it has seen, its performance often collapses when encountering new classes or stylistic shifts (e.g., moving from natural photos to sketches). KR-NFT addresses these limitations by focusing on efficient feature-level adaptation and explicit knowledge preservation.

Methodology

KR-NFT is built upon three primary technical pillars designed to balance task-specific adaptation with broad generalization.

1. Negative Feature Tuning (NFT)

Traditional prompt tuning requires expensive backpropagation through the entire text encoder. KR-NFT bypasses this by applying lightweight, learnable transformations directly to the text features. Using distribution-aware scaling and shifting, the model learns to push positive (In-Distribution) and negative (OOD) features into distinct, well-separated regions of the embedding space. This direct manipulation of features is more computationally efficient and provides more stable gradients than tuning high-dimensional prompts.

2. Image-Conditional Module

To account for variations in image style and perspective, KR-NFT utilizes a lightweight "meta-network." This network analyzes the input image to generate specific factors that adjust the text features dynamically. This makes the model "instance-adaptive," allowing it to tailor its detection logic to the specific visual context of the input rather than relying on a static, one-size-fits-all prompt.

3. Knowledge Regularization (KR)

To combat the issue of knowledge forgetting, the authors introduce a Knowledge Regularization loss. This loss function acts as a mathematical tether, ensuring that the tuned features do not drift too far from the original, robust CLIP features. By balancing the objective of OOD separation with the preservation of pre-trained knowledge, the model retains its ability to generalize to unseen domains.

Experimental Setup

The effectiveness of KR-NFT was evaluated across a diverse range of benchmarks:

  • In-Distribution (ID) Training: ImageNet-1k (4-shot setting).
  • OOD Evaluation: Standard benchmarks including iNaturalist, SUN, Places, and Textures.
  • Generalization (Unseen Classes): CIFAR-10, CIFAR-100, and fine-grained datasets like CUB-200.
  • Generalization (Unseen Styles): ImageNet-V2, ImageNet-R (Rendition), ImageNet-A (Adversarial), and ImageNet-Sketch.

Key Insights and Results

Superior Generalization and Robustness

KR-NFT demonstrates a significant performance lead over existing state-of-the-art methods. On unseen ID categories, the model reduced the FPR95 (False Positive Rate at a 95% True Positive Rate) by 5.44%. The most dramatic improvements were observed in style robustness; when tested on unseen styles such as sketches or artistic renditions, KR-NFT outperformed competitors by an average of 16.77% in FPR95.

Computational Efficiency

By avoiding the heavy text encoder during backpropagation, KR-NFT is significantly more efficient than prompt-based methods. The training time is reduced from approximately 1.6 hours to just 0.25 hours. In terms of computational complexity, KR-NFT requires only 0.11 TFLOPs, compared to the ~194 TFLOPs typically required by standard prompt tuning approaches.

Visualizing Knowledge Preservation

Using GradCAM visualizations, the authors observed that standard tuning methods often cause the model to lose focus on the foreground object when encountering unseen classes. In contrast, KR-NFT maintains a strong focus on the actual object of interest, even in new domains, confirming that the knowledge regularization effectively preserves the model's "common sense."

Conclusion

KR-NFT represents a shift toward more efficient and robust VLM adaptation. By moving from prompt tuning to knowledge-regularized feature tuning, the method achieves superior OOD detection performance while remaining computationally lightweight. While the current implementation relies on mined negative labels as OOD proxies, future work may explore dynamic generation of these proxies to further enhance the model's autonomy. Ultimately, KR-NFT provides a scalable path for deploying VLMs in dynamic, real-world environments where distribution shifts are inevitable.

Summary updated

BibTeX
@inproceedings{zhu2025knowledge,
  author = {Wenjie Zhu and Yabin Zhang and Xin Jin and Wenjun Zeng and Lei Zhang},
  title = {{Knowledge Regularized Negative Feature Tuning of Vision-Language Models for Out-of-Distribution Detection}},
  booktitle = {ACM Multimedia},
  year = {2025},
  doi = {10.1145/3746027.3755120},
}
Figure