# Surface Defect Detection Model for Aero-Engine Components Based on Improved YOLOv5
## 2 Methods and Principles  
### YOLOv5 Algorithm  
The YOLO algorithm is a one-stage object detection algorithm characterized by the direct regression of the location and category of an object after feature extraction. It has the advantages of fast inference speed and high detection accuracy. The author of the YOLO algorithm then proposed the YOLOv2 [17] and YOLOv3 [18] models successively, and their performance showed continuous improvements. In 2020, [PERSON] proposed the YOLOv4 algorithm [19], which modified the backbone network to CSPDarknet53, replaced the activation function with Mish and added a PANet [20] structure based on the FPN [21] from YOLOv3. The YOLOv5 model [22] has been improved on the basis of YOLOv4, with the detection speed being significantly improved and the model size greatly reduced, and it is more suitable for engineering applications. The YOLOv5 algorithm has four models: YOLOv5s, YOLOv5m, YOLOv5l and YOLOv5x. The depth and width of these models increase in turn, and the feature extraction ability also gradually improves. Considering that our algorithm was intended to be deployed and applied in mobile terminals in the future, we selected the lightest YOLOv5s network as the research object, improved it on the basis of our needs and established a model for detection of surface defects in aero-engine components. YOLOv5 is mainly composed of three parts: the backbone, neck and head. The backbone consists of a series of convolutional neural networks used to extract image features, mainly focus, C3 and SPP modules. The focus module slices the images and splices them into the channel dimension to integrate the width and height information into the channel dimension, which can effectively improve the speed of feature extraction. The C3 module is improved from the structure of the cross-stage partial (CSP) connections [23], having one less convolution layer and changing the activation function, and its main function is to extract features from images and reduce the repetition of gradient information. The spatial pyramid pooling (SPP) module respectively uses three pooling kernels of sizes 5, 9 and 13 to perform max-pooling operations on the images. This module can increase the receptive field of the network and obtain features of different scales. The neck is the feature fusion network of the model, where feature pyramid networks (FPNs) and path aggregation network (PANet) are adopted. The structure of the FPNs transmits semantic information from the top down, while the PANet additionally transmits location information from the bottom up on the basis of the FPNs. The head is the prediction network of the model and, through convolution operations, three groups of feature vectors containing the categories prediction boxes, confidence and coordinate position are output, which predict at scales of 80 \(\times\) 80, 40 \(\times\) 40 and 20 \(\times\) 20, respectively. The architecture of YOLOv5s is shown in Figure 1, where k represents the convolution kernel size, C3(T) represents the C3 module containing a residual structure, C3(F) does not contain a residual structure, Upsample is the upsampling operation and CBS is the standard convolution process consisting of Conv (the convolution layer), BN (batch normalization) and SiLu (activation function). Figure 1: The architecture of YOLOv5s. A loss function is used to measure the extent to which the predicted value of the model is different from the true value and largely determines the performance of the model. The loss functions of YOLOv5 include positioning loss (box_loss), confidence loss (obj_loss) and classification loss (cls_loss). Box_loss calculates the error between the prediction box and the real labeling box using the _GloU_loss_ function.