Volume 7, Issue 2 e13117
RESEARCH ARTICLE
Open Access

Optimized Design of YOLOv5s Algorithm for Printed Circuit Board Surface Defect Detection

Kaisi Lin

Kaisi Lin

Department of Electrical Engineering, Tongling Polytechnic, Tongling, Anhui, China

Contribution: Validation, Funding acquisition

Search for more papers by this author
Lu Zhang

Corresponding Author

Lu Zhang

Department of Electrical Engineering, Tongling Polytechnic, Tongling, Anhui, China

Correspondence:

Lu Zhang ([email protected])

Contribution: Software, Project administration

Search for more papers by this author
First published: 13 February 2025

Funding: This study was supported by Key Project of Natural Science Foundation of Anhui Colleges and Universities, 2022AH052753.

ABSTRACT

To address the challenge of detecting surface defects on printed circuit board (PCB), this paper proposes an improved method based on YOLOv5s. To enhance the detection of small target defects, the Coordinate Attention mechanism is integrated into the three Convolutional layers module of YOLOv5s, and the Normalized Gaussian Weighted Distance loss is introduced to replace the Complete Intersection over Union loss. To achieve a lightweight model with parameters reduced and to enhance detection speed for real-time applications and terminal deployment, the convolutional layers in the Neck module of YOLOv5s are replaced with Grouped Shuffled Convolution layers. Evaluated on two benchmark data sets, the PCB_DATASET and DeepPCB data sets, the improved model achieves 97.0% and 99.1% in [email protected] and achieves 163 and 167 in Frames Per Second, respectively. In addition, the model parameters are reduced to 6.6 million, meeting the demands of small target detection in real-time applications.

1 Introduction

An indispensable part of electronic products is the printed circuit board (PCB). Due to its complex manufacturing processes, it is susceptible to the influence of processing equipment, human operation, and the environment, which can lead to defects such as spur, mouse bite, short circuit, open circuit, and missing hole in the produced PCB. These defects influence the appearance and performance of the PCB. In severe cases, the PCB will be scrapped, which will reduce the pass rate and increase the production cost [1, 2]. Manual visual inspection is currently the primary method of detecting PCB surface defects, which has the disadvantages of high long-term costs and easy subjective error. Another method is the electrical performance test, whose disadvantage is that the test probe has physical contact with the test pad, which may leave a small pit on the solder [3]. There is also automatic optical inspection, which is non-destructive and non-contact automatic online inspection. In addition, there are traditional machine vision inspection and deep–learning based inspection [4].

In the existing research, PCB surface defect detection mainly uses deep-learning methods [5]. There are two approaches to target recognition based on deep learning: two-stage and one-stage methods. Fast R-CNN [6, 7] and Faster R-CNN [8] are typical two-stage target detection methods. Two-stage target detection methods have high accuracy but they normally have low speed and cannot achieve real-time detection. For example, based on Faster R-CNN, Fang et al. proposed a defect detection algorithm for solder joints in PCB assemblies. This algorithm replaces the feature extraction network in Faster R-CNN with the first eight stages of EfficientNet-B7 and optimizes the loss function for bounding box regression, which significantly improves the detection accuracy [9]. Compared with two-stage object detection methods, one-stage methods normally achieve lower accuracies. However, one-stage methods are normally faster in the detection efficiency, such as the YOLO series single-step detection algorithm. Tang et al. [10] used the K-means++ algorithm and Swin transformer to improve the detection ability of YOLOv5 for PCB minor defects. By introducing depth-separable convolutions, the model parameters are reduced and the detection speed is increased. Wu et al. addressed the problem that YOLOv4 preset anchor frames are not adapted to PCB small target defect detection. They proposed an improved YOLOv4 algorithm using improved bipartite K-means clustering combined with IoU loss function to determine the anchor frame [11]. Chen et al. [12] proposed a Transformer-YOLO detection model. The model employs the Swin Transformer to extract network features, incorporating both convolution and attention mechanism modules within the feature detection network. In this way, the detection accuracy of PCB defects can be improved. Spadaro et al. [13] develop a modified architecture of YOLOv5, which is proposed to detect small components on PCB. The proposed method can achieve real-time processing of large images. Benjumea et al. [14] investigate how YOLOv5 can be modified to detect smaller objects. Specifically, they replace certain structural elements and parameters of YOLOv5 to propose a series of models, termed as YOLO-Z. Results show that the proposed models achieve an increase of up to 6.9% in mAP. In addition, variants of YOLOv5 are released on GitHub [15], which are added with extra detection heads, such as YOLOv5-p2, to improve the detection performance on small objects.

