An Improved YOLOv5x-Based Algorithm for IC Pin Welding Defects Detection

This study suggests an integrated circuit (IC) pin welding defect detection algorithm based on improved YOLOv5x to address the issues of low detection accuracy caused by small target size and dense pin arrangement in IC pin welding defects identification. The ability of the network to extract features is improved by effective fusing of features with various receptive fields through the inclusion of the D-SPP module to merge different channel information. The introduction of the mask self-attention mechanism module increases the network’s capacity to recognize global feature correlations and raises the algorithm’s detection precision. In order to speed up the model’s convergence and tackle the issue of sample imbalance in BBox regression, the Focal-EIoU loss function is applied. The detection accuracy and speed are increased by using the k-means++ clustering algorithm to create nine clustering centers to figure out the size of the prior box. According to the results of the experiment, the new method achieves average precisions for short-circuit, missing pin, pin-cocked, and little tin faults in IC pin welding of 96.7%, 94.5%, 95.6%, and 93.3%, respectively. The mean average precision increases to 95.0% at a threshold of 0.5, which is 13.3% and 8.9% greater than YOLOv3 and YOLOv5x, respectively. A reference value for IC pin welding defect identification is provided by the improved algorithm, which has a detection time of 0.142 seconds per image. This meets the speed requirements of IC quality inspection.


Introduction
With the rapid development of information technology, the integration level of electronic products is increasing, and they are gradually becoming smaller, more intelligent, and more integrated.IC has become increasingly important in the information industry and are widely used in the fields of electronics, semi-conductors, and artificial intelligence [23].After the IC chip and other electronic components go through processes such as silk screen printing and surface mount technology (SMT), they are welded on the printed circuit board (PCB) and ultimately used to implement corresponding functions in electronic products [30].Whether various electronic products can operate normally and the length of their service life are closely related to the quality of the PCB.The quality of the PCB depends on the welding quality of its electronic components.If PCBs with welding problems enter the market for assembly and production, they may cause equipment damage during use, which could result in significant economic losses and even endanger personal safety in severe cases [28].Therefore, it is necessary to perform fast and accurate detection of PCB defects in the production process, among which IC pin welding defect detection is one of the most important detections in PCB defect detection.IC pin welding defect detection can effectively prevent defective circuit boards from entering subsequent processes and minimize losses as much as possible.

