Leveraging Latent Diffusion Models for Training-Free In-Distribution Data Augmentation for Surface Defect Detection

Federico Girella, Ziyue Liu, Franco Fummi, Francesco Setti, Marco Cristani, Luigi CapogrossoarXiv 2024

TL;DR

DIAG is a novel, training-free data augmentation pipeline that leverages Latent Diffusion Models (LDMs) to generate highly realistic, "in-distribution" surface defects for industrial anomaly detection. By combining expert text prompts with spatial masks, DIAG synthesizes high-quality anomalous images in a zero-shot manner, significantly boosting the accuracy of defect classifiers without requiring massive real-world defect datasets.

What Problem Does This Paper Address?

In industrial manufacturing, automated Surface Defect Detection (SDD) is essential for quality control. However, training reliable deep learning classifiers is notoriously difficult due to a severe data imbalance: defective products (positive samples) are rare, while flawless products (negative samples) are abundant.

To fix this, traditional data augmentation techniques often superimpose artificial noise, random textures, or cut-and-paste artifacts onto normal images. The problem? These methods generate out-of-distribution (OOD) anomalies. Instead of learning what a genuine defect looks like, the downstream classifier simply learns to detect the unrealistic artifacts introduced by the augmentation process. When faced with subtle, real-world defects, these models frequently fail.

Methods

The authors introduce DIAG (Diffusion-based In-distribution Anomaly Generation), a human-in-the-loop pipeline that utilizes a pre-trained, text-conditioned Latent Diffusion Model—specifically Stable Diffusion XL (SDXL) configured for inpainting—without any additional fine-tuning.

The pipeline operates in three main steps:

  1. Expert Input: A domain expert provides multimodal guidance consisting of a spatial defect mask (defining where the anomaly should appear) and a text prompt describing the defect (e.g., "copper metal scratches"). A negative prompt (e.g., "smooth surface") is also used to steer the model away from generating normal textures.
  2. In-Distribution Inpainting: The LDM seamlessly blends the requested defect into the masked region of a normal, defect-free image. Because diffusion models understand context and texture, the generated defect naturally respects the boundaries, lighting, and material properties of the original surface.
  3. Downstream Training: These highly realistic synthetic images are added to the training set to train a standard binary classifier (a ResNet-50 backbone) using Binary Cross-Entropy loss.
The DIAG Pipeline

Datasets

The approach was validated on the Kolektor Surface-Defect Dataset 2 (KSDD2), a challenging, real-world industrial benchmark featuring various surface imperfections like scratches and spots. The dataset contains:

  • Training set: 246 positive (defective) images and 2,085 negative (normal) images.
  • Testing set: 110 positive images and 894 negative images.

All images were standardized to a resolution of $224 \times 632$ pixels for the experiments.

Key Insights and Ideas

  • Foundational Models Don't Need Fine-Tuning for Industry: A major takeaway is that large, pre-trained foundational models like SDXL already possess a deep enough understanding of textures and geometry to generate specialized industrial defects zero-shot, provided they are guided by spatial masks and descriptive prompts.
  • Realism Trumps Quantity: Generating in-distribution defects matters far more than simply generating more data. By matching the true distribution of real defects, the classifier establishes much cleaner and more accurate decision boundaries.
  • The Stochasticity Trade-off: In zero-shot settings, increasing the number of augmented images past a certain threshold ($N_{aug} = 120$) actually caused a slight performance drop. The authors attribute this to the stochastic nature of diffusion models, where an unconstrained model occasionally generates low-quality samples that don't perfectly align with the prompt, introducing noise into the training set.

Key Results

The authors evaluated DIAG under two primary scenarios:

1. Zero-Shot Data Augmentation (No real defects available for training)

When assuming absolutely no real positive samples are available, DIAG achieved an Average Precision (AP) of 0.801 (at 100 augmented images). This vastly outperformed traditional methods like MemSeg (0.388 AP) and the previous state-of-the-art diffusion method, In&Out (0.626 AP).

2. Full-Shot Data Augmentation (Real defects available)

When real positive samples were included alongside the synthetic ones, DIAG pushed the state-of-the-art further, reaching an AP of 0.924, compared to In&Out's 0.782 and MemSeg's 0.734.

3. Qualitative Realism

Using the Fréchet Inception Distance (FID) to measure visual similarity to real defects, DIAG achieved the lowest score by a wide margin (FID 192 of 0.411 vs. In&Out's 1.520 and MemSeg's 4.376), numerically proving that its anomalies look remarkably authentic.

Fig. 2. First row displays some negative samples from the KSDD2 dataset. Instead, the second row shows some images of positive samples from the same dataset. In the third row, we show the MemSeg-generated defect samples. The fourth row shows In&Out generated defect samples. Lastly, the final row showcases images generated with DIAG. Notably, the defect images that DIAG generated are more realistic and in-distribution.

Limitations and Future Work

While DIAG represents a major leap forward, the authors note that the predictability and consistency of the generated images can still vary due to the inherent randomness of diffusion models. Occasionally, the model might fail to fully comply with the text prompt.

Future research will focus on improving quality consistency within the image generation pipeline and evaluating how robust the system remains when human operators provide noisy or imperfect textual prompts.

Summary updated

BibTeX
@misc{girella2024leveraging,
  author = {Federico Girella and Ziyue Liu and Franco Fummi and Francesco Setti and Marco Cristani and Luigi Capogrosso},
  title = {{Leveraging Latent Diffusion Models for Training-Free In-Distribution Data Augmentation for Surface Defect Detection}},
  year = {2024},
  eprint = {2407.03961},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.03961},
}
Figure