This paper applies YOLOv5s as the base network to solve the exiting problems that PCB surface defect detection is not accurate, and to meet the need for real-time detection and deployment [16]. Specifically, to improve the detection accuracy of small targets, the CA (Coordinate Attention) module is introduced in the C3 (three Convolutional layers) module of the backbone network in YOLOv5s, and the NWD (Normalized Gaussian Weighted Distance) loss is used instead of the CIoU (Complete Intersection over Union) loss. Moreover, the Conv convolution in the Neck network of YOLOv5s is replaced with GSConv (Grouped Shuffled Convolution) to reduce the model parameters. This can make the model lightweight and easy to deploy to terminals and can improve the detection speed. Therefore, the enhanced model based on YOLOv5s not only improves the detection accuracy but also reduces the model parameters, which has higher application value in the actual PCB defect detection.

2 The Improved YOLOv5s Model

YOLOv5 has four versions. In this paper, − considering the terminal deployment requirements of the actual PCB defect detection, we choose the version with the smallest network size, YOLOv5s, as the base network for improvement.

The YOLOv5s network model is made up of three parts: Backbone, Neck, and Head. The Backbone network is primarily for feature extraction from PCB images. To extract richer target features, the Neck network integrates low-level and high-level features, which are then utilized by the Head for target classification and bounding box regression [17]. In this work, three improvements are made to enhance YOLOv5s. First, the CA attention is introduced to the C3 module in the Backbone network, which forms the C3CA module. Second, the Conv convolution is replaced by the GSConv convolution in the Neck network. Third, the NWD loss is used instead of the CIoU loss. Therefore, the improved model is termed as CGN-YOLOv5s (CA GSConv NWD YOLOv5s). Figure 1 shows the structure of CGN-YOLOv5s.

Details are in the caption following the image
The structure of CGN-YOLOv5s.

2.1 The C3CA Module

A key module in the YOLOv5s is the C3 module, which enhances the ability to extract features by increasing the network depth and receptive field [18]. Hou et al. proposed a new attention mechanism called CA [19]. It embeds location information in the channel attention and acts on lightweight networks. CA attention is different from channel attention. CA attention decomposes the channel attention into two 1D (dimensional) feature encodings. This results in aggregated features in both spatial directions and makes it possible to capture remote dependencies. CA attention also provides precise location information along each of the two spatial directions. Then, to enhance the feature targets into direction and position-sensitive feature maps, the generated feature maps are encoded separately for direction and position. Figure 2 shows the CA attention structure.

Details are in the caption following the image
The structure of the CA attention module.

The CA attention module is flexible and lightweight and can be easily inserted into classical modules to enhance features by reinforcing information representation. Therefore, the CA attention is incorporated into the Bottleneck structure of YOLOv5s to constitute the CA Bottleneck structure, as shown in Figure 3. In addition, C3CA in turn consists of CA Bottleneck as shown in Figure 4. Due to its residual network and coordinate attention, it is effective in obtaining spatial location information of target features. And the information obtained is incorporated into the generated feature map to enhance the feature extraction capability of the backbone network [17]. PCB tiny defects have the characteristics of small image share and low contrast with the background. PCB tiny defects are characterized by small image share and low contrast with background [20]. Therefore, in the feature extraction of the deep network, there is a limited rejection of redundant background information. The result is that the network is not sensitive to the information of tiny defects. Feature extraction of PCB tiny defects is significantly enhanced after incorporating CA attention.

Details are in the caption following the image
The structure of the CA Bottleneck.
Details are in the caption following the image
The structure of C3CA.

2.2 Lightweight Network Structure: GSConv