Related Works
Traditional PCB defect detection methods include visual inspection, online testing, and functional testing [22].Among them, visual inspection relies on human eyesight to directly observe the circuit board through equipment such as magnifying glasses.Its main advantages are low cost and no need for fixtures or other equipment.However, its disadvantages are that it is easily affected by subjective factors such as the work experience and emotions of the personnel, leading to lower accuracy and efficiency in defect detection.The main method of online testing is flying probe testing, which has the advantages of flexibility and fast testing.However, it belongs to contact measurement and may cause secondary damage to the circuit board to a certain extent.Functional testing is based on the principle of automated testing and uses various testing equipment to test specific boards or units.Its disadvantages are slow testing speed and lack of support for parameter measurement.
Machine vision is a non-contact and non-destructive automatic inspection technology [24], which has developed rapidly in recent years and has been widely applied in industrial quality inspection.The applica-tion of machine vision for PCB defect detection has also received much attention.Keenan et al. [9] developed a non-invasive technique for photographing the component circuits of ICs and used infrared laser beam detection technology to inspect flaws in integrated circuits on PCBs.Yamada et al. [29] used high-sensitivity micro eddy current probes along with image processing technologies.By using differential and filtering operations between standard images and test images of PCBs, Ibrahim et al. [6] successfully reduced the noise produced during image preprocessing, minimizing errors or uneven binarization.In order to fully detect PCB defects, Kumar et al. [10] suggested picture enhancing techniques as color plane extraction and LUT transformation, as well as a standard data creation approach.In order to efficiently identify flaws in bare PCBs such etching, short circuits, and open circuits, Kaur et al. [8] proposed applying image differential operations.Gaidhane et al. [3] used a similarity measurement technique that allowed for the direct quantification of similarity between scene photos of PCB surfaces and reference images without the need for image feature computations.In summary, methods based on traditional image processing and machine vision have some progress, with basic steps such as feature extraction and template matching.However, for different PCBs, re-modeling is required, which has the shortcomings of being time-consuming and cumbersome.
In recent years, with the successful application of deep learning models in fields such as face recognition, defect detection and object tracking [27,31,15], deep learning-based PCB defect detection has also developed rapidly.Park et al. [17] developed the Mars-Net construction, which improves the Dilated Residual Network (DRN) to increase feature map resolution.Additionally, they created Horizontal Vertical Pooling (HVP) to improve pooling efficiency by obtaining positioning data from the feature maps.In order to improve PCB defect detection performance, Ding et al. [2] created a Tiny Defect Detection Network (TDD-Net) based on Faster R-CNN.This network improves the connections between feature maps at different levels.A cascaded CNN network was utilized by Cai et al. [1] to identify SMT welding junctions.Two other CNN networks received the input image and the adaptive image learning results from one CNN network.This approach eliminates the requirement to extract low-level features by simply completing the detection operation.Ran et al. [18] proposed a PCB defect detec-tion and recognition algorithm based on SSD, which customizes different scale bounding boxes using multi-scale feature mapping, predicts classification results and boundary box information using small convolution kernels, and optimizes the detection results using NMS algorithm.The Edge and Multi-scale Reverse Attention Network (EMRA-Net), created by Lin et al. [11], incorporates a new Pyramid Edge Module and a Multi-scale Fusion (MSF) module in the feature extraction procedure.These modules are used to obtain features with different resolutions and sizes.A CNN-based two-stage object detection framework was developed by Luo et al. [16].They used a Locally Non-Local (LNL) module to improve defect classification accuracy and a Multi-Hierarchical Aggregation (MHA) module to improve the localization accuracy of non-prominent faults.While the above networks enhance the accuracy of defect detection to a certain extent, they are not without limitations.
Particularly, in cases where the dataset is large, the excessive computation can significantly impact both the learning process of the model and the detection speed.Consequently, they fail to meet the real-time detection requirements.

Testing Process
In order to solve the difficulty in detection of small and dense IC pins, this paper proposes an improved YOLOv5x algorithm to detect defects in IC pin welding.The detection process diagram is given in Figure 1, and the specific procedure of model establishment can be divided into the following four steps: a Firstly, annotate the collected IC pin welding defect images and create a dataset in Pascal VOC format.

Network Model Algorithm
Deep learning-based object detection algorithms can be broadly categorized into two types: two-stage detection algorithms and one-stage detection algorithms.On the one hand, two-stage object detection algorithms divide the detection task into two stages.First, they identify candidate regions where objects may be present and make preliminary judgments about whether they contain objects.Then, they classify and regress these candidate regions to refine their positions and ultimately output the object's category.Representative algorithms in this category include R-CNN [4], Fast R-CNN [5], and Faster R-CNN [21].
On the other hand, one-stage object detection algorithms do not have a separate stage for generating

Figure 2
The network structure diagram of IC pin welding defect detection based on YOLOv5x candidate regions.Instead, they directly output the probability of object categories along with the corresponding position coordinates.Representative algorithms in this category include YOLO [19], YOLOv3 [20], SSD [14], and others.In 2020, Jocher et al. [7] introduced the YOLOv5 algorithm.YOLOv5 comprises five different models, namely YOLOv5n, YOLOv5s, YOLOv5m, YOLOv5l, and YOLOv5x.These five models share a common internal structure but differ in their depth and width factors.Consequently, the models vary in size, parameter count, network depth, detection accuracy, and detection speed.Notably, YOLOv5x exhibits exceptional detection accuracy.Therefore, this paper selects the YOLOv5x model for the design of the IC pin welding defect detection algorithm.

YOLOv5x Network Model
The network structure of IC pin welding defect detection based on YOLOv5x is shown in Figure 2. The backbone network is the CSPDarknet53 network [26], the neck network is a combination of Feature Pyramid Networks (FPN) [12] and Path Aggregation Network (PAN) [13], and the detection head has outputs in three different scales.The IC pin welding defect detection network based on YOLOv5x includes two types of CSP structures: CSP1_x and CSP2_x.The CSP1_x, Focus, and SPP structures are used to improve the backbone network, while the CSP2_x, FPN,

