PCB Defect Based on Improved YOLOv7: Comparison
Please note this is a comparison between Version 1 by YUJIE YANG and Version 2 by Camila Xu.

The printed circuit board (PCB) holds immense importance in the electronic industry as a crucial component for the development of electronic products. PCBs are becoming increasingly integrated and smaller due to the excellent craftsmanship, precise wiring, and rapid development of integrated circuits.

  • deep learning
  • printed circuit boards
  • YOLOv7

1. Introduction

The printed circuit board (PCB) holds immense importance in the electronic industry as a crucial component for the development of electronic products. PCBs are becoming increasingly integrated and smaller [1] due to the excellent craftsmanship, precise wiring, and rapid development of integrated circuits. However, with the reduction in size, defects in the PCBs are also getting smaller and more challenging to detect. Therefore, it is imperative to conduct a thorough defect detection process during PCB-related production to improve product quality and reduce company costs.
The conventional methods of detecting defects in PCBs are classified into three categories: manual visual inspection, electrical testing, and optical inspection [2]. Manual visual inspection involves workers inspecting bare PCBs directly using their eyes and other equipment. However, this method has become inadequate due to the increasing demand for higher precision in PCB development, as it has poor detection stability and low efficiency. On the other hand, electrical testing employs contact testing to detect defects in bare PCBs, which requires complex testing circuits, expensive molds, and fixtures for each batch of PCBs. This method is also limited in detecting multi-layer PCBs and poses a risk of secondary damage. In contrast, automated optical inspection (AOI) is a non-contact inspection method that uses machine vision technology and image processing algorithms [3]. Industrial cameras capture images of the PCBs, which are transmitted to a computer that provides feedback on the defect detection results. AOI is more stable and accurate than the previous methods, with a faster detection speed [4], and does not impact the PCB.
The advancement of deep learning has led to the development of contactless automatic detection methods, which have become a popular area of research due to their strong recognition adaptability and generalization ability. Typically, deep learning-based detection networks can be categorized into one-stage and two-stage networks. The one-stage network includes Single Shot Detector (SSD) [5], and You Only Look Once (YOLO) [6]. In contrast, the two-stage network includes regions with convolutional neural networks (R-CNN) [7], Fast R-CNN [8], and Faster R-CNN [9], which is an improved version of R-CNN. The primary difference between these networks is that the one-stage network directly predicts the location and category of defects in the network after feature extraction, while the two-stage network first generates proposals that may include defects, then conducts the detection process. Specifically, the two-stage network generates candidate boxes of different sizes that may contain defect features, then performs target detection to predict defect classes and locations. However, the detection speed is slow due to the generation of many candidate frames. On the other hand, the one-stage network performs both training and detection in a single network without the need for explicit region proposals, resulting in faster detection speed. This paper adopts the one-stage network based on YOLOv7 [10] and improves it to meet real-time performance requirements in the industrial field.
The Swin Transformer v2 [11] is designed to overcome three significant challenges in large visual model training and application, namely, model instability, the resolution gap problem, and a chronic lack of labeled data. To address these challenges, the Swin Transformer v2 proposes three primary methods. First, it combines cosine attention and post-normalization to enhance model stability. Second, it introduces a logarithmic space continuous location deviation method, which enables the model to be trained on low-resolution images, then transferred to its higher-resolution counterparts. Lastly, it introduces SimMIM, a self-supervised pretraining method that reduces the need for large amounts of labeled data. To improve the global feature extraction and stability of the model, SwinV2_CSPB modules can replace some ELAN modules in the YOLOv7 backbone network.

2. PCB Defect Based on Improved YOLOv7