GSconv [21] was proposed by Li et al. in 2022, and this convolutional model achieves a perfect balance between speed and accuracy. Li et al. [21] suggested that to improve the speed of detection through Deep Separable Convolution (DSC), lightweight networks such as Xception [22] and MobileNets [23] are used. However, DSC has the drawback that it is much lower than Standard Convolution (SC) in terms of feature extraction and fusion capability, and this defect is amplified in backbone networks. The GSconv proposed in [21] is a hybrid convolution, which combines SC, DSC, and shuffle. Using shuffle, each piece of information generated by the DSC is interleaved with the information generated by the dense convolution of the SC channel. Shuffle is a homogeneous mixed measurement. It achieves uniform distribution of SC information by exchanging local features across multiple channels and incorporating this information into the output of the DSC without complicated processing. This trims the feature maps extracted by GSConv, which is significantly closer to those extracted by SC than those extracted by DSC. The result is possible that the extraction accuracy of GSConv is close to that of SC, while the detection speed is greatly improved compared to SC. Figure 5 shows the structure of GSConv.

Details are in the caption following the image
The structure of GSConv.

2.3 NWD Loss Function

Xu et al. [24] pointed out that the ratio of intersection to concatenation of small targets is susceptible. A slight deviation in the target position can significantly decreases the IoU, which affects the detection performance. They proposed an evaluation metric called NWD. This metric is used to measure the bounding box similarity in small target detection. NWD can be conveniently incorporated into the loss function as an alternative to IoU with significantly better detection accuracy for small targets.

Since real small objects are often not perfect rectangles, their bounding boxes will often contain some non-target background pixels [25]. Within these bounding boxes, the foreground pixels are concentrated in the central area. The background pixels are spread out nearer the boundaries. The bounding box describes the different pixel weights in the bounding box by modeling them as 2D Gaussian distributions.

Assume a horizontal bounding box is R = ( cx , cy , w , h ) $$ R=\left( cx, cy,w,h\right) $$ , whose coordinates of the center is ( cx , cy $$ cx, cy $$ ) and its width and height are w $$ w $$ and h $$ h $$ , respectively. Then the equation of the internal tangent circle of the bounding box can be expressed as:
x μ x 2 σ x 2 + y μ y 2 σ y 2 = 1 $$ \frac{{\left(x-{\mu}_x\right)}^2}{\sigma_x^2}+\frac{{\left(y-{\mu}_y\right)}^2}{\sigma_y^2}=1 $$ (1)

Where μ x , μ y $$ \left({\mu}_x,{\mu}_y\right) $$ are the center coordinates, σ x , σ y $$ {\sigma}_x,{\sigma}_y $$ are the semi-axis lengths along the x-axis and y-axis, respectively.

Correspondingly, μ x = cx , μ y = cy , σ x = w 2 , σ y = h 2 $$ {\mu}_x= cx,{\mu}_y= cy,{\sigma}_x=\frac{w}{2},{\sigma}_y=\frac{h}{2} $$ , the probability density function of the 2D Gaussian distribution is shown in Equation (2):
f x | μ , = exp 1 2 ( x μ ) T 1 ( x μ ) 2 π 1 / 2 $$ f\left(\mathbf{x}\mid \mu, \sum \right)=\frac{\exp \left(-\frac{1}{2}{\left(\mathbf{x}-\mu \right)}^{\mathrm{T}}{\sum}^{-1}\left(\mathbf{x}-\mu \right)\right)}{2\pi {\left|\sum \right|}^{1/2}} $$ (2)
where x $$ \mathbf{x} $$ , μ $$ \mu $$ and $$ \sum $$ denote the coordinates ( x , y ) $$ \left(x,y\right) $$ , the vector, and the covariance matrix, respectively. The standard Gaussian distribution is obtained, when the equation ( x μ ) T 1 ( X μ ) = 1 $$ {\left(\mathbf{x}-\mu \right)}^T{\sum}^{-1}\left(\mathrm{X}-\mu \right)=1 $$ holds. The ellipse in Equation (1) is the density contour of the 2D Gaussian distribution. Therefore, R = ( cx , cy , w , h ) $$ R=\left( cx, cy,w,h\right) $$ can be modeled as a 2D Gaussian distribution M μ , $$ M\left(\mu, \sum \right) $$ , where μ = c x c y $$ \mu =\left[\begin{array}{l}{c}_x\\ {}{c}_y\end{array}\right] $$ , = w 2 4 0 0 h 2 4 $$ \sum =\left(\begin{array}{cc}\frac{w^2}{4}& 0\\ {}0& \frac{h^2}{4}\end{array}\right) $$ .