Figure 2
The network structure diagram of IC pin welding defect detection based on YOLOv5x

Improved YOLOv5x Network Model
The algorithm presented in this paper is an enhancement built upon the foundation of the YOLOv5x algorithm.The and PAN are combined to form the neck network, which strengthens the fusion of features at different scales and enhances the network's ability to extract features of IC pin welding defects.

Improved YOLOv5x Network Model
The algorithm presented in this paper is an enhancement built upon the foundation of the YOLOv5x algorithm.The following sections provide an introduction to the modifications made in three aspects: D-SPP, Masked Self-Attention Mechanism, and Loss Function.

D-SPP Module
The YOLOv5x algorithm uses the SPP module in the backbone network to obtain information at different receptive field sizes.However, the SPP module cannot fully integrate local and global information, which may result in information loss.This paper proposes the D-SPP module, as shown in Figure 3.The structure adopts a method similar to spatial attention to embed SPP into SPPF to generate adaptive weights for features at different scales.By combining information from different channels, features from different receptive fields can be efficiently fused, enhancing feature representation capacity.
The D-SPP module generates adaptive spatial weights for features with different receptive fields through a combination of convolutional and pooling operations.Initially, it employs pooling branches with fixed scales and then utilizes the SPP module to extract information, embedding spatial details.By weighting and fusing contextual features, it generates new features enriched with multiscale contextual information.These newly generated feature maps, obtained through two successive max-pooling operations, are subsequently fused with the previously obtained feature maps.Initially, it employs pooling branches with fixed scales and 2 Masked Self-Attention Mechanism This paper introduces a Masked Self-Attention Mechanism module [25] to enhance the network's ability to capture global feature relationships.The module is embedded after the output of the effective feature layer and before the input of the prediction layer in the neck network.The Masked Self-Attention Mechanism operates on feature maps of three sizes: large, medium, and small, to detect IC pin welding defects at multiple scales, thereby improving detection accuracy of the algorithm.The structure of Masked Self-Attention Mechanism module is shown in Figure 4.  pooling operations, are subsequently fused with the previously obtained feature maps.

2) Masked Self-Attention Mechanism
This paper introduces a Masked Self-Attention Mechanism module [25] to enhance the network's ability to capture global feature relationships.The module is embedded after the output of the effective feature layer and before the input of the prediction layer in the neck network.The Masked Self-Attention Mechanism operates on feature maps of three sizes: large, medium, and small, to detect IC pin welding defects at multiple scales, thereby improving detection accuracy of the algorithm.The structure of Masked Self-Attention Mechanism module is shown in  In Figure 4, the input feature map X is multiplied by convolution kernels W Q , W K and W V to generate query vector matrix Q, key vector matrix K and value vector matrix V, respectively.By performing inner product operations on query vector matrix Q and key vector matrix K through scaled dot-product, attention scores are obtained through Softmax activation function normalization.The attention scores are then subject to mask calculation, and finally multiplied by value vector matrix V to obtain the output of self-attention.The output of the Masked Self-Attention module is shown in Equation (1).
feature maps, obtained through two successive maxpooling operations, are subsequently fused with the previously obtained feature maps.

3) Loss Function
The loss function of the improved YOLOv5x algorithm consists of confidence loss, classification loss and boundary box regression loss.The confidence loss and classification loss are calculated using binary cross- 3

Loss Function
The loss function of the improved YOLOv5x algorithm consists of confidence loss, classification loss and boundary box regression loss.The confidence loss and classification loss are calculated using binary cross-entropy loss function, while the boundary box regression loss is calculated using Focal-EIoU.In Focal-EIoU Loss, the width and height losses directly minimize the difference between the widths and heights of target box and anchor box, which speeds up convergence and solves the vague definition problem of CIoU aspect ratio.Furthermore, Focal Loss is added to address the sample imbalance problem in BBox regression.The formulas for calculating Focal-EIoU Loss are shown in Equations ( 2)-( 3).The complete loss function is shown in Equation ( 4). ( (3) ( (3) 3) FPS represents the ratio between the total number of test samples and the time taken to perform detection on these test samples.The calculation formula is as follows: . ( 7) N represents the total number of test samples, and T represents the time expended for the detection process on these test samples.

Experiment Preparation
In Equation ( 4), 3) FPS represents the ratio between the total number of test samples and the time taken to perform detection on these test samples.The calculation formula is as follows: . ( 7) N represents the total number of test samples, and T and In Equation ( 4), L ij obj and L ij noobj represent the probabilities of the j th anchor box in the i th grid containing and not containing defects, respectively.The value is 1 when the box contains defects, and 0 otherwise.C i represents the confidence level of the j th predicted box in the i th grid, while C i represents the confidence level of the truth box.
p i represents the probability value of the predicted box for its class, and p i represents the probability value of the truth box for its class.