The conventional approach for detecting visual anomalies in artificial systems has drawbacks, such as high cost, low efficiency, and errors in detection. As an alternative, the electrical properties of components can be leveraged for detecting defects in printed circuit boards (PCBs) through a semi-automatic, manual detection method that includes online and functional testing [12][13]. Researchers have explored various techniques to enhance this method, such as compressing images using wavelet transform to reduce memory and computation requirements [13][14], using traditional machine learning algorithms for defect detection [14][15], and designing low-complexity neural network and machine vision schemes to improve defect detection [15][16]. Other approaches include using Fourier image reconstruction to identify small defects [16][17] and ultrasonic laser thermal imaging for real-time defect detection [17][18]. Although these methods can reduce costs compared to manual detection, their limited application is attributed to factors, such as the non-reusability of the test process, the high cost of equipment, and complex writing functions, among others. Machine vision detection methods have emerged as a viable solution to overcome the shortcomings of traditional artificial detection methods and are increasingly being applied in modern industries [18][19]. There are three primary categories of PCB defect detection methods based on machine vision: reference, non-reference, and hybrid methods. The reference method [19][20] typically involves image segmentation techniques to detect defects. For example, Li et al. compared PCB images with and without defects to identify defects [20][21]. Non-reference methods [21][22] mainly rely on machine learning algorithms for defect detection. For instance, Malge et al. employed an image segmentation algorithm to detect PCB defects [22][23]. The hybrid method [23][24] combines reference and non-reference methods to achieve more accurate defect detection. For example, Ray et al. developed a hybrid detection method by comparing PCB images and using image segmentation techniques [24][25]. Image segmentation techniques include threshold segmentation, edge segmentation, and region segmentation methods. For example, Ardhy et al. [25][26] used the adaptive Gaussian threshold segmentation to achieve rapid detection with minimal parameters, but the detection efficacy varied significantly in different areas with light strips. Baygin et al. [26][27] used Hough transform for edge segmentation and combined it with the Canny operator to enhance detection efficiency. Ma et al. [27][28] improved the region growth algorithm for region segmentation to achieve better detection outcomes. However, these methods require manual tuning of model parameters, which may lead to suboptimal accuracy and efficiency. Recent studies have demonstrated that the accuracy of automated optical inspection (AOI) is higher compared to other methods. However, due to the system’s high sensitivity, it has very strict parameter-setting rules and may miss some cases, necessitating manual screening after machine screening is complete [28][29]. Meanwhile, deep learning technology has been rapidly advancing. Target defect detection methods based on deep learning have shown to be highly accurate, fast, and do not require manual screening. Thus, they are more cost-effective and efficient. Moreover, the parameter-setting rules are not as strict as those in the AOI system. As a result, deep learning-based methods are being increasingly studied and applied in various industries. Due to advancements in computing technology, complex operations have become more affordable, resulting in the rapid development of neural networks, including a large number of deep neural networks. In the field of PCB defect detection, many scholars have applied deep learning techniques. DenseNet [29][30] achieved better performance with fewer parameters and computing costs by densely connecting all front and back layers to enable feature reuse. Huang et al. [30][31] improved detection accuracy and efficiency by designing a convolutional neural network that connects each layer in a feedforward manner. Compared to conventional machine vision methods, deep learning algorithms have stronger nonlinear abilities, higher robustness, and are applicable to more complex scenarios. He [31][32] proposed an improvement measure that helped achieve a 96.91% accuracy rate. Geng et al. [32][33] improved the detection accuracy to 96.65% by using focal loss and ResNet50 as the backbone network. Ding et al. [33][34] designed TDD-net, a detection network specifically aimed at tiny PCB defects, which adopted a multi-scale fusion strategy and applied online hard example mining to enhance the certainty of ROI proposals, resulting in a detection accuracy of 98.90%. Sun et al. [34][35] proposed the Inception-ResNet-v2 model, which improved the PCB detection accuracy by adding an SE module to part of the structure. Hu et al. [35][36] presented UF-Net, which retained more defect target information by using the Skip Connect method and achieved a detection accuracy of 98.6%. Li et al. [36][37] improved the mAP value to 98.71% by replacing the convolution layer in the trunk with the residual structure unit CSP based on the YOLOv4 algorithm. Wang et al. [37][38] proposed a lightweight model that used the ShuffleNetV2 structure in the YOLOv5 backbone and achieved an accuracy of 95%. YOLOv7, as a classic representative of the target detection algorithm, has surpassed the previous YOLO series in detection speed and accuracy.