1. Introduction
As an indispensable carrier of electronic components, a printed circuit board (PCB) can realize various circuit functions and plays an essential role in support, fixation, and heat dissipation [
1]. Widely used across industries such as computing and telecommunications, PCBs constitute the primary components of nearly all electronic devices [
2]. With the advent of the fourth industrial revolution, there are heightened demands regarding the levels of integration and quality in PCB manufacturing [
3]. High-quality PCB products undergo stringent inspection procedures to ensure their stability and reliability [
4]. The current efforts by electronic manufacturers to enhance the production quality focus on developing high-precision inspection methods, following the trend of “zero-defect manufacturing”, aimed at minimizing defect occurrences as much as possible [
5]. Given the complexity of PCB manufacturing processes, the emergence of various types of defects is inevitable [
6], such as soldering defects, including missing solders, short solders, and solder balls. The quality of the soldering of electronic components mounted on PCBs greatly impacts the overall product quality. Soldering defects directly or indirectly affect the actual performance of the product. Therefore, conducting a solder quality inspection of PCBs is a crucial step in ensuring the compliance and reliability of the product. Conducting PCB defect detection not only optimizes PCB production lines and reduces the likelihood of defects but also contributes to resource conservation, minimizes capacity wastage, and improves resource utilization. Detecting PCB defects has become a crucial step in enhancing the PCB production quality, and businesses urgently require efficient PCB defect detection technologies to address this issue [
7].
In the early stages of PCB manufacturing, defect detection relied primarily on visual inspection by workers [
8], which has some obvious drawbacks. Firstly, it is heavily influenced by human factors, and the accuracy may vary depending on the skill level and fatigue of the workers. Secondly, with the increase in PCB production and the shrinkage of the line spacing and component volume, visual inspection becomes increasingly challenging. It fails to meet the requirements of modern industrial production levels. With technological advancements, PCB defect detection has gradually shifted toward utilizing advanced machine equipment technologies, such as automated optical inspection (AOI) [
9]. AOI technology primarily uses template matching or image recognition methods [
10], significantly enhancing the detection efficiency. However, the detection outcome is directly affected by the template matching accuracy and lighting conditions, and the equipment still requires supervision, maintenance, and the interpretation of the results by skilled personnel [
11]. The inefficiency of traditional detection methods underscores the crucial role of efficient and automated PCB defect detection in the inspection process.
Currently, deep-learning-based detection methods have become the mainstream direction for PCB defect detection due to their high detection efficiency [
12]. Deep-learning-based PCB defect detection mainly consists of two types of networks: object detection and semantic segmentation [
13]. Object detection networks can be further divided into two-stage algorithms, represented by the Faster-RCNN algorithm [
14], and single-stage algorithms, dominated by the SSD algorithm [
15] and the YOLO series algorithm [
16]. For example, Ding et al. [
17] proposed TDD-net for the detection of PCB defects by combining Faster-RCNN and a feature pyramid network, adopting the point of view that PCB defects account for a small percentage of the image, as well as considering the irregular shape of the defects. Shi et al. [
18] proposed an algorithm, named SSDT, for tiny defect detection based on SSD, which resulted in improved PCB surface defect detection accuracy. Tang et al. [
19] introduced a lightweight PCB defect detection model, light-PDD, which utilizes an improved cross-stage local structure for feature fusion. This model reduces the complexity, enhances the detection speed, and achieves high accuracy.
Semantic segmentation involves partitioning an image into regions with different features, extracting regions of interest [
20]. Kang et al. [
21] proposed an adaptive feature reconstruction network (AFRNet) consisting of a Siamese encoder with shared parameters and a symmetric feature reconstruction module. This significantly improves the segmentation accuracy of various benchmark models for defects on PCBs. Ling et al. [
22] proposed combining the similarity measurement of Siamese networks with encoder–decoder semantic segmentation networks to further enhance the segmentation capabilities for soldering defects on PCBs. Although both networks achieve high segmentation performance, their architectures require both template images and defect images as input, making the segmentation performance highly dependent on image matching, and the detection speed of the networks is relatively slow. Furthermore, the preparation of template images and defect images is tedious and requires high-level acquisition techniques. The UNet network proposed by Ronneberger et al. [
23], which adopts a U-shaped encoder–decoder network structure, effectively utilizes the contextual information in images to enhance the segmentation accuracy and is widely applied in defect detection. Chen et al. [
24] introduced a multi-scale dynamic attention fusion UNet model (MDAF-UNet), providing an effective solution for the segmentation of defects in mobile phone backplanes. Kamanli [
25] proposed MCPAD-UNet for steel surface defect segmentation based on multi-scale cross-patch attention with dilated convolution. This model accurately identifies and segments defects in industrial processes, leveraging multi-scale contextual information to handle complex and subtle defects.
In summary, the challenges in the segmentation of PCB soldering defects include small defect sizes, irregular contours, and significant interference due to background image similarity. In previous studies on PCB defect segmentation, most methods used template matching, such as in references [
21,
22]. Although template matching can achieve satisfactory segmentation results, it requires both template images and defect images, which creates high data acquisition requirements and results in a slow segmentation speed. To address these issues, this paper proposes three critical improvements based on UNet. The UNet network structure only requires defect images for segmentation, and, after the improvements, the segmentation accuracy is enhanced and it meets the requirements regarding the real-time segmentation speed. First, we enhance the encoder’s focus on the differences in features at different scales; second, we introduce a hybrid attention mechanism to reduce the background similarity interference and strengthen the ability to segment the contours of small soldering defects in images at various scales; third, we enhance the decoder’s feature fusion capabilities. Under the condition of having only defect images, this paper achieves higher segmentation accuracy for PCB soldering defects while using a small number of model parameters and achieving a fast detection speed. The main contributions of this paper are as follows.
- (1)
The encoder adopts a backbone network that varies in its attention to different scales, flexibly adjusting the degree of attention to differently scaled feature layers during the feature extraction stage. While maintaining an emphasis on shallower feature layers, it enhances the attention to deeper feature layers, thereby improving the overall model’s ability to segment defect edges.
- (2)
The dynamic hybrid attention module (DHAM) is proposed to replace the ordinary skip connections in the network. In conditions where the background image similarity causes substantial interference, the DHAM effectively utilizes features at various scales to enhance the attention to defect contours.
- (3)
The residual GSConv module (RGSM), based on GSConv, is proposed to be applied within the decoder network, enhancing the fusion capabilities for features between low-resolution and high-resolution feature maps to generate more accurate segmentation results.
The rest of this paper is organized as follows.
Section 2 describes the structure and each module of the improved UNet.
Section 3 presents the experimental setup, evaluation metrics, and loss function.
Section 4 presents the experimental results and analysis, and
Section 5 provides the conclusions.
5. Conclusions
PCB soldering defect segmentation plays a crucial role in the quality control of PCBs. In this study, we propose an improved method for PCB soldering defect segmentation based on UNet. To address the issue of low segmentation accuracy, our proposed model replaces the encoder with the VGG16 encoder. By deepening the network’s feature extraction part to enhance the encoder’s feature extraction capabilities, we aim to capture more detailed edge features of defect contours.
Additionally, we introduce a hybrid attention module based on channel attention and dynamic spatial attention, replacing the simple skip connections in the UNet structure. This helps to mitigate interference from complex backgrounds and facilitates the better acquisition of defect information.
In the decoder network part, we employ the residual GSConv module to fuse features from different depths, enhancing the feature fusion capabilities and better restoring the detail information in the image.
Finally, we design a hybrid loss function combining the Dice loss and focal loss to enhance the model’s ability to distinguish between defects and backgrounds.
The experimental results demonstrate that our model achieves significant segmentation performance while maintaining a fast detection speed and a lower number of model parameters. In future work, we will continue to investigate the influence of different parameters on model training and apply the model to other PCB defects.