Few-Shot Anomaly-Driven Generation for Anomaly Classification and Segmentation

Bin-Bin GaoECCV 2024

TL;DR

This paper introduces AnoGen, a novel few-shot anomaly generation method that leverages diffusion models to create realistic and semantically consistent anomalies from just a few real examples. By guiding a pre-trained diffusion model with learned embeddings and bounding boxes, AnoGen generates synthetic anomalies that significantly improve the performance of downstream anomaly detection and segmentation tasks, bridging the gap between synthetic and real-world anomalies.

What Problem Does This Paper Address?

Anomaly detection, particularly in industrial settings, is hampered by the extreme scarcity of anomalous data. This makes it challenging to train robust models for tasks like quality inspection. Existing methods often resort to synthesizing anomalies using noise or external datasets, but these synthetic anomalies suffer from a significant "semantic gap" with real-world anomalies, leading to suboptimal performance. This paper tackles the problem of generating realistic, diverse, and semantically aligned anomalies using only a handful of real anomaly examples, thereby enabling better training of anomaly detection models.

Methods

The proposed AnoGen method operates in three stages:

  1. Learn Anomaly Embedding: Instead of fine-tuning the entire diffusion model (which is computationally expensive and requires lots of data), AnoGen learns a compact embedding vector. This embedding captures the semantic characteristics of a few "support anomalies" (real anomaly examples). The pre-trained diffusion model's parameters are frozen, and only this embedding is optimized.
  2. Guiding Image Generation: The learned embedding is then used to guide a pre-trained Latent Diffusion Model (LDM) to generate new anomalies. This generation process is conditioned on a normal image and a bounding box mask, allowing for control over the anomaly's location and size. This bounding box also serves as a weak supervision signal for downstream tasks.
  3. Weakly-Supervised Anomaly Detection: Finally, the generated anomalies, along with their bounding box masks, are used to train discriminative anomaly detection models (like DRAEM and DeSTSeg). A novel weakly-supervised loss is introduced to handle the imprecision of bounding box masks, effectively filtering out high-confidence normal pixels within the box to prevent misclassification.

Datasets

The primary dataset used for evaluation is MVTec AD. This dataset is a standard benchmark for industrial anomaly detection, containing 10 objects and 5 textures with various types of anomalies. The authors generated a large synthetic dataset of 70,760 images for training their models.

Key Insights and Ideas

  • Few-Shot Generation is Key: The core idea is that even a few real anomalies can provide enough semantic information to guide a powerful generative model (like diffusion models) to produce more realistic synthetic anomalies than methods relying on external data or noise.
  • Embedding as a Compact Representation: Learning a small embedding vector is a more efficient and effective way to condition a diffusion model for anomaly generation than trying to fine-tune the entire model, especially with limited data.
  • Bounding Boxes as Dual-Purpose Supervision: The bounding boxes used to control anomaly generation also serve as a crucial weak supervision signal for training anomaly segmentation models, simplifying the process compared to requiring precise pixel-level masks.
  • Bridging the Semantic Gap: The generated anomalies are semantically consistent with real-world anomalies, which is critical for improving the performance of downstream anomaly detection models, especially for segmentation tasks where precise localization is important.

Key Results

  • AnoGen significantly improves the performance of existing anomaly detection models like DRAEM and DeSTSeg.
  • On the MVTec dataset, DRAEM achieved a 5.8% improvement in pixel-level AU-PR, and DeSTSeg achieved a 1.5% improvement in pixel-level AU-PR when trained with AnoGen-generated anomalies.
  • Image-level AU-ROC also saw improvements, with DRAEM gaining 1.6% and DeSTSeg 0.5%.
  • Qualitative results show that AnoGen generates diverse and realistic anomalies that are spatially controllable.

Limitations and Future Work

  • Bounding Box Limitations: The generated anomalies are annotated with bounding boxes, not precise pixel-level masks. This necessitates the use of weakly-supervised methods for training segmentation models, which can introduce additional hyperparameters.
  • Future Work: The authors aim to explore methods for generating more precise annotations (e.g., pixel-level masks) for the anomalies, which would make them more readily usable for standard supervised anomaly detection tasks. They also suggest that further research could explore how to obtain more precise annotations when generating anomaly images.

Summary updated

Abstract

Anomaly detection is a practical and challenging task due to the scarcity of anomaly samples in industrial inspection. Some existing anomaly detection methods address this issue by synthesizing anomalies with noise or external data. However, there is always a large semantic gap between synthetic and real-world anomalies, resulting in weak performance in anomaly detection. To solve the problem, we propose a few-shot Anomaly-driven Generation (AnoGen) method, which guides the diffusion model to generate realistic and diverse anomalies with only a few real anomalies, thereby benefiting training anomaly detection models. Specifically, our work is divided into three stages. In the first stage, we learn the anomaly distribution based on a few given real anomalies and inject the learned knowledge into an embedding. In the second stage, we use embedding and given bounding boxes to guide the diffusion model in generating realistic and diverse anomalies on specific objects (or textures). In the final stage, we propose a weakly-supervised anomaly detection method to train a more powerful model with generated anomalies. Our method builds upon DRAEM and DesTSeg as the foundation model and conducts experiments on the commonly used industrial anomaly detection dataset, MVTec. The experiments demonstrate that our generated anomalies effectively improve the model performance of both anomaly classification and segmentation tasks simultaneously, e.g., DRAEM and DseTSeg achieved a 5.8% and 1.5% improvement in AU-PR metric on segmentation task, respectively. The code and generated anomalous data are available at https://github.com/gaobb/AnoGen.
BibTeX
@inproceedings{gao2024few,
  author = {Bin-Bin Gao},
  title = {{Few-Shot Anomaly-Driven Generation for Anomaly Classification and Segmentation}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  url = {https://openreview.net/forum?id=xBC1vCXk5U},
}
Figure