Furthermore, the degree of similarity between two bounding boxes can be quantified by modeling them as two Gaussian distributions and calculating the difference between the two distributions. This also establishes the distribution relationship between x and y.

Assume μ 1 = M m 1 , 1 $$ {\mu}_1=M\left({m}_1,{\sum}_1\right) $$ and μ 2 = M m 2 , 2 $$ {\mu}_2=M\left({m}_2,{\sum}_2\right) $$ are two 2D Gaussian distributions. The second-order Wasserstein distance between them is:
W 2 2 μ 1 , μ 2 = m 1 - m 2 2 2 + Tr 1 + 2 2 2 1 / 2 1 2 1 / 2 1 / 2 $$ {W}_2^2\left({\mu}_1,{\mu}_2\right)={\left\Vert {\mathrm{m}}_1\hbox{-} {\mathrm{m}}_2\right\Vert}_2^2+\mathbf{Tr}\left({\sum}_1+{\sum}_2-2{\left({\sum}_2^{1/2}{\sum}_1{\sum}_2^{1/2}\right)}^{1/2}\right) $$ (3)
Assume there are two bounding boxes, A = cx a , cy a , w a , h a $$ A=\left({cx}_a,{cy}_a,{w}_a,{h}_a\right) $$ and B = cx b , cy b , w b , h b $$ B=\left({cx}_b,{cy}_b,{w}_b,{h}_b\right) $$ , which define the Gaussian distributions of M a $$ {M}_a $$ and M b $$ {M}_b $$ . The above equation can be reduced to:
W 2 2 M a , M b = cx a , cy a , w a 2 , h a 2 T , cx b , cy b , w b 2 , h b 2 T 2 2 $$ {W}_2^2\left({M}_a,{M}_b\right)={\left\Vert \left({\left[{cx}_a,{cy}_a,\frac{w_a}{2},\frac{h_a}{2}\right]}^{\mathrm{T}},{\left[{cx}_b,{cy}_b,\frac{w_b}{2},\frac{h_b}{2}\right]}^{\mathrm{T}}\right)\right\Vert}_2^2 $$ (4)
W 2 2 $$ {W}_2^2 $$ is the distance metric for M a , M b $$ \left({M}_a,{M}_b\right) $$ , which cannot be directly used as a resemblance measure. Accordingly, by normalizing the exponential form, a new metric can be obtained. This is the NWD, shown in the Equation (5).
NWD M a , M b = exp W 2 2 N a , N b C $$ \mathrm{NWD}\left({M}_a,{M}_b\right)=\exp \left(-\frac{\sqrt{W_2^2\left({N}_a,{N}_b\right)}}{C}\right) $$ (5)
Assume C $$ C $$ is a constant with respect to the data set. If the predicted bounding box and the true bounding box are denoted by P and G, respectively, and by IoU-Loss in the case where P and G do not overlap. The box P completely contains the box G or the reverse cannot be the gradient for the optimization mesh. For tiny target detection, IoU-Loss is not suitable. For the above two cases, CIoU [26] and DIoU [27] can handle it, but they are both based on IoU and sensitive to positional deviation of tiny targets. Thus, NWD is designed as a loss function in this work, shown in Equation (6):
L NWD = 1 NWD N p , N q $$ {L}_{\mathrm{NWD}}=1-\mathrm{NWD}\left({N}_p,{N}_q\right) $$ (6)

3 Experimental Analysis

3.1 Data Sets

Various test experiments are performed on the PCB_DATASET and DeepPCB data sets to test the performance of the model comprehensively. The PCB_DATASET is an open-source PCB data set from Peking University. It is collected by the industrial camera to capture different images of the PCB bare board, and then each image is retouched for different kinds of defects. The data set comprises six types of PCB surface defects, including missing holes, mouse bites, open circuits, shorts, spurs, and residual copper [28]. The data set contains a total of 693 corrupted images. The average size is 2777 by 2138 pixels. The sample size of the original data set is significantly small. This paper employs random cropping, rotation, and light change of defective PCB images to expand the data set to 5000 sheets. In addition, the image size is adjusted to pixel 640 × 640, and then LabelImg is used to label the surface defects on each image, and the images are stored in YAML format. 5000 samples are arbitrarily divided into a training set of 3500 sheets, a validation set of 1000 sheets, and a test set of 500 sheets.

