This paper proposes an improved YOLOv5 algorithm for metal surface defect detection to address the issues of slow detection speed and low accuracy in traditional YOLO algorithms. The proposed algorithm introduces a Convolutional Block Attention Module (CBAM) consisting of two sub-modules: Spatial Attention Module (SAM) and Channel Attention Module (CAM), which collect attention information in both spatial and channel dimensions and combine them to obtain more comprehensive and reliable attention information. Additionally, the paper introduces the SIOU loss function, which accurately measures the accuracy of object localization by considering the vector angle in boundary box regression. The proposed method achieves significant improvements in detection accuracy by minimizing the difference in vector angles, which allows for better adjustment of the position and orientation of the boundary boxes. Experimental results demonstrate that the improved algorithm increases detection accuracy by 5.7 % compared to the traditional algorithm.