Evaluation Indicators
In the task of detecting defects in IC pin welding, the .
M represents the number of defect categories, and in this study, we have focused on four distinct defect categories; therefore, M=4.Here, AP i denotes the Average Precision for each individual defect class.
3) FPS represents the ratio between the total number of test samples and the time taken to perform detection on these test samples.The calculation formula is as follows: (7) represent the probabilities of the j th anchor box in the i th grid containing and not containing defects, respectively.The value is 1 when the box contains defects, and 0 otherwise.
n Equation (4), L ij obj and L ij noobj represent the probabilities f the j th anchor box in the i th grid containing and not ontaining defects, respectively.The value is 1 when the ox contains defects, and 0 otherwise.C i represents the onfidence level of the j th predicted box in the i th grid, hile C i represents the confidence level of the truth box.
i represents the probability value of the predicted box for ts class, and p i represents the probability value of the truth ox for its class. .
M represents the number of defect categories, and in this study, we have focused on four distinct defect categories; therefore, M=4.Here, AP i denotes the Average Precision for each individual defect class.
3) FPS represents the ratio between the total number of test samples and the time taken to perform detection on these represents the confidence level of the j th predicted box in the i th grid, while C i represents the confidence level of the truth box.3) FPS represents the ratio between the total number of test samples and the time taken to perform detection on these represents the probability value of the predicted box for its class, and p i represents the probability value of the truth box for its class.

Evaluation Indicators
In the task of detecting defects in IC pin welding, the performance of the algorithm is mainly evaluated based on its detection accuracy and speed.The detection accuracy mainly includes Average Precision (AP) and Mean Average Precision (mAP).Detection speed is generally measured in Frames Per Second (FPS).
1 AP is a metric used to assess the detection accuracy of individual defect categories within the IC pin welding defect dataset.AP is determined by the area under the Precision-Recall curve, with both precision and recall calculated from the confusion matrix.A higher AP value indicates a better detection performance for a particular category.The calculation method for AP is as follows:

Data Enhanceme
When the number of trainin deep learning algorithms making it challenging t augmentation is a comm mitigates overfitting and fa 2 mAP serves as a metric for assessing the detection accuracy across all defect categories within the IC pin welding defect dataset.mAP is calculated as the average of the AP values for each individual defect category.The calculation method for mAP is as follows: (4) In Equation ( 4), L ij obj and L ij noobj represent the probabilities of the j th anchor box in the i th grid containing and not containing defects, respectively.The value is 1 when the box contains defects, and 0 otherwise.C i represents the confidence level of the j th predicted box in the i th grid, while C i represents the confidence level of the truth box.
p i represents the probability value of the predicted box for its class, and p i represents the probability value of the truth box for its class.

Evaluation Indicators
In the task of detecting defects in IC pin welding, the performance of the algorithm is mainly evaluated based on its detection accuracy and speed.The detection accuracy mainly includes Average Precision (AP) and Mean Average Precision (mAP).Detection speed is generally measured in Frames Per Second (FPS).
1) AP is a metric used to assess the detection accuracy of individual defect categories within the IC pin welding defect dataset.AP is determined by the area under the Precision-Recall curve, with both precision and recall calculated from the confusion matrix.A higher AP value indicates a better detection performance for a particular category.The calculation method for AP is as follows: . ( 5) .
M represents the number of defect categories, and in this study, we have focused on four distinct defect categories; therefore, M=4.Here, APi denotes the Average Precision for each individual defect class.
3) FPS represents the ratio between the total number of test samples and the time taken to perform detection on these test samples.The calculation formula is as follows: .
N represents the total number of test samples, and T represents the time expended for the detection process on these test samples.

