TL;DR
Anomaly Anything (AnomalyAny) is a novel framework that leverages Stable Diffusion to generate realistic, diverse visual anomalies for arbitrary objects using only a single normal reference image and a text prompt. By combining test-time conditioning with attention-guided optimization, it creates high-quality synthetic training data that significantly boosts the performance of anomaly detection models, especially in data-scarce scenarios.
What Problem Does This Paper Address?
Visual Anomaly Detection (AD) is critical for industrial quality control, yet it suffers from a fundamental "data desert" problem: anomalies are, by definition, rare and hard to collect.
Existing solutions fall into two camps, both with major drawbacks:
- Heuristic Synthesis (e.g., Cut-and-Paste): These methods are "universal" but often produce unrealistic, "photoshopped" patterns that don't help models generalize to real-world defects.
- Generative Models (e.g., GANs or fine-tuned Diffusion): These produce realistic images but typically require a large dataset of both normal and abnormal samples to train, which defeats the purpose when data is scarce.
The authors identify a "missing middle": a way to generate realistic anomalies for unseen objects and defect types without needing a massive training library.
Methods
AnomalyAny repurposes a pre-trained Stable Diffusion (SD) model for zero-shot anomaly generation through three clever modules:
- Test-time Normal Sample Conditioning: Instead of starting from pure noise, the model begins the denoising process with a noised version of a real "normal" image. This ensures the generated anomaly (like a crack or a rust spot) is grounded in the correct object geometry and texture without requiring any fine-tuning.
- Attention-Guided Anomaly Optimization: Standard SD often ignores anomaly prompts because defects are rare in its training data and usually occupy very small image regions. To fix this, the authors introduce a loss function that maximizes the model's internal attention on the specific "anomaly token" (e.g., the word "damaged") during the backward pass of the diffusion process.
- Prompt-Guided Anomaly Refinement: To move beyond simple keywords, the framework uses GPT-4 to generate detailed descriptions of defects (e.g., "a bottle with a concentrated chip and scuff, revealing a lighter, rough patch"). It then uses a CLIP-based loss to ensure the generated pixels align perfectly with these nuanced descriptions.
Datasets
The authors evaluated their framework on two gold-standard industrial benchmarks:
- MVTec AD: 5,000 images across 15 categories (objects and textures) with pixel-level defect annotations.
- VisA: 10,821 images across 12 categories.
They also demonstrated the model's versatility by generating anomalies for "web images" of objects not found in standard industrial datasets, like phone screens and vases.
Key Insights and Ideas
- The "Attention Gap": The most striking insight is that SD knows how to draw anomalies, but it doesn't want to. Because anomalies are small and rare, they get "washed out" during standard denoising. Forcing the model to pay attention to the anomaly token is the key to unlocking its generative power for AD.
- Conditioning vs. Fine-tuning: Fine-tuning SD on a specific dataset (like "bottles") often destroys its ability to generalize. By using test-time conditioning (starting from a noised real image), AnomalyAny preserves the broad knowledge of the base model while keeping the output "on-brand" for the specific industrial part.
- Localization for Free: Because the method relies on attention maps to generate the anomaly, those same maps can be used as pixel-level ground truth masks for training downstream detection models.
Key Results
- Generation Quality: AnomalyAny achieved an average Inception Score (IS) of 2.02, outperforming the previous state-of-the-art (AnoDiff at 1.80) and significantly beating heuristic methods like NSA (1.44).
- 1-Shot Detection: When used to train a 1-shot anomaly detector (using only one normal image), AnomalyAny reached 94.9% I-AUC on MVTec AD, outperforming existing few-shot methods like WinCLIP and AnomalyGPT.
- User Preference: In a user study with 20 participants, images generated by AnomalyAny were voted "most realistic" more than twice as often as those from the next best competitor (AnomalyDiffusion).
Limitations and Future Work
The authors acknowledge that AnomalyAny still relies heavily on the quality of text descriptions. While GPT-4 helps, the CLIP model used for alignment sometimes struggles with very long or highly specialized technical descriptions.
Future work may involve incorporating "one-shot anomalous images" (if available) as additional visual prompts to provide even more precise guidance for complex, hard-to-describe defect patterns. This would move the framework from "text-to-anomaly" toward a more flexible "multimodal-to-anomaly" paradigm.
Summary updated