Surface Defect Detection Algorithm for Workpieces Based on Improved YOLOv8
Abstract
1. Introduction
2. Related Work
2.1. Deep Learning-Based Object Detection
2.2. Attention Mechanisms in Object Detection
2.3. Data Augmentation for Defect Detection
3. Materials and Methods
3.1. Overall Framework
3.2. Channel–Spatial Modulation Attention (CASM)
3.2.1. Lightweight Channel Attention (LCA)
- , ;
- is the reduction ratio;
- is the sigmoid activation function.
3.2.2. Guided Spatial Attention (GSA)
- denotes a convolution with kernel size k;
- The concatenated result has 2 channels and is reduced to 1 channel via convolution.
3.2.3. Attention Fusion Modulation
- , automatically balancing channel vs. spatial emphasis;
- This fusion strategy enhances the adaptive feature selection capability of the attention mechanism.
3.3. Small-Scale Grid Texture Shuffling Augmentation
| Pseudocode |
| Input: -Original image I of size H × W -Bounding box B = (xmin, ymin, xmax, ymax) -Grid division size G = (4, 4) Output: -Augmented image I_aug |
| 1: Extract the defect region R = I[ymin:ymax, xmin:xmax] 2. Get height h and width w of R 3. Compute patch height: step_h = floor(h/4), patch width: step_w = floor(w/4) 4. Crop R to (step_h × 4, step_w × 4) 5. Initialize empty patch list P = [] 6. For i = 0 to 3: For j = 0 to 3: P_ij = R[i*step_h: (i + 1)*step_h, j*step_w: (j + 1)*step_w] Append P_ij to P 7. Shuffle patch list P randomly 8. Reconstruct R_shuffled by placing shuffled patches back in order 9. Replace original region in I with R_shuffled→I_aug 10. Return I_aug |
4. Results and Discussion
4.1. Dataset and Experimental Setup
4.2. Evaluation Metrics
4.3. Implementation Details
4.4. Combined Effect of CASM and SG-TSA on YOLOv8n
5. Conclusions
Author Contributions
Funding
Data Availability Statement
Conflicts of Interest
References
- Wang, T.; Chen, Y.; Qiao, M.; Snoussi, H. A fast and robust convolutional neural network-based defect detection model in product quality control. Int. J. Adv. Manuf. Technol. 2018, 94, 3465–3471. [Google Scholar] [CrossRef]
- Rao, X.; Zhang, F.; Lu, Y.; Luo, X.; Chen, F. Surface and subsurface damage of reaction-bonded silicon carbide induced by electrical discharge diamond grinding. Int. J. Mach. Tools Manuf. Des. Res. Appl. 2020, 154, 103564. [Google Scholar] [CrossRef]
- Hong, B.B. Research on Intelligent Detection Technology of Flat Workpiece Based on Deep Learning. Master’s Thesis, Xi’an Polytechnic University, Xi’an, China, 2019. [Google Scholar] [CrossRef]
- Xia, B.; Luo, H.; Shi, S. Improved Faster R-CNN Based Surface Defect Detection Algorithm for Plates. Comput. Intell. Neurosci. 2022, 2022, 3248722. [Google Scholar] [CrossRef]
- Xu, S.; Shao, Z.J. An improved faster RCNN based on Swin transformer for surface defect detection of metal workpieces. In Proceedings of the 2022 6th International Conference on Electronic Information Technology and Computer Engineering, Xiamen, China, 21–23 October 2022. [Google Scholar]
- He, L.; Zheng, L.; Xiong, J. FMV-YOLO: A steel surface defect detection algorithm for real-world scenarios. Electronics 2025, 14, 1143. [Google Scholar] [CrossRef]
- Chen, Y.; Zhang, H. Research on PCB defect detection based on SSD. In Proceedings of the 2022 IEEE 4th International Conference on Civil Aviation Safety and Information Technology (ICCASIT), Dali, China, 12–14 October 2022; IEEE: Washington, DC, USA, 2022; pp. 1–5. [Google Scholar]
- Girshick, R.; Donahue, J.; Darrell, T.; Malik, J. Rich feature hierarchies for accurate object detection and semantic segmentation. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Columbus, OH, USA, 23–28 June 2014. [Google Scholar]
- Li, J.; Zhang, L.; Zheng, W. Improved faster R-CNN and adaptive Canny algorithm for defect detection using eddy current thermography. AIP Adv. 2024, 14, 025310. [Google Scholar] [CrossRef]
- Shi, X.; Zhou, S.; Tai, Y.; Wang, J.; Wu, S.; Liu, J.; Xu, K.; Peng, T.; Zhang, Z. An improved faster R-CNN for steel surface defect detection. In Proceedings of the 2022 IEEE 24th International Workshop on Multimedia Signal Processing (MMSP), Shanghai, China, 26–28 September 2022. [Google Scholar]
- Wang, H.; Han, S.; Li, Q. Research on Experimental Method for Image Recognition of Wire Rope Damage Using Improved YOLOv5. J. Comput. Eng. Appl. 2023, 59, 99. [Google Scholar] [CrossRef]
- Zhao, C.; Shu, X.; Yan, X.; Zuo, X.; Zhu, F. RDD-YOLO: A modified YOLO for detection of steel surface defects. Measurement 2023, 214, 112776. [Google Scholar] [CrossRef]
- Khan, I.U.; Aslam, N.; Aboulnour, M.; Bashamakh, A.; Alghool, F.; Alsuwayan, N.; Alturaif, R.; Gull, H.; Iqbal, S.Z.; Hussain, T. Deep Learning-Based Surface Defect Detection in Steel Products Using Convolutional Neural Networks. Math. Model. Eng. Probl. 2024, 11, 3006–3014. [Google Scholar] [CrossRef]
- Yang, J.; Li, S.; Wang, Z.; Dong, H.; Wang, J.; Tang, S. Using deep learning to detect defects in manufacturing: A comprehensive survey and current challenges. Materials 2020, 13, 5755. [Google Scholar] [CrossRef] [PubMed]
- Lin, Y.; Xiang, Y.; Lin, Y.; Yu, J. Defect detection system for optical element surface based on machine vision. In Proceedings of the 2019 2nd International Conference on Information Systems and Computer Aided Education (ICISCAE), Dalian, China, 28–30 September 2019; IEEE: Washington, DC, USA, 2019; pp. 415–418. [Google Scholar]
- Long, J.; Yang, Y.; Hua, L.; Ou, Y. Self-supervised augmented patches segmentation for anomaly detection. In Proceedings of the Asian Conference on Computer Vision 2023, Macao, China, 4–8 December 2022. [Google Scholar]
- Wang, D.; Yu, W.; Lian, P.; Zhang, M. Textile Defect Detection Algorithm Based on Unsupervised Learning. In Proceedings of the 2022 7th International Conference on Image, Vision and Computing (ICIVC) 2022, Xi’an, China, 26–28 July 2022. [Google Scholar] [CrossRef]
- Xiao, S.; Liu, Z.; Yan, Z.; Wang, M. Grad-MobileNet: A Gradient-Based Unsupervised Learning Method for Laser Welding Surface Defect Classification. Sensors 2023, 23, 4563. [Google Scholar] [CrossRef]
- Roy, A.G.; Navab, N.; Wachinger, C. Concurrent spatial and channel ‘squeeze & excitation’ in fully convolutional networks. In Proceedings of the Medical Image Computing and Computer Assisted Intervention–MICCAI 2018: 21st International Conference, Granada, Spain, 16–20 September 2018. [Google Scholar]
- Hu, J.; Shen, L.; Sun, G. Squeeze-and-excitation networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Salt Lake City, UT, USA, 18–23 June 2018. [Google Scholar]
- Wang, Q.; Wu, B.; Zhu, P.; Li, P.; Zuo, W.; Hu, Q. ECA-Net: Efficient channel attention for deep convolutional neural networks. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, Seattle, WA, USA, 14–19 June 2020. [Google Scholar]
- Lu, X.-Y.; Qu, M.-X. Steel surface defect detection based on improved YOLOv8. Eng. Res. Express 2025, 7, 015262. [Google Scholar] [CrossRef]
- Chen, Y.; Tang, Y.; Hao, H.; Zhou, J.; Yuan, H.; Zhang, Y.; Zhao, Y. AMFF-YOLOx: Towards an attention mechanism and multiple feature fusion based on YOLOx for industrial defect detection. Electronics 2023, 12, 1662. [Google Scholar] [CrossRef]
- Ma, S.; Zhao, X.; Wan, L.; Zhang, Y.; Gao, H. A lightweight algorithm for steel surface defect detection using improved yolov8. Sci. Rep. 2025, 15, 8966. [Google Scholar] [CrossRef]
- Zhou, Z.; Yuan, M. Steelguard-yolo: Steel surface defect detection network based on improved yolov5s. Rev. Int. Metodos Numer. Para Calc. Y Diseno En Ing. 2024, 40, 29. [Google Scholar] [CrossRef]
- Ding, Z.; Zhao, J.; Misra, R.D.K.; Guo, F.; Xie, Z.; Wang, X.; Li, X.; Wang, J.; Shang, C. Deep Learning-Based Understanding of Defects in Continuous Casting Product. Metals 2023, 13, 1809. [Google Scholar] [CrossRef]
- You, C.; Kong, H. Improved steel surface defect detection algorithm based on YOLOv8. IEEE Access 2024, 12, 99570–99577. [Google Scholar] [CrossRef]
- Song, X.; Cao, S.; Zhang, J.; Hou, Z. Steel surface defect detection algorithm based on YOLOv8. Electronics 2024, 13, 3374. [Google Scholar] [CrossRef]
- Yeung, C.C.; Lam, K.M. Efficient fused-attention model for steel surface defect detection. IEEE Trans. Instrum. Meas. 2022, 71, 2510011. [Google Scholar] [CrossRef]
- Shi, J.; Yang, J.; Zhang, Y. Research on steel surface defect detection based on YOLOv5 with attention mechanism. Electronics 2022, 11, 3735. [Google Scholar] [CrossRef]
- Tang, B.; Chen, L.; Sun, W.; Lin, Z.K. Review of surface defect detection of steel products based on machine vision. IET Image Process. 2023, 17, 303–322. [Google Scholar] [CrossRef]
- Guclu, E.; Akin, E. Enhanced defect detection on steel surfaces using integrated residual refinement module with synthetic data augmentation. Measurement 2025, 250, 117136. [Google Scholar] [CrossRef]
- Yang, B.; Liu, Z.; Duan, G.; Tan, J. Mask2Defect: A prior knowledge-based data augmentation method for metal surface defect inspection. IEEE Trans. Ind. Inform. 2021, 18, 6743–6755. [Google Scholar] [CrossRef]
- Ran, G.; Yao, X.; Wang, K.; Ye, J.; Ou, S. Sketch-guided spatial adaptive normalization and high-level feature constraints based GAN image synthesis for steel strip defect detection data augmentation. Meas. Sci. Technol. 2024, 35, 045408. [Google Scholar] [CrossRef]
- Wieler, M.; Hahn, T.; Hamprecht, F.A. Weakly Supervised Learning for Industrial Optical Inspection. [Dataset]. 2007. Available online: https://hci.iwr.uni-heidelberg.de/content/weakly-supervised-learning-industrial-optical-inspection (accessed on 30 October 2025).









