Learning Transferable Negative Prompts for Out-of-Distribution Detection

Tianqi Li, Guansong Pang, Xiao Bai, Wenjun Miao, Jin Zheng

Abstract

Vision-Language Models (VLMs) like CLIP often exhibit overconfidence when encountering Out-of-Distribution (OOD) samples, force-fitting them into known categories. We introduce NegPrompt, a lightweight prompt-learning technique that learns "negative prompts" to capture semantics contrary to known classes using only in-distribution data. By creating a robust decision boundary, NegPrompt effectively flags unknown samples even in open-vocabulary scenarios. Our method is data-efficient, transferable, and significantly outperforms existing OOD detection baselines without requiring auxiliary outlier datasets.

Introduction

Vision-Language Models (VLMs) have revolutionized computer vision with their zero-shot capabilities. However, they suffer from a classic "overconfidence" problem: when shown an image that doesn't belong to any known categories (Out-of-Distribution, or OOD), they often assign it to a known class with high confidence.

Existing solutions typically require massive auxiliary datasets of "outlier" images or introduce computationally expensive extra encoders. Furthermore, most current methods struggle with "open-vocabulary" settings, where they cannot easily adapt OOD detection logic to new, unseen classes without retraining. NegPrompt addresses these issues by being data-efficient and highly transferable.

Methodology

The core innovation of NegPrompt is learning a set of negative prompts for every category. While a positive prompt might be "a photo of a dog," a negative prompt learns the "not-dog" semantic space.

The NegPrompt architecture utilizes a two-stage training process to learn negative context vectors alongside frozen positive prompts and VLM parameters.

The training process involves two stages:

  1. Positive Anchoring: Standard prompt tuning (e.g., CoOp) is used to learn positive prompts representing In-Distribution (ID) classes.
  2. Negative Learning: With positive prompts and the VLM frozen, a small set of learnable "negative" context vectors is trained using three specific loss functions:
  3. Negative-Image Separation Loss ($L_{NIS}$): Pushes negative prompt embeddings away from ID images, forcing them to represent "everything else."
    • Negative-Positive Distance Loss ($L_{NPD}$): Prevents negative prompts from drifting too far into irrelevant space, keeping them as a "fence" just outside the positive class boundary.
  4. Negative-Negative Distance Loss ($L_{NND}$): Ensures multiple negative prompts remain diverse and do not collapse into a single point.

Key Insights

NegPrompt relies on the conceptual "fence" analogy. In the embedding space, positive prompts act as anchors for class centers. NegPrompt builds a "fence" of negative points around them. OOD images, which naturally fall outside positive clusters, are more likely to be captured by this negative boundary.

Visualization of the Prompt Embedding Space, where negative prompts form a boundary around positive class clusters to capture OOD samples.

A critical finding is that "negativeness" is a transferable concept. Negative prompts trained on specific classes (e.g., "cat") can have their learned "negative context" applied to entirely new classes (e.g., "airplane") simply by swapping the class name. This enables effective OOD detection in open-vocabulary settings without retraining.

Experimental Evaluation

NegPrompt was evaluated on standard benchmarks including ImageNet-1k (ID) and various OOD datasets like Texture, iNaturalist, Places, and SUN. It was also tested on "Hard OOD" splits and "Open-Vocabulary" settings.

Key results include:

  • FPR95 Reduction: On ImageNet benchmarks, NegPrompt reduced the False Positive Rate (at 95% TPR) to 23.01%, compared to ~51.68% for standard CoOp and ~31.10% for CLIPN.
  • Open-Vocabulary Success: When trained on only 10% of ID classes, NegPrompt achieved an average FPR95 of 25.86%, demonstrating remarkable generalization to unseen categories.
  • Efficiency: NegPrompt maintains the inference speed of standard CLIP and is faster to train than competitors like LoCoOp.

Conclusion

NegPrompt provides a robust, outlier-free approach to OOD detection in VLMs. While highly effective, the computational cost scales with the number of negative prompts per class, presenting a trade-off between accuracy and efficiency. Future work may explore adapting this negative semantic approach to other modalities or larger foundational models.

Summary updated

BibTeX
@inproceedings{li2024learning,
  author = {Tianqi Li and Guansong Pang and Xiao Bai and Wenjun Miao and Jin Zheng},
  title = {{Learning Transferable Negative Prompts for Out-of-Distribution Detection}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2024},
}
Figure