Image Acquisition
The experimental data in this paper was collected by the constructed image acquisition hardware platform.The computer issued the acquisition instruction, and the motion controller controlled the PCB to move on the track and stop at the specified position.Then the light source was turned on, and the camera captured the image of the IC, which was then stored in the computer.A total of 1000 images .
M represents the number of defect categories, and in this study, we have focused on four distinct defect categories; therefore, M=4.Here, AP i denotes the Average Precision for each individual defect class.
3 FPS represents the ratio between the total number of test samples and the time taken to perform detection on these test samples.The calculation formula is as follows: P is a metric used to assess the detection accuracy of vidual defect categories within the IC pin welding ct dataset.AP is determined by the area under the ision-Recall curve, with both precision and recall ulated from the confusion matrix.A higher AP value cates a better detection performance for a particular gory.The calculation method for AP is as follows: . ( 5) M represents the number of defect categories, and in this study, we have focused on four distinct defect categories; therefore, M=4.Here, APi denotes the Average Precision for each individual defect class.
3) FPS represents the ratio between the total number of test samples and the time taken to perform detection on these test samples.The calculation formula is as follows: . ( 7) N represents the total number of test samples, and T represents the time expended for the detection process on these test samples.

Image Acquisition
The experimental data in this paper was collected by the constructed image acquisition hardware platform.The computer issued the acquisition instruction, and the motion controller controlled the PCB to move on the track and stop at the specified position.Then the light source was turned on, and the camera captured the image of the IC, which was then stored in the computer.A total of 1000 images .
N represents the total number of test samples, and T represents the time expended for the detection process on these test samples.

Image Acquisition
The experimental data in this paper was collected by the constructed image acquisition hardware platform.The computer issued the acquisition instruction, and the motion controller controlled the PCB to move on the track and stop at the specified position.Then the light source was turned on, and the camera captured the image of the IC, which was then stored in the computer.A total of 1000 images were collected.

Data Enhancement
When the number of training samples is limited, the use of deep learning algorithms can often lead to overfitting, making it challenging to train robust models.Data augmentation is a commonly employed technique that mitigates overfitting and facilitates

Dataset Production
In order to make the collected image data more standard during model training and testing, the image data after data augmentation were made into a Pascal VOC format dataset.There are four types of IC pin welding defects obtained from the captured images, namely short circuit, missing pin, pin cocked, and little tin.LabelImg was selected to label the defects, and for each labeled image, a corresponding XML-format annotation file was generated.This file contains information such as the name and size of the image, the name of the defect, and the position information of the defect annotation box.The ratio of training set, validation set, and test set is 6:2:2.

Experimental Environment
The computational platform utilized for this study exhibits the following specifications: The CPU is Intel(R) Core(TM) i7-7700@3.60GHz;the GPU is NVIDIA GeForce GTX 1070; the system is equipped with 16 GB of RAM; the operating system employed is Windows 10.In terms of software components, the deep learning framework employed is PyTorch 1.8.0 (with torchvision 1.9.0),CUDA version 10.2, CUDNN version 7.6, and the programming language utilized is Python 3.7.

Configure Training Parameters
The dataset consists of 10,000 images, divided into 6,000 images for the training set, 2,000 images for the validation set, and 2,000 images for the test set.The combined size of the training and validation sets is 8,000 images.With a batch size of 20, this results in 400 batches and the input image size is 640×640.The initial learning rate is set to 0.00125, and the momentum parameter is set to 0.9.The entire training process is divided into 100 epochs, resulting in a total of 40,000 iterations.YOLOv5x predicts defects using three feature maps of different scales, and each feature map contains three prediction values.Therefore, there are nine anchor parameters.The size and aspect ratios of the targets in different datasets vary.To more accurately identify the defects in the dataset created in this paper, an improved algorithm uses the k-means++ clustering algorithm to cluster all defect box sizes, resulting in nine cluster centers: (19,60), (18,76)

Experimental Results and Analysis
To verify the performance of the improved network, under the same experimental conditions, the same IC pin welding defect dataset was applied to YOLOv3, YOLOv5x, and the improved network for 100 epochs, then the comparison of the loss value curves is shown in Figure 6.

Experimental Environment
The computational platform utilized for this study exhibits