The DeepPCB data set is an open-source PCB data set by Shanghai Jiao Tong University. The data set has 1500 images. It comprises six distinct categories of PCB defects, including copper, mouse-bite, open, pin-hole, short, and spur [29]. Compared with the PCB_DATASET data set, although the two data sets have similar types of defects, there are differences in the image background and image color. In addition, multiple defect targets on each image in the PCB_DATASET data set are of the same type, while multiple defect targets on each image in the DeepPCB data set are of different types, as shown in Figures 6 and 7. The 1500 samples are randomly divided into 1200 for training, 150 for validation, and 150 for testing.

Details are in the caption following the image
PCB_DATASET data set sample.
Details are in the caption following the image
DeepPCB data set sample.

3.2 Evaluation Metrics

The accuracy and speed must be balanced in this improved model. Average precision (AP) and mean average precision (mAP) are used to evaluate accuracy. AP is used as the evaluation index for each defect category.

The mAP is the average of the APs of several categories, which is used as a metric to evaluate the performance of the entire network. The detection speed is measured by the refresh rate FPS. Precision, recall, and number of model parameters are auxiliary metrics [30].

Precision is calculated using the formula:
Precision = TP TP + FP $$ \mathrm{Precision}=\frac{\mathrm{TP}}{\mathrm{TP}+\mathrm{FP}} $$
Recall is calculated using the formula:
Recall = TP TP + FP $$ \mathrm{Recall}=\frac{\mathrm{TP}}{\mathrm{TP}+\mathrm{FP}} $$

Where TP represents the number of positive samples that are correctly identified to be positive, while FP denotes the number of negative samples that are incorrectly predicted to be positive. Conversely, FN signifies the number of positive samples that are erroneously classified as negative ones.

The area under the precision-recall curve (PR curve) is defined as AUC. The number of model parameters is contingent upon the size of the model. A model with higher accuracy, less parameters, and smaller memory occupation is better.

3.3 Experimental Environment and Parameter Settings

The experimental environment is shown in Table 1.

TABLE 1. Experimental environment.
CPU Intel(R) i9-12900H
Operating system Win11
GPU RTX 4060Ti
PyTorch 1.12.1
Parallel computing architecture CUDA11.3+cuDNN8.3.0

Network input size is 640 × 640. The initial learning rate is 0.01. The weight decay coefficient is 0.0005. The number of training epoch is 100, and the number of images per training batch size is 16.

3.4 The Results of CGN-YOLOv5s

The enhanced model is evaluated in comparison with YOLOv5 on two distinct datasets. The results of the experimental investigation conducted on the PCB_DATASET data set are presented in Table 2. As illustrated in Table 2, CGN-YOLOv5s exhibits a 1.1% superior overall detection accuracy compared to that of YOLOv5s. With the exception of missing hole defects, the detection accuracy of other defects is superior to that of YOLOv5s. Table 3 presents a comparison of the experimental results on the DeepPCB data set. As evidenced in Table 3, the total detection accuracy of the enhanced algorithm has been augmented by 2.2% in comparison to YOLOv5s, with an overall improvement in detection accuracy for all defects. In both instances, the detection accuracy is enhanced, which indicates that CGN-YOLOv5s possesses a more potent capacity to detect small defects of PCB. Furthermore, the incorporation of GSConv into CGN-YOLOv5s results in a notable reduction in the number of model parameters, which is more conducive to deployment on end devices. The FPS on the two data sets reaches 163 and 167, respectively, which represents a negligible decrease in comparison to the FPS of YOLOv5s. The training process of the two algorithms on the two data sets is also analyzed, which is shown in Figures 8 and 9.

