Diffusion-based Image Generation for In-distribution Data Augmentation in Surface Defect Detection

Luigi Capogrosso, Federico Girella, Francesco Taioli, Michele Dalla Chiara, Muhammad Aqeel, Franco Fummi, Francesco Setti, Marco CristaniarXiv 2024

TL;DR

Industrial surface defect detection often fails because real-world defects are rare, leading to models that don't know what a "genuine" flaw looks like. This paper introduces In&Out, a data augmentation strategy that combines traditional "out-of-distribution" synthetic artifacts with realistic "in-distribution" defects generated by Diffusion Models. By balancing these two types of data, the authors achieved a new state-of-the-art Average Precision (AP) of 0.782 on the challenging Kolektor Surface-Defect Dataset 2 (KSDD2).

What Problem Does This Paper Address?

In industrial quality control, automated systems need to spot tiny scratches or cracks on surfaces. The biggest hurdle is data imbalance: you might have thousands of images of "perfect" products (negative samples) but only a handful of "defective" ones (positive samples).

To fix this, researchers usually use data augmentation. Current state-of-the-art methods like MemSeg create synthetic defects by overlaying random noise or textures onto normal images. While this helps the model learn what is not a normal sample (improving precision), these "out-of-distribution" (OOD) artifacts don't look like real defects. Consequently, the models often miss subtle, genuine flaws, leading to poor recall.

Methods

The authors propose a hybrid approach called In&Out, which leverages Denoising Diffusion Probabilistic Models (DDPMs) to generate realistic, "in-distribution" (ID) defects.

The In&Out Pipeline

The strategy splits the augmented data ($N_{aug}$) into two halves:

  1. Out-of-Distribution (OOD): $N_{aug}/2$ samples are generated using traditional methods (like MemSeg) that superimpose noise patches.
  2. In-Distribution (ID): $N_{aug}/2$ samples are generated using a fine-tuned Diffusion Model (Stable Diffusion).
Figure 1: Idea underlying our In&Out data augmentation approach. (Left, blue dots) The blue dots outside the bulk of negative data could be wrongly classified as anomalies (false positives), being slightly different from most of the negative data. (Right, yellow crosses) State-of-the-art per-region data augmentation methods (for example, MemSeg (Yang et al., 2023)) add positive synthetic samples in that zone, which helps in deciding what is certainly not anomalous data. (Left, red dots) On the other hand, the red dot partially outside the bulk of positive data could be, in principle, understood as a negative sample, leading to a false negative. (Right, red crosses) Diffusion-based generated data is capable of producing defects very similar to the ones in the bulk of positive data, helping the classifier not produce false negative classifications.

Training Scenarios

The paper explores two main settings:

  • Zero-shot: When no real defects are available, they fine-tune the DDPM on normal samples and use a "human-in-the-loop" approach. An expert provides text prompts like "scratches" or "cracked" to guide the diffusion model in generating plausible anomalies.
  • N-shot: When a few ($N=5$) or many ($N=246$) real defects are available, they use Dreambooth combined with LoRA (Low-Rank Adaptation) to efficiently fine-tune the model on those specific defect types.
The Zero-shot data augmentation workflow.

Datasets

The primary benchmark is the Kolektor Surface-Defect Dataset 2 (KSDD2). It contains RGB images of production items with defects varying in shape, size, and color—from tiny scratches to large spots. It is considered one of the most challenging datasets in the field because many defects are nearly invisible to the naked eye.

Figure 4: Normal (top row) and anomalous (bottom row) samples from the KSDD2 dataset. Note that some defects are very difficult to find.

Key Insights and Ideas

  • Complementary Strengths: The authors found a clear trade-off. OOD methods (MemSeg) yield high precision (fewer false alarms) because they define clear boundaries of what is "not normal." ID methods (DDPM) yield high recall (fewer missed defects) because they teach the model the actual texture and appearance of real flaws.
  • The "In&Out" Balance: By mixing both, the model achieves a balanced performance that outperforms using either method alone.
  • Diffusion as an Expert Proxy: In zero-shot settings, the diffusion model acts as a bridge between an engineer's domain knowledge (expressed via text prompts) and the visual training data.
  • Efficiency Matters: By using LoRA, the authors could fine-tune large diffusion models on consumer-grade hardware (NVIDIA RTX 4090) without the massive computational overhead usually associated with generative AI.

Key Results

The In&Out approach was tested against a ResNet-50 baseline and existing SOTA methods:

  • State-of-the-Art: On the KSDD2 dataset, In&Out achieved an AP of 0.782, surpassing the previous best of 0.733.
  • Zero-Shot Success: Even with zero real defective samples, the In&Out method achieved an AP of 0.626, significantly higher than using only OOD (0.514) or only DDPM (0.547) augmentations.
  • Recall Boost: In the full-shot scenario, DDPM-based augmentation alone pushed recall to 0.739, compared to MemSeg's 0.717, proving that realistic samples help the model "see" more defects.

Limitations and Future Work

  • Overfitting in Few-Shot: The authors noted that when only a very small number of defects (e.g., $N=5$) are available, the DDPM can overfit to those specific examples, failing to generalize to the broader distribution of possible defects.
  • Prompt Engineering: The quality of zero-shot generation relies heavily on the textual prompts. Future work could explore more automated or robust ways to interact with the DDPM.
  • Dataset Diversity: While successful on KSDD2, the authors suggest further studies on different types of industrial surfaces and materials to prove the method's universality.

Summary updated

BibTeX
@misc{capogrosso2024diffusion,
  author = {Luigi Capogrosso and Federico Girella and Francesco Taioli and Michele Dalla Chiara and Muhammad Aqeel and Franco Fummi and Francesco Setti and Marco Cristani},
  title = {{Diffusion-based Image Generation for In-distribution Data Augmentation in Surface Defect Detection}},
  year = {2024},
  eprint = {2406.00501},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.00501},
}
Figure