CoPA: Object-Agnostic Contextual Prompt Learning for Zero-Shot Anomaly Detection
Abstract
Zero-shot anomaly detection (ZSAD) aims to identify anomalous images and segment anomalous regions in unseen target domains without access to target-domain training data. Although CLIP provides strong zero-shot transferability, its pretraining primarily focuses on aligning images with object-level textual semantics, whereas anomaly detection depends more on normal/abnormal states and subtle local visual patterns. Object-agnostic prompting alleviates this mismatch by replacing category-specific names with generic object placeholders, thereby encouraging the prompts to represent transferable normal and abnormal semantics rather than object identity. However, a fixed set of static prompts cannot adapt anomaly semantics to substantial instance-level variations. Visual-conditioned prompt learning provides a natural way to achieve such adaptation, yet global image representations may dilute the cues of small and localized anomalies because they are often dominated by normal content. To address this issue, we propose CoPA, an object-agnostic contextual prompt learning framework that keeps the normal prompt branch static and dynamically adapts only the abnormal branch. CoPA explicitly models interactions between local visual patch features and abnormal context tokens, producing anomaly semantics conditioned on image-specific local evidence while preserving category independence. Experiments on diverse industrial and medical benchmarks demonstrate competitive cross-domain performance in both image-level anomaly detection and pixel-level anomaly segmentation, with limited additional computational overhead.