Configure Training Parameters
The dataset consists of 10,000 images, divided into 6,000   In conclusion, the loss curve of the improved algorithm has the smallest convergence value and tends to be stable, indicating that its training results are better than the other two algorithms.
During training, the validation set was used to verify the model performance every round of training.The comparison of the mean average precision (mAP) curve is shown in Figure 7.

Figure 7
The comparison of the mAP curves of 3 models

Figure 7
The comparison of the mAP curves of 3 models   A detailed comparison of the detection performance of the three models is provided in Table 1.It is notable that the YOLOv3 model exhibits a significant decrease in AP of 19.4% for short circuit and little tin defect, indicating a substantial drop in model performance as defect complexity increases.In contrast, the YOLOv5x model demonstrates a 12.3% decrease in AP for short circuit and little tin defect, suggesting an enhanced capability to recognize complex defects.The improved algorithm exhibits a maximum AP difference of 3.4% across the four defect categories, indicating a more balanced average detection accuracy for each defect type and a significant overall improvement in model performance.Under a threshold of 0.5, the mAP of the improved model reaches 95.0%, representing an increase of 13.3% and 8.9% when compared to YOLOv3 and YOLOv5x, respectively.Regarding detection speed, the improved model outperforms the other two models, offering faster detection capabilities.To provide a more intuitive visualization of the performance of the three models in IC pin welding defect detection, each of the three models was employed to detect defects in two IC pin welding images.The results are illustrated in Figures 8-10.
The detection results are summarized and presented in Tables 2-3.It is evident from the results that the YOLOv3 algorithm missed one missing pin in the left image and incorrectly identified one little tin.While in the right image, it missed one pin cocked and false-   both images.These observations collectively demonstrate that the improved algorithm exhibits superior recognition performance for IC pin welding defects when compared to the other two algorithms.

Conclusions
This paper presents an IC pin welding defect detection method based on an improved YOLOv5x algorithm.The mAP of the improved algorithm reaches 95.0%, an improvement of 13.3% and 8.9% compared to YOLOv3 and YOLOv5x, respectively.The detection time for a single image using the improved algorithm is 0.142 s, faster than the detection speed of YOLOv3 and YOLOv5x.This work provides new research ideas and methods for IC pin welding defect detection, and has important theoretical and reference value for detecting small and dense targets.

Figure 1 Detection flow chart 3 . 2
Figure 1 Detection flow chart YOLOv5x includes two types of CSP structures: CSP1_x and CSP2_x.The CSP1_x, Focus, and SPP structures are used to improve the backbone network, while the CSP2_x, FPN, and PAN are combined to form the neck network, which strengthens the fusion of features at different scales and enhances the network's ability to extract features of IC pin welding defects.

Figure 3 D
Figure 3 D-SPP structure diagram fusion of features at different scales and enhances the network's ability to extract features of IC pin welding defects.ng defect detection based on YOLOv5x

Figure 3 D
Figure 3 D-SPP structure diagram

Figure 4
Figure 4 Structure diagram of Masked Self-Attention Mechanism

Figure 4 Structure
Figure 4Structure diagram of Masked Self-Attention Mechanism

module [ 25 ]
to enhance the network's ability to capture global feature relationships.The module is embedded after the output of the effective feature layer and before the input of the prediction layer in the neck network.The Masked Self-Attention Mechanism operates on feature maps of three sizes: large, medium, and small, to detect IC pin welding defects at multiple scales, thereby improving detection accuracy of the algorithm.The structure of Masked Self-Attention Mechanism module is shown in

Figure 4
Figure 4Structure diagram of Masked Self-Attention Mechanism

