arXiv:2609.06232cs.CVSep 2026

Manuscript Offprint

arXiv:2609.06232

Spatial Attention Supervision for Defect Localization: Exploiting Ground-Truth Masks as Training Signal in Diffusion-Augmented Defect Detection

Sajjad Rezvani Boroujeni, Muskan Saraf, Gnana Tulasi Makineni, Tom Bush, Hossein Abedi

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Ground-truth defect masks in industrial inspection datasets are typically reserved for evaluation. This paper repurposes them as spatial supervision signals during the training of classification networks, teaching a model not just what to predict but where to look. The proposed method adds an activation-based attention alignment loss that steers convolutional feature maps toward defect regions, within a mixed-supervision formulation that also accommodates samples without masks, such as diffusion-generated images. Combined with DDPM-based data augmentation, this produces a training regime in which synthetic images contribute quantity and the masks contribute spatial precision. The approach is evaluated across 85 trained models (four CNN backbones under a 2 × 2 data/training factorial design over five seeds, plus a Swin-V2-T transformer baseline over five seeds) on the MVTec-AD bottle benchmark. All localization is evaluated on held-out defect images excluded from classifier gradient updates, with metrics aggregated as mean ± standard deviation across five seeds. The main findings are: (1) on these held-out images, attention-guided training improves activation-based localization (Pixel-AUROC) by +18.0% for EfficientNetB0 in the augmented setting (p=0.005p = 0.005, Cohen's d=2.6d = 2.6) and by +18.7% for ResNet50 (p=0.008p = 0.008), with gains reaching significance in four of the eight CNN settings (all four among the three backbones that respond to the loss; uncorrected for multiple comparisons) and no statistically significant change in classification; (2) for EfficientNetB0 a data × training-mode interaction test is significant (p = 0.002), consistent with a super-additive effect: combining the two improves localization by +13.6% over the real-data, standard-training baseline, beyond the sum of their individual effects (+1.6%; augmentation alone is slightly negative and attention alone gives +5.4%); (3) architectures with weaker spatial representations benefit most, whereas ConvNeXt-T shows no effect, which appears to stem from its depthwise-convolution activations yielding spatially uninformative channel-mean maps; (4) unsupervised PatchCore remains the strongest localizer (Pixel-AUROC=0.983) and serves as a strong reference that contextualizes the supervised gains. Overall, these results show that existing evaluation masks can act as practical training signals that measurably and reproducibly improve where defect classifiers attend.

Keywords: defect localization, spatial attention supervision, activation alignment, diffusion augmentation, glass manufacturing, MVTec-AD, Grad-CAM, PatchCore, transfer learning, industrial quality control

1 Introduction

Automated visual inspection using deep learning has become essential in glass container manufacturing, where defects such as cracks, bubbles, and contamination compromise product integrity and safety [1, 2, 33]. While binary classification (labeling images as defective or non-defective) has seen substantial progress, industrial deployment increasingly demands localization: identifying not just whether a defect exists, but where it is located. Localization supports root-cause analysis, process improvement, and operator trust in automated systems.

Prior work [3] showed that Denoising Diffusion Probabilistic Model (DDPM)-generated synthetic defective images improve CNN-based classification on the MVTec-AD bottle dataset, raising ResNet50V2 accuracy from 78% to 93%. That study, like the broader literature on diffusion-augmented defect detection, reports only image-level metrics (accuracy, F1, AUROC), which leaves a basic question open: when the model makes its decision, does it actually look at the defect?

Ground-truth defect masks exist in standard benchmarks like MVTec-AD and are routinely used for evaluation of localization methods. However, these masks represent untapped potential: they could serve as spatial supervision signals during training of classification networks. While segmentation models (e.g., U-Net) use masks as direct output targets, little prior work uses them as auxiliary attention guidance for classifiers, particularly in a mixed-supervision setting where some training samples have masks and others do not.

This paper introduces spatial attention supervision for defect classification networks. The approach adds an activation-based attention alignment loss during training that encourages convolutional feature maps to activate on actual defect regions, as defined by ground-truth masks. The method operates in a mixed-supervision framework: it uses masks when available and falls back to classification-only loss when they are not. Combined with DDPM augmentation, this creates a dual-path strategy where synthetic data provides quantity and mask supervision provides spatial precision.

The main contributions are:

  • C1: A lightweight activation-alignment approach that uses ground-truth defect masks as an auxiliary spatial-supervision signal (not a direct output target) for classification networks, studied in the specific setting of partial-mask supervision combined with maskless DDPM-generated defective samples within a mixed-supervision formulation.
  • C2: A 2 × 2 study of DDPM augmentation and attention guidance across four CNN architectures, with Swin-V2-T as a transformer baseline, revealing an architecture-dependent interaction: a significant super-additive interaction for EfficientNetB0 (p = 0.002), no significant interaction for MobileNetV2 (approximately additive), and a non-significant sub-additive trend for ResNet50.
  • C3: A multi-architecture benchmark (85 models, 5 backbones, 5 seeds) with held-out classification evaluation and dual localization assessment (activation-based and Grad-CAM), revealing architecture-dependent responses to attention supervision.
  • C4: An evaluation protocol in which localization is measured only on held-out validation images excluded from classifier gradient updates, aggregated across five seeds with paired significance tests and effect sizes, in contrast to prior work that reports single-run localization on training images.

References (32)