Introduction
Zero-shot anomaly detection (ZSAD) aims to identify defects in images without having seen those specific objects or anomalies during training. Current state-of-the-art methods typically adapt the CLIP (Contrastive Language-Image Pre-training) model by aligning visual image patches with a single, shared textual embedding (e.g., the prompt "a photo of a [damaged] object").
The authors identify this as indiscriminate alignment. Because every visual token—whether it represents a smooth background, a complex foreground texture, or a tiny crack—is forced to align with the same textual space, the model must make semantic trade-offs. This "coarse" alignment tends to favor common, obvious anomalies while failing to capture rare or fine-grained defects, like a subtle tumor in a brain scan or a hairline fracture on a metal surface.
Methods
The core innovation of TokenCLIP is Dynamic Alignment via Optimal Transport (OT). Instead of a single textual space, the framework functions as follows:
- Multi-head Textual Subspaces: The model projects a base textual embedding into multiple orthogonal subspaces. An orthogonality regularization loss ensures these subspaces remain distinct and don't become redundant.
- Optimal Transport Formulation: The authors treat the alignment as a distribution matching problem. Visual tokens are "transported" to textual subspaces based on a cost matrix (cosine similarity).
- The minimal cost objective encourages each subspace to specialize in specific semantic patterns (e.g., one for foreground objects, another for background textures).
- The marginal constraints of OT ensure that all subspaces are sufficiently utilized and optimized during training.
- Top-K Sparsification: To prevent noise and ensure specialized focus, the model applies a Top-K mask to the transport plan. This means each visual token is only supervised by its most semantically relevant textual subspaces.
- Hybrid Loss: The model is trained end-to-end using a combination of global image-level loss, a "base" local loss (for general semantics), and the new dynamic alignment loss, further refined by a hinge loss to enforce a clear margin between normal and anomalous regions.
Key Insights and Ideas
- OT as a Semantic Specializer: The most striking insight is that Optimal Transport naturally induces specialization. The authors mathematically prove that the OT minimizer avoids "mixing" distinct visual clusters into a single subspace because doing so increases the transport cost.
- Emergent Roles: Without explicit labels for "foreground" or "background," the model naturally learns to assign foreground object tokens to specific subspaces and background/texture tokens to others. Visualization shows that different subspaces focus on distinct semantic components of the image.
- Efficiency over Ensembles: Previous attempts to improve granularity often used large ensembles of prompts, which are computationally expensive. TokenCLIP achieves better results by using a small set of "basis" subspaces that are combined adaptively for each pixel, striking a better balance between performance and speed.
Evaluation and Results
The authors evaluated TokenCLIP across a massive suite of 15 datasets spanning industrial inspection (e.g., MVTec AD, VisA) and medical diagnosis (e.g., ISIC, BrainMRI). They followed a "cross-dataset" evaluation protocol, using MVTec AD or VisA as auxiliary training sets to test the model's zero-shot generalization on the remaining unseen categories.
TokenCLIP sets a new state-of-the-art for ZSAD:
- Industrial Performance: On the MVTec AD benchmark, it achieved 92.2% AUROC and 87.9% PRO at the pixel level, significantly outperforming the previous leader, AnomalyCLIP (91.1% / 81.4%).
- Medical Generalization: The model showed robust cross-domain capabilities, outperforming competitors on medical tasks like skin lesion detection (91.6% AUROC on ISIC) and brain tumor identification.
- Computational Efficiency: Despite the added complexity of OT, TokenCLIP is nearly 2x faster and uses 1.3x less GPU memory than ensemble-based competitors like FAprompt.
Limitations and Future Work
The authors acknowledge a few areas for improvement:
- Spatial Inconsistency: Because the alignment is performed token-wise, the model occasionally produces "spot-level" false positives where a single token is inconsistently assigned to a different subspace than its neighbors.
- Computational Overhead: While more efficient than ensembles, the Sinkhorn-Knopp iterations required for OT still add a slight overhead compared to basic indiscriminate alignment.
- Future Directions: The authors suggest exploring ways to enforce spatial smoothness in the transport plan to reduce localized false alarms.
Summary updated