TL;DR
Existing few-shot out-of-distribution (FS-OOD) detection methods isolate background features using brittle class similarities and rigid, fixed patch-selection thresholds. This paper introduces Mambo, a framework that learns a dedicated, class-agnostic background prompt and dynamically scales patch extraction based on model confidence. By decoupling background identification from closed-set class semantics, Mambo achieves state-of-the-art OOD and near-OOD detection across multiple vision-language benchmarks while adding negligible computational overhead.
What Problem Does This Paper Address?
When deploying Vision-Language Models (VLMs) like CLIP into safety-critical environments, models must perform downstream classification on known in-distribution (ID) classes while reliably flagging out-of-distribution (OOD) inputs. In few-shot OOD (FS-OOD) settings, models must adapt using only a handful of labeled ID examples per class.
A prominent line of work relies on foreground-background (FG-BG) decomposition (e.g., LoCoOp): local image patches deemed irrelevant to the ID classes are identified and pushed away from ID class representations during prompt tuning. However, current FG-BG approaches suffer from two core weaknesses:
- Over-reliance on local class similarity: They assume that background patches can be identified solely by measuring low cosine similarity between local patch tokens and ID class text features. If an image has small objects, clutter, or low resolution, these class similarity estimates fail, leading to misclassified background regions.
- Fixed extraction thresholds: Prior methods apply a static rule (such as taking a fixed top-$K$ patches) to all images, ignoring the fact that foreground-to-background ratios vary dramatically from one image to another.
Methods
Mambo introduces a principled pipeline to isolate and regularize background tokens without falling into these traps:
[ID Image] ──> Image Encoder ──> Local Image Patches
│
[Background Prompt] ─> Text Encoder ──> Background Feature ──> Local BG Similarity
│
[Class Prompt] ──────> Text Encoder ──> Local Class Similarity ──> [Refinement]
│
[Patch Self-Calibrated Tuning]
│
Selected Background Patches ──> LOOD
- Background Prompt Learning: Instead of treating background as simply "not foreground," Mambo introduces a learnable background prompt vector $t^b \in \mathbb{R}^{L \times d}$ processed by CLIP's frozen text encoder to produce a background text feature $g^b$. The cosine similarity between $g^b$ and local image patches provides an independent, class-agnostic baseline for background detection.
- Local Similarity Refinement: Because the background prompt alone lacks sample-specific nuances, Mambo adaptively refines this background similarity using the ground-truth class prediction probability $p(y^{id}|x^{id})$ and normalized local class similarities. When the model is confident, foreground information helps sharpen fuzzy background boundaries.
-
Patch Self-Calibrated Tuning: Rather than adopting a static top-$K$ cut, Mambo calculates an image-specific threshold $\theta$: $$\theta = \bar{s} - \alpha \cdot (2p(y^{id}|x^{id}) - 1) \cdot \sigma_s$$ where $\bar{s}$ and $\sigma_s$ are the mean and standard deviation of local patch similarities. For low-confidence samples, the threshold increases, extracting fewer background patches to prevent accidentally discarding valuable ID features. For high-confidence samples, the threshold decreases, extracting more background patches to suppress spurious OOD cues.
-
Inference with R-MCM Scoring: During testing, Mambo scores inputs using R-MCM, which aggregates the maximum softmax probabilities across global features, local class features, and local background similarity.
Datasets
- In-Distribution (ID): ImageNet-1K, ImageNet-100, and semantically dense subsets (ImageNet-10, ImageNet-20).
- Out-of-Distribution (OOD): iNaturalist, SUN, Places, Texture, and the OpenOOD v1.5 benchmark (incorporating OpenImage-O).
- Near-OOD: ImageNet-O, SSB-hard, NINCO, and cross-evaluation between ImageNet-10 and ImageNet-20.
Key Insights and Ideas
- Background has its own semantic identity: Backgrounds share common textures, scenes, and contextual cues that can be captured directly via prompt learning rather than treated as an afterthought or mathematical residual of class labels.
- Confidence should govern regularization strength: If a model is uncertain about an ID image's label, aggressively regularizing "background" patches risks erasing weak foreground features. Tying the patch-selection threshold to classification probability $p(y^{id}|x^{id})$ naturally safeguards fragile representations.
- Superior efficiency over negative-prompt baselines: While methods like Local-Prompt train large negative prompt banks—ballooning training time and memory—Mambo uses a single shared background prompt vector, retaining near-baseline training speeds (~25 seconds per epoch on ImageNet-1K).
Key Results
- ImageNet-1K Benchmark: Across 1-shot, 4-shot, and 16-shot setups, Mambo consistently outperforms previous SOTA FG-BG and prompt-based methods:
- 1-shot: Achieves an average FPR95 of 30.38% (compared to LoCoOp's 32.27% and SCT's 33.56%).
- 4-shot: Achieves an average FPR95 of 26.65% and AUROC of 93.32% (vs. LoCoOp's 29.41% FPR95 and SCT's 28.14% FPR95).
- 16-shot: Reaches 25.31% FPR95 and 93.68% AUROC.
- ImageNet-100 (4-shot): Mambo achieves 14.63% FPR95 and 97.07% AUROC, beating LoCoOp (16.48% FPR95) and SCT (17.53% FPR95).
- Architecture Agnostic: The performance advantage holds across multiple Vision Transformer backbones (ViT-B/32, ViT-B/16, and ViT-L/14) under identical hyperparameters.
- Compute Efficiency: On 1-shot ImageNet-1K, Mambo trains in 25.57 seconds/epoch with 19.2 GB VRAM, compared to Local-Prompt’s 270.9 seconds/epoch and 24.3 GB VRAM.
Limitations and Future Work
- Extreme Camouflage and Low Feature Contrast: Mambo struggles when foreground targets closely mimic background textures (e.g., desert horned vipers, slugs, or flat electric rays), where the background prompt can falsely latch onto the subject.
- Scope of Modalities: The current formulation is validated solely on 2D natural image classification benchmarks. Extending dynamic background prompting to safety-critical, dense-prediction domains—such as autonomous driving or 3D medical imaging—remains an open research direction.
Summary updated