Industrial Anomaly Detection and Localization Using Weakly-Supervised Residual Transformers

Hanxi Li, Jingqi Wu, Hao Chen, Mingwen Wang, Chunhua Shen, Wang, Mingwen, Shen, Chunhua · DOI

Abstract

Recent advancements in industrial anomaly detection (AD) have demonstrated that incorporating a small number of anomalous samples during training can significantly enhance accuracy. However, this improvement often comes at the cost of extensive annotation efforts, which are impractical for many real-world applications. In this paper, we introduce a novel framework, Weakly-supervised RESidual Transformer (WeakREST), designed to achieve high anomaly detection accuracy while minimizing the reliance on manual annotations. First, we reformulate the pixel-wise anomaly localization task into a block-wise classification problem. Second, we introduce a residual-based feature representation called Positional Fast Anomaly Residuals (PosFAR) which captures anomalous patterns more effectively. To leverage this feature, we adapt the Swin Transformer for enhanced anomaly detection and localization. Additionally, we propose a weak annotation approach, utilizing bounding boxes and image tags to define anomalous regions. This approach establishes a semi-supervised learning context that reduces the dependency on precise pixel-level labels. To further improve the learning process, we develop a novel ResMixMatch algorithm, capable of handling the interplay between weak labels and residual-based representations. On the benchmark dataset MVTec-AD, our method achieves an Average Precision (AP) of $83.0\%$, surpassing the previous best result of $82.7\%$ in the unsupervised setting. In the supervised AD setting, WeakREST attains an AP of $87.6\%$, outperforming the previous best of $86.0\%$. Notably, even when using weaker annotations such as bounding boxes, WeakREST exceeds the performance of leading methods relying on pixel-wise supervision, achieving an AP of $87.1\%$ compared to the prior best of $86.0\%$ on MVTec-AD.

Introduction

In industrial manufacturing, detecting defects is critical for quality control. However, researchers often face a dilemma: unsupervised methods are easy to deploy but struggle with subtle defects, while supervised methods offer high accuracy but require painstaking pixel-level annotations. This "annotation bottleneck" makes high-performance AD impractical for many factory lines.

Comparison of conventional pixel-level supervision versus the proposed weakly-supervised block classification approach.

WeakREST addresses this by bridging the gap between unsupervised and fully supervised learning. By treating anomaly localization as a block-wise classification task and utilizing "weak" labels—such as quick bounding boxes or simple image-level tags—the framework achieves elite performance with a fraction of the human labor. A user study conducted by the authors showed that image tags take approximately 0.5 seconds and bounding boxes take 5 seconds to produce, compared to over 32 seconds for pixel-level masks.

Methodology

The WeakREST framework introduces several key technical innovations to handle weak supervision effectively:

  • Block-wise Reformulation: Instead of classifying every pixel, the model divides the image into blocks. This reduces task complexity and aligns better with coarse annotations like bounding boxes.
  • Positional Fast Anomaly Residuals (PosFAR): Rather than feeding raw features into a network, PosFAR calculates the "residual" (the difference) between a test patch and the most similar "normal" patches from a reference bank. It incorporates positional encoding to help the model understand that certain features may be normal in one part of an object but anomalous in another.
  • Swin Transformer Backbone: The model utilizes a modified Swin Transformer to process these residual tokens, allowing it to analyze spatial relationships between different image regions to confirm anomalies.
  • ResMixMatch: To manage the uncertainty of weak labels (e.g., the non-defective space inside a bounding box), the authors developed a semi-supervised algorithm that "guesses" labels for unlabeled blocks and uses data augmentation to ensure robustness.
The WeakREST architecture featuring Positional Fast Anomaly Residuals (PosFAR) and a Swin Transformer backbone.

Experiments and Results

The framework was evaluated on major industrial benchmarks, including MVTec-AD, MVTec 3D-AD, and KSDD2.

  • State-of-the-Art Performance: On MVTec-AD, WeakREST achieved an Average Precision (AP) of 83.0% in the unsupervised setting.
  • Efficiency of Weak Labels: Remarkably, when trained only on bounding boxes, WeakREST achieved 87.1% AP, outperforming previous state-of-the-art methods that required full pixel-level supervision (86.0%).
  • Real-World Robustness: On the challenging KSDD2 surface defect dataset, the method reached 76.4% AP in the unsupervised setting, a significant jump from the previous best of 64.1%.
  • Inference Speed: By employing Principal Component Analysis (PCA) to compress features, the authors doubled the algorithm's speed with negligible impact on accuracy.

Conclusion

WeakREST demonstrates that high-precision industrial anomaly detection is possible without the need for expensive, pixel-perfect labels. By focusing on the "difference from normality" through residual features and leveraging the spatial context of Transformers, the model achieves superior results even with coarse human input. Future research may extend this residual approach to 3D data and further optimize the exploitation of unlabeled regions in defective samples.

Summary updated

BibTeX
@misc{li2023industrial,
  author = {Hanxi Li and Jingqi Wu and Hao Chen and Mingwen Wang and Chunhua Shen and Wang, Mingwen and Shen, Chunhua},
  title = {{Industrial Anomaly Detection and Localization Using Weakly-Supervised Residual Transformers}},
  year = {2023},
  eprint = {2306.03492},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.03492},
}
Figure