TABLE 2. Experimental comparison of the PCB_DATASET data set.
AP
Algorithm Open Copper Mouse_bite Missing_hole Short Spur [email protected] FPS Params/M
YOLOv5s 0.948 0.969 0.937 0.993 0.972 0.935 0.959 166 7.0
CGN-YOLOv5s 0.975 0.977 0.959 0.944 0.973 0.942 0.970 163 6.6
TABLE 3. Experimental comparison of the DeepPCB data set.
Algorithm AP
Algorithm Copper Mouse_bite Open Pin-hole Short Spur [email protected] FPS Params/M
YOLOv5s 0.979 0.937 0.964 0.962 0.991 0.980 0.969 169 7.0
CGN-YOLOv5s 0.985 0.990 0.989 0.990 0.996 0.993 0.991 167 6.6
Details are in the caption following the image
Comparison of training loss on two data sets.
Details are in the caption following the image
Comparison of [email protected] on two data sets.

The loss in Figure 8 is the total loss. The training loss of CGN-YOLOv5s on both data sets declines at a considerably faster rate than that of YOLOv5s. The values of the loss are smaller. The results demonstrate that the enhanced detection algorithm exhibits superior training outcomes in comparison to YOLOv5s.

As illustrated in Figure 9, the detection accuracy corresponding to the weights obtained from different epoch training demonstrates that CGN-YOLOv5s outperforms YOLOv5s on both data sets. The above shows that CGN-YOLOv5s not only obtains lower training loss but also has higher accuracy in tiny defect detection.

To evaluate the efficacy ofCGN-YOLOv5s, visualization experiments have been conducted on both CGN-YOLOv5s and YOLOv5s. Considering the length of the article, only the test results on the DeepPCB data set are shown here. Figure 10 shows the randomly selected detection results, the detection results of the two algorithms are compared with the labels. The results show that YOLOv5s has two misdetections and one leakage, and CGN-YOLOv5s has two leakages, whose detection accuracy is a little higher.

Details are in the caption following the image
Comparison of detection results on the DeepPCB data set.

3.5 Ablation Experiments

This paper presents three enhancements to the YOLOv5s model. In order to analyze the impact of the various improvements on the model performance, the YOLOv5s model is augmented with the different improvements, and a “√” is used to indicate that the corresponding improvement scheme has been incorporated. All the methods are tested on two datasets with all the same parameters. The results are as shown in Tables 4 and 5.

TABLE 4. Different improvement experiments in the PCB_DATASET data set.
Algorithm CA GSConv NWD [email protected] FPS Params/M
YOLOv5s 0.959 166 7.0
YOLOv5s+CA 0.963 123 7.0
YOLOv5s+CA+ GSConv 0.967 152 6.6
CGN-YOLOv5s (YOLOv5s+CA+ GSConv+NWD) 0.970 1 6.6
TABLE 5. Different improvement experiments in the DeepPCB data set.
Algorithm CA GSConv NWD [email protected] FPS Params(M)
YOLOv5s 0.969 169 7.0
YOLOv5s+CA 0.982 127 7.0
YOLOv5s+CA+ GSConv 0.985 162 6.6
CGN-YOLOv5s (YOLOv5s+CA+ GSConv+NWD) 0.991 167 6.6

As can be seen in Tables 4 and 5, YOLOv5s incorporation of the CAC3 module improves the detection accuracy on both data sets, but the FPS shows a large decrease. After using GSConv in the Neck network, the number of parameters is reduced by 0.4 M. With a slight improvement in accuracy, the FPS has significantly increased compared to YOLOv5s + CA. The introduction of NWD in YOLOv5 results in a large increase in accuracy in both data sets, which suggests that NWD is more suited to the detection of tiny targets compared to IoU. In addition, as can be seen in Figure 11, the training loss decreases faster with smaller values after the introduction of NWD.

Details are in the caption following the image
Effect of different improvements on training loss on two data sets.

As illustrated in Figure 12, the PR curves of the algorithms presented in this paper collectively encompass the other improvement cases, thereby indicating that the detection accuracy for small targets is superior to that of the other improvements.

Details are in the caption following the image
Precision-Recall curves of different improvement schemes on two data sets.

3.6 Comparison With State-Of-The-Art Methods

