Ground-truth defect masks in industrial inspection datasets are typically reserved for evaluation. This paper repurposes them as spatial supervision signals during training of classification networks, teaching a model not just what to predict but where to look. The method adds an activation-based attention alignment loss that steers convolutional feature maps toward defect regions, in a mixed-supervision formulation that also accommodates samples without masks, such as diffusion-generated images. Combined with DDPM augmentation, synthetic images contribute quantity while masks contribute spatial precision. We evaluate 85 models (four CNN backbones under a 2x2 data/training factorial over five seeds, plus a Swin-V2-T transformer baseline) on the MVTec-AD bottle benchmark, with localization measured on held-out defect images excluded from classifier gradient updates. Main findings: (1) attention-guided training improves activation-based localization (Pixel-AUROC) by +18.0% for EfficientNetB0 with augmentation (p=0.005, Cohen's d=2.6) and +18.7% for ResNet50 (p=0.008), significant in four of eight CNN settings (uncorrected for multiple comparisons) with no significant change in classification; (2) for EfficientNetB0 a data x training-mode interaction is significant (p=0.002), consistent with a super-additive effect (+13.6% combined vs +1.6% summed individual effects); (3) architectures with weaker spatial representations benefit most, whereas ConvNeXt-T shows no effect, apparently because its depthwise-convolution activations yield spatially uninformative channel-mean maps; (4) unsupervised PatchCore remains the strongest localizer (Pixel-AUROC=0.983), contextualizing the supervised gains. These results show that existing evaluation masks can act as practical training signals that measurably and reproducibly improve where defect classifiers attend.
Figures & tables
Approach
Use of Masks
Difference from Proposed
Segmentation (U-Net, DeepLab)
Direct output target
Predicts mask; typically trained with dense mask supervision
Ross et al. [ 15 ]
Gradient penalty
Input gradients (not activations); not industrial
Kasem et al. [ 13 ]
None (architectural)
CBAM modules in architecture, not a training loss
Region-Aware CAM [ 14 ]
Evaluation only
Weakly-supervised; no mask-guided training
PatchCore [ 20 ]
Evaluation only
Unsupervised; masks unused during training
Prior work [ 3 ]
Evaluation only
DDPM augmentation for classification; no localization
Table 1: Positioning relative to prior work. Among the approaches reviewed, the proposed method is distinctive in combining auxiliary mask supervision with diffusion augmentation in a mixed-supervision setting.
Figure 1: Pipeline overview. Data: MVTec-AD bottle with optional DDPM augmentation. Training: 85 models total, four CNN backbones under a 2×2 factorial (data setting × training mode) across five seeds, plus Swin-V2-T baseline across five seeds. Evaluation: held-out classification metrics and held-out localization via Pixel-AUROC.
Backbone
Type
Year
Params
Input Size
EfficientNetB0 [ 25 ]
CNN
2019
5.3M
224 × 224
MobileNetV2 [ 26 ]
CNN
2018
3.5M
224 × 224
ResNet50 [ 27 ]
CNN
2016
25.6M
224 × 224
ConvNeXt-T [ 28 ]
CNN
2022
28.6M
224 × 224
Swin-V2-T [ 29 ]
Transformer
2022
28M
256 × 256
Table 2: Backbone Architectures.
Backbone
Config
F1
AUROC
Recall
EfficientNetB0
Real, Std
.888 ± .072
.961 ± .048
.911
Real, AG
.878 ± .086
.949 ± .066
.911
Aug, Std
.902 ± .063
.975 ± .016
.842
Aug, AG
.886 ± .052
.977 ± .012
.827
MobileNetV2
Real, Std
.844 ± .067
.962 ± .031
.867
Real, AG
.878 ± .058
.971 ± .018
.889
Table 3: Held-out classification performance (F1 and AUROC as mean ± std across 5 seeds; Recall as mean). Best F1 per backbone in bold. For ConvNeXt-T, standard and attention-guided training yield classification metrics that coincide to three decimal places (the alignment loss produces no discernible change in its classification; see Section 6.1 ), so the two modes are reported jointly as “Std/AG.”
Figure 2: ( a ) Held-out classification F1 across four training configurations for three CNN architectures. Swin-V2-T reference line at F1=1.000. ( b ) Best configuration per architecture, showing ConvNeXt-T and Swin-V2-T dominate classification while lighter CNNs achieve 0.88 to 0.90 F1.
Backbone
Data
Std
AG
Δ
p
d
EfficientNetB0
Real
0.552 ± .047
0.582 ± .058
+5.4%
0.051
1.23
+DDPM
0.531 ± .063
0.627 ± .040
+18.0%
0.005
2.57
MobileNetV2
Real
0.563 ± .053
0.585 ± .055
+4.0%
0.020
1.68
+DDPM
0.562 ± .054
0.588 ± .044
+4.5%
0.238
0.62
ResNet50
Real
0.464 ± .045
0.550 ± .049
+18.7%
0.008
2.18
+DDPM
0.454 ± .040
0.509 ± .013
+12.0%
0.023
1.61
Table 4: Held-out localization (activation-based Pixel-AUROC, mean ± std across 5 seeds). Each model is evaluated only on held-out validation defect images excluded from its gradient updates. Δ is the relative change from standard (Std) to attention-guided (AG); p is a paired t -test (by seed) and d is Cohen’s d . Significant improvements ( p<0.05 , uncorrected for multiple comparisons) in bold. Swin-V2-T (occlusion) and PatchCore (unsupervised) are localization references. 0 0 footnotetext: † ConvNeXt-T shows no consistent effect and very high seed variance; a plausible explanation is that its depthwise-convolution activations are spatially uninformative, which would leave the alignment loss with little useful gradient (Section 6.1 ).
Figure 3: ( a ) Held-out activation-based localization (Pixel-AUROC): standard vs. attention-guided across three CNN architectures and two data settings, with error bars (std across 5 seeds) and the PatchCore reference line. ( b ) 2×2 decomposition for EfficientNetB0: DDPM augmentation and attention guidance together show a significant super-additive interaction ( p=0.002 ; Section 5.3 ).
Figure 4: Held-out activation-based vs. Grad-CAM localization for the four CNN backbones (AugmentedData-trained, evaluated on held-out defect images). Arrows show the shift from standard (circle) to attention-guided (square) training. All points fall below the diagonal, indicating that Grad-CAM outperforms raw activation maps. Arrows point upward for EfficientNetB0, MobileNetV2, and ResNet50, showing that attention guidance improves activation-based localization while leaving Grad-CAM largely unchanged. ConvNeXt-T’s arrow does not point up: its activation map is spatially uninformative and high-variance, and the alignment loss does not improve it, even though its Grad-CAM localization is the strongest of all backbones (see Section 6.1 ).
Backbone
Data
Std
AG
Δ
p
d
EfficientNetB0
Real
0.749 ± .041
0.753 ± .041
+0.5%
0.526
0.31
+DDPM
0.752 ± .064
0.772 ± .039
+2.6%
0.323
0.50
MobileNetV2
Real
0.623 ± .086
0.623 ± .063
0.0%
0.993
0.00
+DDPM
0.696 ± .073
0.703 ± .051
+1.1%
0.714
0.18
ResNet50
Real
0.543 ± .023
0.579 ± .025
+6.6%
0.044
1.30
+DDPM
0.485 ± .044
0.537 ± .026
+10.7%
0.024
1.59
Table 5: Held-out Grad-CAM localization (Pixel-AUROC, mean ± std across 5 seeds), reported as in Table 4 . Δ is the standard → attention-guided change; p is a paired t -test (by seed) and d is Cohen’s d . Grad-CAM values exceed the activation-based ones (cf. Table 4 ); attention guidance transfers to Grad-CAM significantly only for ResNet50 (significant improvements in bold).
Figure 5: Qualitative comparison of activation heatmaps for EfficientNetB0 (AugmentedData). Columns: input image, ground-truth mask, standard training heatmap, attention-guided heatmap. Attention-guided models produce activations that are visually more concentrated on the actual defect regions.
School of Cyber Science and Technology, Shenzhen Campus of Sun Yat-sen University · School of Artificial Intelligence and Robotics, Hunan University · Department of Computer and Information Science, University of Macau +1