LoCoOp: Few-Shot Out-of-Distribution Detection via Prompt Learning

Atsuyuki Miyai, Qing Yu, Go Irie, Kiyoharu Aizawa · DOI

Abstract

Machine learning models deployed in real-world environments frequently encounter Out-of-Distribution (OOD) samples—images from classes not seen during training. Detecting these samples is critical for the safety and reliability of autonomous systems. While large-scale vision-language models like CLIP have advanced zero-shot OOD detection, they often struggle with domain gaps or require extensive fine-tuning that can degrade their pre-trained representations. This paper presents LoCoOp (Local regularized Context Optimization), a novel few-shot approach that leverages CLIP’s local features to perform OOD detection. By identifying and regularizing background nuisances within in-distribution images, LoCoOp achieves state-of-the-art performance, even in extreme low-data regimes.

Introduction

Out-of-Distribution (OOD) detection is a fundamental challenge in computer vision. Standard supervised models tend to be overconfident when presented with samples from unknown classes. While prompt learning methods like CoOp (Context Optimization) have been developed to adapt models like CLIP to specific downstream tasks using a few labeled images, they primarily focus on global image features.

The authors identify a critical flaw in this global approach: when trained on limited data, the model often learns to associate the entire image—including irrelevant backgrounds or "nuisances"—with the class label. Consequently, when the model encounters an OOD image with a similar background (e.g., a bird in a forest vs. an empty forest), it erroneously classifies the sample with high confidence. LoCoOp addresses this by treating the background of in-distribution (ID) images as a proxy for the OOD space.

Methodology

LoCoOp introduces a local regularization technique during the prompt learning phase to "clean" class embeddings and focus the model on the actual objects of interest.

1. Local Feature Extraction

Unlike standard prompt learning which utilizes global pooled features, LoCoOp accesses CLIP’s local feature maps—the grid of features available before global average pooling. This allows the model to reason about specific spatial regions within an image.

2. ID-Irrelevant Region Identification

For a given image belonging to a specific class (e.g., "dog"), the model evaluates each local region. If a region’s prediction for the target class does not rank within the Top-K candidates, it is flagged as an "ID-irrelevant nuisance." These regions typically represent the background or non-essential elements of the scene.

3. OOD Regularization via Entropy Maximization

Once nuisances are identified, the model is trained to maximize the entropy of the classification probability for these specific regions. By doing so, the model learns that these local features should not be strongly associated with any of the known in-distribution classes. This effectively uses the background of ID images as "pseudo-OOD" samples, eliminating the need for external OOD datasets during training.

4. Joint Optimization

The final objective function is a combination of two losses:

  • Cross-Entropy Loss: To ensure the model correctly identifies the primary object in the image.
  • OOD Regularization Loss: To ensure the model remains uncertain about background regions.

Experimental Setup

The researchers evaluated LoCoOp across several benchmarks to test its robustness in few-shot scenarios (1, 2, 4, 8, and 16 shots per class):

  • In-Distribution (ID): ImageNet-1K.
  • Out-of-Distribution (OOD): iNaturalist, SUN, Places, and TEXTURE.
  • Metrics: Area Under the Receiver Operating Characteristic curve (AUROC) and False Positive Rate at 95% True Positive Rate (FPR95).

Results and Discussion

Performance in Low-Data Regimes

LoCoOp demonstrates remarkable efficiency in few-shot settings. With only one training image per class (1-shot), LoCoOp outperforms existing zero-shot methods and even some fully supervised models. On the ImageNet benchmark, LoCoOp achieved an average AUROC of 93.52% in a 16-shot setting.

Reduction in False Positives

A key highlight is the significant reduction in FPR95. In the 1-shot setting, LoCoOp achieved an average FPR95 of 33.52%, a substantial improvement over zero-shot MCM (42.82%) and standard CoOp (44.81%). This indicates that the model is much less likely to misclassify OOD samples as known classes.

Computational Efficiency

LoCoOp maintains high inference speeds because it learns a single static prompt. Unlike dynamic methods like CoCoOp, which generate prompts per image, LoCoOp completed the ImageNet OOD benchmarks in 3.7 minutes, compared to CoCoOp's 3.5 hours.

Trade-offs

The authors noted a minor trade-off: a slight decrease in closed-set ID accuracy (e.g., 71.7% for LoCoOp vs. 72.1% for CoOp). This occurs because the model can no longer rely on background cues to identify the object. However, this trade-off is generally considered acceptable for the significant gains in OOD robustness.

Conclusion

LoCoOp provides a highly effective and efficient framework for few-shot OOD detection. By leveraging local features and treating background nuisances as a form of internal OOD exposure, it prevents the model from over-associating irrelevant context with class labels. This "local-to-global" optimization ensures that the learned prompts are more representative of the actual objects, leading to safer and more reliable performance in open-world applications.

Summary updated

BibTeX
@inproceedings{miyai2023locoop,
  author = {Atsuyuki Miyai and Qing Yu and Go Irie and Kiyoharu Aizawa},
  title = {{LoCoOp: Few-Shot Out-of-Distribution Detection via Prompt Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=UjtiLdXGMC},
}
Figure