To further verify the effectiveness and feasibility of the model presented in this paper, a series of experiments are conducted to compare the performance of PCB defect detection with a range of contemporary target detection models, including YOLOv4 [31], YOLOv7 [32], YOLOv7-tiny, Faster-RCNN [33], SSD [34], and YOLOv5m. These experiments are carried out on the DeepPCB data set within the same experimental environment. The experimental data is presented in Table 6. As evidenced by the data presented in the table, the [email protected] of the proposed algorithm reaches 99.1%, which is the highest. In addition, the FPS of CGN-YOLOv5s is also 41, 82, and 54 higher than those of YOLOv4, YOLOv7, and YOLOv5m models, respectively. YOLOv7-tiny has the highest FPS value of 397, but its detection accuracy is relatively low with 92.7%. The FPS of CGN-YOLOv5s reaches 167, which is sufficient to meet the requirements of real-time PCB defect detection without ensuring accuracy.

TABLE 6. Comparison with updated object detection methods.
Algorithm [email protected] FPS Params/M
Faster-RCNN 0.837 27 41.3
SSD 0.789 78 24.28
YOLOv4 0.905 126 63.9
YOLOv7 0.981 85 74.9
YOLOv7-tiny 0.927 397 12.3
YOLOv5m 0.984 113 20.8
YOLOv5s 0.969 169 7.0
CGN-YOLOv5s 0.991 167 6.6

CGN-YOLOv5s can meet the requirements of real-time PCB defect detection without lowering accuracy.

3.7 Real-World Implications and Practical Deployment Challenges

The proposed method, CGN-YOLOv5s, for detecting PCB surface defects have several significant advantages, for example, a lightweight model, enhanced detection accuracy for small target defects, and real-time detection capabilities. These advantages make CGN-YOLOv5s highly suitable for the industrial applications, for example, automated PCB inspection in the manufacturing environments, where accurate and high-speed defect detection is important to ensure product quality.

However, deploying CGN-YOLOv5s in real-world applications may have the following two challenges:
  1. Data Quality and Variability: In the practical settings, the quality of PCB images may vary due to factors like camera angles, lighting conditions, presence of noise or reflections, and so forth. The model must be robust to handle such variations to avoid performance decline in real-world environments.
  2. Scalability: In real-world applications, different PCB materials and layouts may require further model fine-tuning to adapt to varied defect characteristics.

In conclusion, while the proposed method shows strong potential for practical deployment in PCB defect detection, addressing the challenges in terms of robustness and scalability will be important for its successful application in the real world.

4 Conclusion

This paper proposes an enhanced algorithm for the detection of surface defects on PCB, based on the YOLOv5s. Experiments have proven to be good. By introducing the CA attention mechanism, NWD loss function, and GSConv convolution, the model exhibits a significant improvement in detection speed and a reduction in parameters, while maintaining a high level of accuracy. The experimental demonstrates that the [email protected] of the enhanced algorithm on the PCB_DATASET and DeepPCB data sets reaches 0.970 and 0.991, respectively. Additionally, the FPS of the proposed model is 163 and 167, respectively, and model parameter is reduced to 6.6 M. Compared with YOLOv5s, the detection progress is improved by 1.1% and 2.2% on the two data sets, respectively. In comparison with the mainstream models, such as YOLOv4, YOLOv7, and YOLOv5m, the proposed algorithm demonstrates superior performance in terms of both accuracy and speed. In addition, the effectiveness of the algorithm is further verified by visual experiments. Accordingly, the algorithm proposed in this paper not only enhances the capability of detecting PCB defects but also fulfills the criteria for real-time detection and terminal deployment, thereby offering practical applications. The code of our method is available at tonglinglinmumu/enhanced_yolov5(github.com).

Author Contributions

Kaisi Lin: validation, funding acquisition. Lu Zhang: software, project administration.

Ethics Statement

This research adheres to the ethical standards. All data presented in this paper are authentic and have been collected, processed, and analyzed with integrity. Proper citations and acknowledgments have been provided for all sources used. There is no indication of plagiarism, data manipulation, or other ethical violations in the preparation of this work.

Conflicts of Interest

The authors declare no conflicts interest.

Data Availability Statement

The data sets used and/or analyzed during the current study are available from the corresponding author on reasonable request.

    The full text of this article hosted at iucr.org is unavailable due to technical difficulties.