Unseen Visual Anomaly Generation

Han Sun, Yunkang Cao, Hao Dong, Olga Fink

Abstract

Visual Anomaly Detection (AD) is a cornerstone of industrial quality control, yet its effectiveness is often limited by the extreme rarity of anomalous samples. This paper introduces AnomalyAny, a generative framework that addresses the "scarcity of the strange" by synthesizing realistic and diverse visual anomalies for any object. Utilizing a pre-trained Stable Diffusion model, AnomalyAny requires only a single normal image and a text prompt to produce high-quality training data. Through innovative test-time interventions, including attention-map optimization and GPT-4-guided prompt refinement, the framework achieves superior performance in one-shot anomaly detection tasks without requiring prior examples of defects.

Introduction

In industrial environments, identifying defects such as scratches, cracks, or missing components is vital. However, training robust AD systems is challenging because anomalies are infrequent. Traditional approaches typically rely on heuristic synthesis (e.g., cut-and-paste), which often lacks realism, or generative models that require extensive datasets of both normal and abnormal samples—a luxury rarely available for new product lines.

Comparison of anomaly generation methods: (a) DRAEM (Universal but Unrealistic), (b) AnomalyDiffusion (Realistic but Specific), and (c) AnomalyAny (Universal and Realistic).

AnomalyAny overcomes these hurdles by leveraging the broad visual knowledge embedded in pre-trained Stable Diffusion (SD) models. It enables the generation of realistic defects for "unseen" categories, where zero prior examples of anomalies exist.

Methodology: The AnomalyAny Framework

The core of AnomalyAny lies in its ability to "nudge" a frozen Stable Diffusion model into generating specific anomalies without the need for fine-tuning. The framework employs three key strategies:

1. Test-time Normal Sample Conditioning

Rather than generating from pure noise, the process begins with a lightly noised version of a real "normal" image. This ensures the output preserves the structural and contextual integrity of the original object (e.g., shape, color, and background).

2. Attention-Guided Anomaly Optimization

Standard diffusion models often overlook fine-grained details like small cracks. AnomalyAny intervenes by monitoring the model's internal cross-attention maps. It mathematically optimizes these maps to increase the model's focus on tokens representing the anomaly (e.g., "damaged") during the denoising process, forcing the defect to manifest in specific spatial regions.

Detail of the AnomalyAny process, showing the use of text prompts and Stable Diffusion to generate localized anomalies on normal samples.

3. Prompt-Guided Refinement

To move beyond vague descriptions, the framework utilizes GPT-4 to expand simple prompts into detailed, descriptive narratives. A CLIP-based loss function then ensures the generated pixels align closely with these refined descriptions, enhancing both realism and diversity.

Experimental Evaluation

The authors evaluated AnomalyAny on the MVTec AD and VisA benchmarks, focusing on the challenging 1-shot anomaly detection scenario.

Key Results

  • Performance: On MVTec AD, AnomalyAny achieved an Image-level Area Under the Curve (I-AUC) of 94.9%, significantly outperforming existing few-shot and heuristic methods.
  • Quality and Diversity: Quantitative metrics such as Inception Score and IC-LPIPS confirmed that AnomalyAny produces more realistic and varied anomalies than previous state-of-the-art methods like DRAEM.
  • Generalization: The framework successfully generated defects for diverse objects found in web images, demonstrating its flexibility beyond standard industrial datasets.

Conclusion

AnomalyAny represents a significant step forward in visual anomaly detection by solving the data scarcity problem through intelligent generative modeling. By treating Stable Diffusion as a zero-shot defect generator and refining its output through attention-map optimization, the framework provides a scalable and effective solution for industrial quality control in the absence of real-world anomaly examples. Future work may involve improving textual precision for highly technical defects and optimizing the computational efficiency of the test-time optimization loop.

Summary updated

BibTeX
@inproceedings{sun2025unseen,
  author = {Han Sun and Yunkang Cao and Hao Dong and Olga Fink},
  title = {{Unseen Visual Anomaly Generation}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2025},
  doi = {10.1109/cvpr52734.2025.02375},
}
Figure