6 of
Masked Self-Attention Mechanism 3) Loss Function The loss function of the improved YOLOv5x algorithm consists of confidence loss, classification loss and boundary box regression loss.The confidence loss and classification loss are calculated using binary crossentropy loss function, while the boundary box regression loss is calculated using Focal-EIoU.In Focal-EIoU Loss, the width and height losses directly minimize the difference between the widths and heights of target box and anchor box, which speeds up convergence and solves the vague definition problem of CIoU aspect ratio.Furthermore, Focal Loss is added to address the sample imbalance problem in BBox regression.The formulas for calculating Focal-EIoU Loss are shown in Equations (2)-(3).The complete loss function is shown in Equation (4).
The loss function of the improved YOLOv5x algorithm consists of confidence loss, classification loss and boundary box regression loss.The confidence loss and classification loss are calculated using binary crossentropy loss function, while the boundary box regression loss is calculated using Focal-EIoU.In Focal-EIoU Loss, the width and height losses directly minimize the difference between the widths and heights of target box and anchor box, which speeds up convergence and solves the vague definition problem of CIoU aspect ratio.Furthermore, Focal Loss is added to address the sample imbalance problem in BBox regression.The formulas for calculating Focal-EIoU Loss are shown in Equations (2)-(3).The complete loss function is shown in Equation (4).

( 4 )
, L ij obj and L ij noobj represent the probabilities anchor box in the i th grid containing and not defects, respectively.The value is 1 when the s defects, and 0 otherwise.C i represents the level of the j th predicted box in the i th grid, resents the confidence level of the truth box.s the probability value of the predicted box for d p i represents the probability value of the truth lass.ation Indicators of detecting defects in IC pin welding, the e of the algorithm is mainly evaluated based on n accuracy and speed.The detection accuracy ludes Average Precision (AP) and Mean ecision (mAP).Detection speed is generally Frames Per Second (FPS). .(6) M represents the number of defect categories, and in this study, we have focused on four distinct defect categories; therefore, M=4.Here, APi denotes the Average Precision for each individual defect class.

uation ( 4 )
, L ij obj and L ij noobj represent the probabilities j th anchor box in the i th grid containing and not ining defects, respectively.The value is 1 when the ontains defects, and 0 otherwise.C i represents the ence level of the j th predicted box in the i th grid, C i represents the confidence level of the truth box.resents the probability value of the predicted box for ss, and p i represents the probability value of the truth r its class.valuation Indicators task of detecting defects in IC pin welding, the mance of the algorithm is mainly evaluated based on .(6) M represents the number of defect categories, and in this study, we have focused on four distinct defect categories; therefore, M=4.Here, AP i denotes the Average Precision for each individual defect class.

6 )
alue is 1 when the .C i represents the ox in the i th grid, l of the truth box.e predicted box for ty value of the truth .(M represents the number of defect categories, and in this study, we have focused on four distinct defect categories; therefore, M=4.Here, AP i denotes the Average Precision for each individual defect class.

7 3. 3
Evaluation IndicatorsIn the task of detecting defects in IC pin welding, the performance of the algorithm is mainly evaluated based on its detection accuracy and speed.The detection accuracy mainly includes Average Precision (AP) and Mean Average Precision (mAP).Detection speed is generally measured in Frames Per Second (FPS).1)AP is a metric used to assess the detection accuracy of individual defect categories within the IC pin welding defect dataset.AP is determined by the area under the Precision-Recall curve, with both precision and recall calculated from the confusion matrix.A higher AP value indicates a better detection performance for a particular category.The calculation method for AP is as follows:.(5)P(r) represents the function of the Precision-Recall (PR) curve.2) mAP serves as a metric for assessing the detection accuracy across all defect categories within the IC pin welding defect dataset.mAP is calculated as the average of the AP values for each individual defect category.The calculation method for mAP is as follows:

( 5 )
P(r) represents the function of the Precision-Recall (PR) curve.
L ij obj and L ij noobj represent the probabilities he j th anchor box in the i th grid containing and not taining defects, respectively.The value is 1 when the contains defects, and 0 otherwise.C i represents the fidence level of the j th predicted box in the i th grid, le C i represents the confidence level of the truth box.presents the probability value of the predicted box for lass, and p i represents the probability value of the truth for its class.Evaluation Indicators he task of detecting defects in IC pin welding, the ormance of the algorithm is mainly evaluated based on etection accuracy and speed.The detection accuracy nly includes Average Precision (AP) and Mean rage Precision (mAP).Detection speed is generally sured in Frames Per Second (FPS).

Figure 5 Figure 5 ,
Figure 5 Sample examples of data augmentation for IC pin welding defect images

Figure 5 Figure 5 ,
Figure 5Sample examples of data augmentation for IC pin welding defect images

