Abstract
Visual anomaly detection (AD) presents significant challenges due to the scarcity of anomalous data samples. While numerous works have been proposed to synthesize anomalous samples, these synthetic anomalies often lack authenticity or require extensive training data, limiting their applicability in real-world scenarios. In this work, we propose Anomaly Anything (AnomalyAny), a novel framework that leverages Stable Diffusion (SD)'s image generation capabilities to generate diverse and realistic unseen anomalies. By conditioning on a single normal sample during test time, AnomalyAny is able to generate unseen anomalies for arbitrary object types with text descriptions. Within AnomalyAny, we propose attention-guided anomaly optimization to direct SD attention on generating hard anomaly concepts. Additionally, we introduce prompt-guided anomaly refinement, incorporating detailed descriptions to further improve the generation quality. Extensive experiments on MVTec AD and VisA datasets demonstrate AnomalyAny's ability in generating high-quality unseen anomalies and its effectiveness in enhancing downstream AD performance.
Introduction: The "Data Starvation" Problem
Visual Anomaly Detection (AD) is a cornerstone of industrial quality control, yet it faces a fundamental "data starvation" problem. In the real world, anomalies are rare, diverse, and often unpredictable. Collecting a dataset of every possible failure mode—such as every way a bottle can crack or a circuit board can fail—is practically impossible.
Existing solutions generally fall into two categories:
- Heuristic Augmentation: Methods like "Cut-and-Paste" take random textures and apply them to normal images. While easy to scale, these often look unrealistic and fail to capture the subtle physics of real-world defects.
- Generative Models: GANs or Diffusion models can produce realistic images but typically require large amounts of data to fine-tune on specific objects or known anomaly types. This defeats the purpose when trying to detect unseen anomalies on a new product line with only one or two reference images.
AnomalyAny bridges this gap, aiming to generate realistic, "unseen" anomalies for arbitrary objects without any training or fine-tuning.
Methodology
AnomalyAny treats anomaly generation as a controlled image-to-image task using a pre-trained Stable Diffusion (SD) model. The framework consists of three core pillars:
- Test-time Normal Sample Conditioning: Instead of starting the diffusion process from pure Gaussian noise, the system begins with a "noised" version of a real normal image. By controlling the noise level ($\gamma$), the model retains the global structure and background of the original object while leaving room to generate new patterns.
- Attention-Guided Anomaly Optimization: Standard diffusion models often ignore small, specific keywords (like "scratch" or "rust") in favor of overall image composition. To fix this, AnomalyAny optimizes the latent representation ($z_t$) at each denoising step by maximizing the values in the cross-attention maps corresponding to the "anomaly token." This forces the model to focus on the defect concept during the generation process.
- Prompt-Guided Anomaly Refinement: Simple prompts like "damaged bottle" are often too vague. The framework uses GPT-4 to expand these into rich, descriptive prompts (e.g., "A bottle with a jagged crack exposing the white interior"). A CLIP-based loss is then used to ensure the visual features of the generated image align with these detailed semantic descriptions.
Key Results and Insights
The authors evaluated AnomalyAny on two gold-standard benchmarks, MVTec AD and VisA, focusing on 1-shot, 2-shot, and 4-shot scenarios.
- Generation Quality: AnomalyAny achieved an average Inception Score (IS) of 2.02, outperforming existing state-of-the-art methods like RealNet (1.64) and AnoDiff (1.80).
- Downstream Performance: In a 1-shot AD setup, using AnomalyAny-generated data led to an I-AUC of 94.9% on MVTec AD. This significantly outperformed traditional few-shot methods like PatchCore (83.4%) and specialized vision-language models like WinCLIP+ (93.1%).
- The "Small Region" Challenge: A key insight is that anomalies are semantically "heavy" but spatially "light." They occupy tiny fractions of an image, which standard diffusion models tend to smooth over. The Attention-Guided Optimization acts as a semantic "magnifying glass," forcing the model to manifest the text prompt in a localized area.
- LLMs as Domain Experts: Using GPT-4 to describe how things break provides the "physical" intuition that the vision model lacks. This synergy between LLMs (reasoning) and Diffusion (rendering) is a powerful template for synthetic data generation.
Limitations and Future Work
While effective, the framework faces a CLIP Semantic Bottleneck, where CLIP sometimes struggles with highly technical descriptions. Additionally, the iterative optimization of the latent space at each denoising step makes inference speed slower than a standard forward pass of a diffusion model. Future directions include incorporating "one-shot anomalous images" as an additional input to allow the model to "re-render" specific defect types across various new normal images.
Summary updated