| Improvement | CASM | √ | √ | |
|---|---|---|---|---|
| SG-TSA | √ | |||
| Performance | map50 | 75.27% | 75.47% | 76.28% |
| map50-95 | 39.31% | 40.9% | 42.32% | |
| Recall | 69.28% | 69.72% | 71.82% | |
| Crazing | 18.16% | 20.93% | 20.92% | |
| Inclusion | 48.35% | 49.56% | 44.05% | |
| Patches | 57.91% | 62.56% | 64.48% | |
| Pitted surface | 47.12% | 46.58% | 49.04% | |
| Rolled-in scale | 28.64% | 29.37% | 28.4% | |
| Scratches | 35.69% | 36.41% | 47.04% |
| Improvement | CBAM | √ | √ | |
|---|---|---|---|---|
| SG-TSA | √ | |||
| Performance | map50 | 75.27% | 75.6% | 77.12% |
| map50-95 | 39.31% | 40.4% | 41.66% | |
| Recall | 69.28% | 66.53% | 71.24% | |
| Crazing | 18.16% | 19.80% | 19.55% | |
| Inclusion | 48.35% | 43.22% | 46.96% | |
| Patches | 57.91% | 63.89% | 63.10% | |
| Pitted surface | 47.12% | 42.02% | 48.83% | |
| Rolled-in scale | 28.64% | 31.74% | 28.79% | |
| Scratches | 35.69% | 41.71% | 42.74% |
| Algorithm | Map50-95 | GFLOPs | Params |
|---|---|---|---|
| YOLOv8n | 39.31% | 8.1 | 3,012,018 |
| YOLOv8n+CBAM | 40.29% | 8.3 | 3,098,776 |
| YOLOv8n+ECA | 39.86% | 8.1 | 3,006,827 |
| YOLOv8n+SE | 41.05% | 8.1 | 3,017,570 |
| YOLOv8n+CBAM+SG-TSA | 41.66% | 8.3 | 3,098,776 |
| YOLOv8n+CASM+SG-TSA | 42.32% | 8.2 | 3,023,540 |
| YOLOv5n | 39.50% | 7.2 | 2,509,618 |
| YOLOv5n+CASM+SG-TSA | 41.12% | 7.2 | 2,521,156 |
| Algorithm | Map50 | Map50-95 | Recall | FPS |
|---|---|---|---|---|
| YOLOv11n | 76.69% | 41.23% | 75.14% | 103.26 |
| YOLOv11n+CASM+SG-TSA | 78.32% | 42.03% | 76.03% | 93.05 |
| YOLOv12n | 74.97% | 40.26% | 71.44% | 89.15 |
| YOLOv12n+CASM+SG-TSA | 78.32% | 42.88% | 74.47% | 81.45 |
| YOLOv12n+CASM | 75.92% | 40.60% | 74.59% | — |
| YOLOv12n+BAM | 75.11% | 40.16% | 71.52% | 70.08 |
| RT-DETR | 68.43% | 35.99% | 65.02% | — |
| Algorithm | Map50 | Map50-95 | Recall |
|---|---|---|---|
| YOLOv12n+CASM+SG-TSA | 78.32% | 42.88% | 74.47% |
| YOLOv12n+CASM+MixUP | 75.97% | 41.12% | 73.13% |
| YOLOv12n+CASM+Mosaic | 75.97% | 40.60% | 74.59% |
| Improvement | CASM | √ | √ | |
|---|---|---|---|---|
| SG-TSA | √ | |||
| Performance | map50 | 95.3% | 96.4% | 98.2% |
| map50-95 | 64.3% | 67.2% | 69.1% | |
| Recall | 94% | 92.6% | 96.9% | |
| Class1 | 58.3% | 67.1% | 70.2% | |
| Class2 | 72% | 77.8% | 78.5% | |
| Class3 | 66.3% | 76.7% | 62% | |
| Class4 | 48.3% | 45.3% | 58.4% | |
| Class5 | 71.2% | 70.9% | 71.1% | |
| Class6 | 52.1% | 59.5% | 68.9% | |
| Class7 | 65.2% | 64% | 69.1% | |
| Class8 | 57.8% | 58.4% | 61.5% | |
| Class9 | 75.6% | 76.3% | 74.9% | |
| Class10 | 76% | 76.3% | 76.9% |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Share and Cite
An, D.; Why, N.K.; Chua, F. Surface Defect Detection Algorithm for Workpieces Based on Improved YOLOv8. Automation 2026, 7, 32. https://doi.org/10.3390/automation7010032
An D, Why NK, Chua F. Surface Defect Detection Algorithm for Workpieces Based on Improved YOLOv8. Automation. 2026; 7(1):32. https://doi.org/10.3390/automation7010032
Chicago/Turabian StyleAn, Da, Ng Kok Why, and Fangfang Chua. 2026. "Surface Defect Detection Algorithm for Workpieces Based on Improved YOLOv8" Automation 7, no. 1: 32. https://doi.org/10.3390/automation7010032
APA StyleAn, D., Why, N. K., & Chua, F. (2026). Surface Defect Detection Algorithm for Workpieces Based on Improved YOLOv8. Automation, 7(1), 32. https://doi.org/10.3390/automation7010032

