Enhanced YOLOv8n-based steel surface defect detection using adaptive threshold focal loss, swin transformer, and a high-resolution detection head
摘要
Steel surface defect detection in industrial environments faces three persistent challenges. First, strong reflections and complex textures often confuse defect features with background patterns. Second, due to limited spatial resolution in deep feature pyramids, micro defects are frequently missed. Third, detection-level imbalance and hard-sample imbalance cause rare defect types to be underrepresented during training, leading to poor recall. To address these issues, this paper proposes ATFL-Swin-YOLO. It is an enhanced YOLOv8n-based detection framework for steel surface defect detection. Several advanced components are carefully integrated and adapted. The standard classification loss is replaced with Adaptive Threshold Focal Loss (ATFL). This loss function was originally developed for infrared small target detection. It dynamically adjusts the learning emphasis between easy and hard samples. To better model long-range spatial dependencies and suppress large-scale background interference, Swin Transformer blocks are embedded into the backbone network. A high-resolution P2 detection head is also introduced. It fuses shallow