# An Improved YOLOv5 Model for Detecting Laser Welding Defects of Lithium Battery Pole
## 2 Laser Welding Defect Detection Model for Lithium Battery Pole  
### YOLOv5 Algorithm  
The official YOLOv5 source code provides four network models with increasing network depth and feature map width, namely YOLOv5s, YOLOv5m, YOLOv5l, and YOLOv5x. To meet the industrial requirements for defect detection algorithms such as real-time detection and easy deployment, we chose YOLOv5s as the infrastructure, which has the smallest model size and the fastest detection speed. Figure 1 shows the network structure of YOLOv5, which mainly includes four parts: Input, Backbone, Neck, and Head.  
Input includes three modules: Adaptive image scaling, Mosaic data enhancement, and Adaptive anchor frame calculation. When images of different sizes are entered into Input, the algorithm first normalizes the image size to 640 \(\times\) 640 by the adaptive image scaling technique. It then randomly selects four images for cropping, scaling, and layout processing by Mosaic data enhancement before finally inputting them into the network for training. The YOLOv5 algorithm provides nine priori anchor frames trained on the MS COCO dataset, calculates the maximum recall between the standard information of the dataset and the priori anchor frames before starting the training, and uses the K-means algorithm to re-cluster the anchor frames that best fit the dataset when the maximum recall is below 0.98.  
Backbone is the backbone network used to extract the input image features, which mainly consists of Conv Batch Normalization SiLU (CBS), CSP bottleneck with 3 Conv (C3), and Spatial Pyramid Pooling Fast (SPPF) modules. Compared with the previous algorithms, the latest YOLOv5 algorithm uses CBS with 6 \(\times\) 6 convolutional kernels to replace the original Focus module at the first layer of the network, reducing the training time cost. The first CBS was followed by four CBS, four C3 modules, and the SPPF module, which is in the last layer of the backbone network. The input image of 640 \(\times\) 640 \(\times\) 3 is first halved, and the number of channels is changed to four times by 6 \(\times\) 6 convolutional kernels to obtain a 320 \(\times\) 320 \(\times\) 12 feature map and then fed into the CBS and C3 modules. Finally, the feature map was obtained by SPPF to extract advanced semantic information.  
YOLOv5, like YOLOv4, still uses the feature pyramid network and pixel aggregation network (FPN-PAN) structure for its Neck part. The FPN structure transmits semantic information by an up-sampling operation from top to bottom, and the PAN structure transmits location information by a down-sampling process from bottom to top. Combining the two structures enables the network to fuse more feature information, constituting a multi-scale feature fusion module that can retain large-scale and small-scale target feature  
Figure 1: The network structure of the YOLOv5 model.  
information. When the input image is 640 \(\times\) 640, the Head part outputs a feature map grid of 20 \(\times\) 20, 40 \(\times\) 40, and 80 \(\times\) 80, representing its predicted small, medium, and large targets. At the same time, there are three anchor boxes for prediction at each scale, and finally, the prediction box with the highest confidence is filtered by non-maximum suppression.