Figure 5 Figure 5 ,
Figure 5Sample examples of data augmentation for IC pin welding defect images

Figure 5
Figure 5Sample examples of data augmentation for IC pin welding defect images Scaling Transformation 2 (h) Contrast Transformation (i) Brightness transformationthe training of models with strong generalization capabilities, thereby enhancing defect recognition.Consequently, in this paper, seven data augmentation methods were used to expand the IC data samples, in order to enhance the richness of the data.The data augmentation methods are as follows: translation, horizontal flip, vertical flip, rotation, scaling transformation, contrast transformation, and brightness transformation.After data augmentation, a total of 10,000 images were obtained, and all the images were resized to 640×640.Data augmentation examples are illustrated in Figure5, as shown below.

Figure 6
Figure 6 Variation curve of training loss value of 3 models the following specifications: The CPU is Intel(R) Core(TM) i7-7700@3.60GHz;the GPU is NVIDIA GeForce GTX 1070; the system is equipped with 16 GB of RAM; the operating system employed is Windows 10.In terms of software components, the deep learning framework employed is PyTorch 1.8.0 (with torchvision 1.9.0),CUDA version 10.2, CUDNN version 7.6, and the programming language utilized is Python 3.7.
images for the training set, 2,000 images for the validation set, and 2,000 images for the test set.The combined size of the training and validation sets is 8,000 images.With a batch size of 20, this results in 400 batches and the input image size is 640×640.The initial learning rate is set to 0.00125, and the momentum parameter is set to 0.9.The entire training process is divided into 100 epochs, resulting in a total of 40,000 iterations.YOLOv5x predicts defects using three feature maps of different scales, and each feature map contains three prediction values.Therefore, there are nine anchor parameters.The size and aspect ratios of the targets in different datasets vary.To more accurately identify the defects in the dataset created in this paper, an improved algorithm uses the k-means++ clustering algorithm to cluster all defect box sizes, resulting in nine cluster centers: (19,60), (18,76), (72,21), (59,30), (56,38), (38,58), (49,84), improved network for 100 epochs, then the comparison of the loss value curves is shown in Figure 6.

Figure 6
Figure 6 Variation curve of training loss value of 3 models

Figure 6
Figure 6 shows that with the increase of training epochs, the loss function curves of the three networks generally show a decreasing trend.The loss value curve of the YOLOv3 algorithm has a large oscillation amplitude and the slowest decrease rate.The loss value curve of the YOLOv5x algorithm has oscillation, but the decrease rate is faster than YOLOv3.The improved algorithm has the fastest decrease rate, and converges after about 30 rounds of training.After 100 epochs of iterative training, the loss value of the YOLOv3 algorithm is around 0.2, the loss value of the YOLOv5x algorithm converges to 0.14, and the loss value of the improved algorithm converges to 0.1.Compared with the other two algorithms, the improved algorithm has the smallest loss convergence

Figure 7
Figure 7 shows that with the increase of training epochs, the mAP curves of the three models generally show an upward trend.The mAP curve of YOLOv3 algorithm fluctuates and has the slowest increase rate.After 100 rounds of training, it is about 80%.The mAP curve of the YOLOv5x algorithm has a faster increase rate than

Figure 7
Figure 7 shows that with the increase of training epochs, the mAP curves of the three models generally show an upward trend.The mAP curve of YOLOv3 algorithm fluctuates and has the slowest increase rate.After 100 rounds of training, it is about 80%.The mAP curve of the YOLOv5x algorithm has a faster increase rate than YOLOv3, and after 80 rounds of training, the model's mAP stabilizes at around 86%.The mAP curve of the improved algorithm has the fastest convergence speed.After 50 rounds of training, the mAP stabilizes at around 90%.

Figure 10 11 Figure 8 Figure 9 Figure 10 Visualization of detection results of the improved algorithm 11 Figure 8 Figure 9 Figure 10
Figure 10Visualization of detection results of the improved algorithm

Table 1
Comparison of detection performance of three modelsTo provide a more intuitive visualization of the performance of the three models in IC pin welding defect detection, each of the three models was employed to detect defects in two IC pin welding images.The results are illustrated in Figures 8-10.

Table 1
Comparison of detection performance of three models

Table 2
Detection results for the left image

Table 3
Detection results for the right image