Official PyTorch Implementation of Advancing Metallic Surface Defect Detection via Anomaly-Guided Pretraining on a Large Industrial Dataset
Pretrained models are commonly employed to improve finetuning performance in metallic surface defect detection, especially in data-scarce environments. However, models pretrained on ImageNet often underperform due to data distribution gaps and misaligned training objectives. To address this, we propose a novel method called Anomaly-Guided Self-Supervised Pretraining (AGSSP), which pretrains on a large industrial dataset containing 120,000 images. AGSSP adopts a two-stage framework: (1) anomaly map guided backbone pretraining, which integrates domain-specific knowledge into feature learning through anomaly maps, and (2) anomaly box guided detector pretraining, where pseudo-defect boxes derived from anomaly maps act as targets to guide detector training. Anomaly maps are generated using a knowledge enhanced anomaly detection method. Additionally, we present two small-scale, pixel-level labeled metallic surface defect datasets for validation. Extensive experiments demonstrate that AGSSP consistently enhances performance across various settings, achieving up to a 10% improvement in mAP@0.5 and 11.4% in mAP@0.5:0.95 compared to ImageNet-based models.
# Our code is based on mmyolo=0.6.0, mmpretrain=1.2.0, mmdet=3.3.0, mmseg=1.2.2.
pip3 install -r requirements.txt# generate anomaly map
cd KeAD/
sh zero_shot_plain_base.sh
# anomaly map to yolo txt
python generate_yolo_box_from_anomaly.py# Change the corresponding configuration in configs
sh run_pretrain.sh
# multi gpu
sh dist_run_pretrain.sh# Change the corresponding configuration in configs
sh run_yolo.sh| Backbone | Detector | Pretrain Method | Pretrain Dataset | mAP@0.5 | mAP@0.5:0.95 | Pretrain Weight | Config |
|---|---|---|---|---|---|---|---|
| CSPDarket | YOLO | cls | ImageNet | 71.6 | 33.5 | - | - |
| CSPDarket | YOLO | cls | Industrial | 72.8 | 34.7 | - | - |
| CSPDarket | YOLO | AGBP | Industrial | 74.9 | 37.5 | - | - |
| CSPDarket | YOLO | AGSSP | Industrial | 77.2 | 44.9 | baiduyun / google | config |
| ResNet50 | YOLO | cls | ImageNet | 69.1 | 32.3 | - | config |
| ResNet50 | YOLO | cls | Industrial | 69.1 | 33.6 | - | - |
| ResNet50 | YOLO | AGBP | Industrial | 72.0 | 36.1 | - | - |
| ResNet50 | YOLO | AGSSP | Industrial | 74.5 | 42.5 | baiduyun / google | config |
| Swin-Base | YOLO | cls | ImageNet | 75.7 | 37.7 | - | config |
| Swin-Base | YOLO | cls | Industrial | 73.3 | 36.0 | - | - |
| Swin-Base | YOLO | AGBP | Industrial | 76.8 | 39.0 | - | - |
| Swin-Base | YOLO | AGSSP | Industrial | 77.7 | 45.0 | baiduyun / google | config |
| Swin-Base | YOLO | SimMIM | ImageNet | 78.3 | 44.3 | - | - |
| Swin-Base | YOLO | SimMIM | Industrial | 76.5 | 41.5 | - | - |
| Swin-Base | YOLO | AGBP | Industrial | 79.8 | 44.3 | - | - |
| Swin-Base | YOLO | AGSSP | Industrial | 78.8 | 48.4 | baiduyun / google | config |
| Swin-Base | Faster R-CNN | SimMIM | ImageNet | 64.6 | 31.7 | - | config |
| Swin-Base | Faster R-CNN | AGBP | Industrial | 71.1 | 38.6 | - | config |
| Swin-Base | Faster R-CNN | AGSSP | Industrial | 73.0 | 41.0 | baiduyun / google | config |
| Swin-Base | DINO | SimMIM | ImageNet | 78.6 | 49.3 | - | config |
| Swin-Base | DINO | AGBP | Industrial | 79.2 | 49.5 | - | config |
| Swin-Base | DINO | AGSSP | Industrial | 79.0 | 50.4 | baidyun / google | config |
If you find our work is useful in your research or applications, please consider giving us a star 🌟 and citing it.
@misc{liu2025advancingmetallicsurfacedefect,
title={Advancing Metallic Surface Defect Detection via Anomaly-Guided Pretraining on a Large Industrial Dataset},
author={Chuni Liu and Hongjie Li and Jiaqi Du and Yangyang Hou and Qian Sun and Lei Jin and Ke Xu},
year={2025},
eprint={2509.18919},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2509.18919},
}
