PCBA welding spot defect detection method and system based on improved RT-DETR

By improving the feature fusion layer of the RT-DETR model and combining local and global feature processing modules, the problem of low accuracy in PCBA solder joint defect detection is solved, and the accuracy and stability of solder joint defect detection is improved while real-time detection is achieved.

CN120471925AActive Publication Date: 2025-08-12QUANZHOU INST OF EQUIP MFG +1

Patent Information

Application Number
CN202510976072.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-16
Publication Date
2025-08-12
Estimated Expiration
2045-07-16

AI Technical Summary

Technical Problem

The existing PCBA solder joint defect detection method based on the RT-DETR model meets the real-time requirements, but also has the problem of low detection accuracy of solder joint defects, especially in complex backgrounds, the detection effect of small-sized solder joints is not ideal.

Method used

By reconstructing the RepC3 module of the RT-DETR model, the three-level structure of the local feature processing module, the global feature processing module and the feature interaction output module are adopted, and combined with diversified working condition data training, feature consistency loss function and model compression deployment technology, the feature fusion capability is improved, especially local detail perception and global semantic fusion.

Benefits of technology

It significantly improves the accuracy of PCBA solder joint defect detection, can meet real-time detection requirements, and improves the ability to identify small-sized solder joint defects, and maintains efficient and stable in complex industrial scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120471925A_ABST
    Figure CN120471925A_ABST
Patent Text Reader

Abstract

The invention provides a PCBA welding spot defect detection method and system based on improved RT-DETR, and belongs to the technical field of industrial AI quality inspection. The method comprises the steps that S1, a large number of historical PCBA welding spot images are acquired to construct a data set; s2, creating a welding spot defect detection model based on the feature extraction layer, the feature fusion layer and the prediction output layer; s3, the data set is divided into a training set, a verification set and a test set, the welding spot defect detection model is trained through the training set, the trained welding spot defect detection model is verified through the verification set, and the welding spot defect detection model passing verification is tested through the test set; s4, performing compression, drift compensation training and deployment on the welding spot defect detection model passing the test; and S5, PCBA welding spot defect detection is carried out through the deployed welding spot defect detection model. The method has the advantages that the real-time detection requirement is met, and meanwhile, the PCBA welding spot defect detection precision is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of industrial AI quality inspection technology, and in particular to a PCBA solder joint defect detection method and system based on improved RT-DETR. Background Art

[0002] With the widespread adoption of electronic products, the electronics assembly industry continues to grow rapidly. As a core component of electronic products, the reliable inspection of solder joint quality in printed circuit board assemblies (PCBAs) is crucial. Currently, manually assisted solder joint quality inspection equipment is widely used within the industry, particularly for solder joint inspection of non-standard electronic components, which relies heavily on manual visual inspection. This largely manual inspection method suffers from disadvantages such as low efficiency, high labor costs, and high subjectivity. To improve inspection efficiency and objectivity, automated inspection technologies based on image recognition are gaining increasing attention.

[0003] In industrial applications, images for solder joint quality inspection are primarily captured using industrial cameras. Compared to the clear outlines and simple backgrounds typically seen in general target detection, these images present significant challenges: The targets (such as solder joints and their defects) are typically small, the background information is complex, the targets are densely distributed, the defect categories are diverse, and some feature differences between categories are subtle. These factors combine to make accurate detection and detailed classification of solder joint defects challenging.

[0004] In recent years, deep learning-based computer vision technology has been widely used in the field of industrial defect detection. Mainstream deep learning detection methods mainly include two categories: those based on convolutional neural networks (CNNs) and those based on the Transformer architecture. CNNs have advantages in extracting local features in image space, but they are limited by their local receptive field. When dealing with small objects or complex background interference, their ability to model global information is limited, which can easily lead to false detections or missed detections. As a result, their performance in PCBA solder joint defect detection tasks is less than ideal. Transformer-based object detection methods, due to their global modeling capabilities and self-attention mechanism, have shown great potential for handling complex inspection tasks. However, the high resource consumption caused by calculating attention scores makes meeting the real-time requirements of inspection tasks a challenge.

[0005] To overcome the computational bottleneck of the Transformer model, the RT-DETR model was developed. RT-DETR significantly reduces the resource overhead caused by calculating attention scores through architectural optimization, and can meet the real-time requirements of solder joint defect detection, making it have application prospects in the field of industrial inspection.Figure 5 As shown in Figure 2, RT-DETR includes a key component, RepC3, which is mainly used in the feature fusion stage to achieve effective fusion of shallow feature maps (rich in detail information) and deep feature maps (rich in semantic information). Specifically, the RepC3 module includes: Input: used to receive input features x; First branch: After performing a 1×1 convolution on the input feature x, it is processed by at least one repeating module. Repeating modules can be stacked N times as needed. Each repeating module contains sub-branch a and sub-branch b for feature processing. The features processed by sub-branch a and sub-branch b are element-wise added together and then processed through the SiLU activation function. The result serves as the input of the next repeating module or the final output of the first branch.

[0006] Second branch: perform 1×1 convolution operation on the input feature x; Output end: The output feature map of the first branch is added to the output feature map of the second branch element by element to generate the final fused output feature map.

[0007] However, when the aforementioned RepC3 structure is applied to the task of inspecting small-scale solder joints in the complex context of PCBAs, it suffers from insufficient multi-scale information fusion capabilities. The core of the problem lies in the fact that the same type of target (such as a solder joint or a specific defect) appears as an abstract semantic region in deep high-level feature maps, but as irregularly shaped pixel blocks in shallow low-level feature maps, resulting in a significant semantic gap between feature maps at different levels. RepC3 primarily relies on convolution operations for cross-layer information exchange. Due to the inherent receptive field limitations of standard convolution operations, it is difficult to bridge the huge differences between these different semantic spaces and establish effective correspondences between features. This results in unsatisfactory feature fusion effects, and key details of small targets (such as solder joints) are easily lost during the fusion process, ultimately limiting the overall detection accuracy of the model.

[0008] Therefore, how to provide a PCBA solder joint defect detection method and system based on improved RT-DETR to improve the accuracy of PCBA solder joint defect detection while meeting real-time detection requirements has become a technical problem that needs to be solved urgently. Summary of the Invention

[0009] The technical problem to be solved by the present invention is to provide a PCBA solder joint defect detection method and system based on improved RT-DETR, so as to improve the accuracy of PCBA solder joint defect detection while meeting the real-time detection requirements.

[0010] In a first aspect, the present invention provides a PCBA solder joint defect detection method based on improved RT-DETR, comprising the following steps: Step S1: Acquire a large number of historical PCBA solder joint images, pre-process and annotate each of the historical PCBA solder joint images, and then construct a data set; Step S2: creating a solder joint defect detection model based on the feature extraction layer, the feature fusion layer, and the prediction output layer, and setting a loss function of the solder joint defect detection model; Step S3, dividing the data set into a training set, a validation set, and a test set, training a solder joint defect detection model using the training set and a loss function, validating the trained solder joint defect detection model using the validation set, and testing the validated solder joint defect detection model using the test set; Step S4: compressing, drift compensation training, and deploying the solder joint defect detection model that has passed the test; Step S5: Perform PCBA solder point defect detection using the deployed solder point defect detection model.

[0011] Furthermore, the step S1 is specifically as follows: A large number of historical PCBA solder joint images with different lighting conditions, shooting angles, and PCBA models are acquired. Each of the historical PCBA solder joint images is preprocessed, including at least cropping, contrast adjustment, exposure adjustment, and size adjustment. The preprocessed historical PCBA solder joint images are labeled with defect types and defect locations using the labelimg annotation tool. A dataset is constructed based on the labeled historical PCBA solder joint images. The defect types include at least normal, kneeling foot, excessive solder, insufficient solder, and continuous solder.

[0012] Furthermore, in step S2, the feature extraction layer is constructed based on the backbone network of the RT-DETR model, and is used to extract shallow features and deep features from the input PCBA solder joint image, and input the shallow features and deep features into the feature fusion layer; The feature fusion layer is constructed based on the local feature processing module, the global feature processing module and the feature interaction output module; The local feature processing module is constructed based on an input channel adjustment unit, a local enhancement unit, a structure optimization unit, and a residual connection unit; the input channel adjustment unit is used to perform channel compression and preliminary feature extraction on the input shallow features and deep features through a 1x1 first convolution normalization activation layer to obtain initial features; the local enhancement unit is used to enhance the local perception ability of the initial features and introduce nonlinear transformation through two stacked local enhancement sub-units to obtain enhanced initial features; the structure optimization unit is used to fuse the two-branch structures of the two local enhancement sub-units into a single 3x3 convolution layer in the inference stage; the residual connection unit is used to fuse the enhanced initial features, shallow features, and deep features to obtain local features, and input the local features into the global feature processing module; The global feature processing module is constructed based on an attention generation unit, a channel space mapping unit, and a spatial compression unit; the attention generation unit is used to fuse the local features through global average pooling, global maximum pooling, and a Softmax function to obtain a fused attention feature; the channel space mapping unit is used to perform spatial mapping on the local features through a 1x1 second convolution normalized activation layer to obtain a channel space mapping feature; the spatial compression unit is used to perform spatial compression on the local features through a 1x1 third convolution normalized activation layer to obtain a spatial compression feature; The feature interaction output module is used to perform matrix multiplication on the fused attention feature and the channel space mapping feature to obtain a spatial enhancement feature, perform matrix multiplication on the channel space mapping feature and the spatial compression feature to obtain a channel enhancement feature, input the spatial enhancement feature into the 1x1 fourth convolution normalized activation layer to obtain a spatial attention map, and input the channel enhancement feature into the unnormalized convolution activation layer to obtain a channel attention map; perform element-by-element multiplication on the spatial attention map and the channel attention map to obtain an initial fused feature, perform a residual connection on the initial fused feature and the local feature to obtain an enhanced fused feature and output it to the prediction output layer; The prediction output layer is constructed based on the decoder of the RT-DETR model, and is used to map the enhanced fusion features into PCBA solder joint defect detection results carrying defect types and defect locations; The formula of the loss function is: ; in, Represents the loss value of the loss function; represents the defect classification loss; represents the bounding box regression loss; represents the bounding box overlap loss; represents feature consistency loss; 、 、 、 Both represent weight coefficients.

[0013] Furthermore, the step S3 is specifically as follows: Dividing the data set into a training set, a validation set, and a test set in a ratio of 8:1:1 using a stratified sampling method, setting hyperparameters including at least a batch size, an optimizer, a learning rate, a weight decay rate, and a training cycle, and training a solder joint defect detection model using the training set and the hyperparameters until a loss value of the loss function is less than a preset loss threshold or a preset early stopping condition is met; The average precision mean, Giga floating point operations per second, parameter count, and frames per second are calculated using the validation set to verify the trained solder joint defect detection model. If the verification fails, the training set is expanded to continue training. If the verification passes, then: The confidence level is calculated using the test set to test the verified solder joint defect detection model. If the test fails, the training set is expanded to continue training; if the test passes, the training is terminated.

[0014] Furthermore, the step S4 is specifically as follows: The solder joint defect detection model that has passed the test is compressed using quantization technology and dynamic pruning technology, and the performance of the compressed solder joint defect detection model is verified. Actual PCBA solder joint images are collected, and drift compensation training is performed on the performance-verified solder joint defect detection model using each of the actual PCBA solder joint images. The solder joint defect detection model after drift compensation training is deployed using containerization technology.

[0015] In a second aspect, the present invention provides a PCBA solder joint defect detection system based on an improved RT-DETR, comprising the following modules: A data set construction module is used to obtain a large number of historical PCBA solder joint images, pre-process and annotate each of the historical PCBA solder joint images, and then construct a data set; A solder joint defect detection model creation module is used to create a solder joint defect detection model based on the feature extraction layer, the feature fusion layer and the prediction output layer, and set the loss function of the solder joint defect detection model; a solder joint defect detection model training module, configured to divide the data set into a training set, a validation set, and a test set, train the solder joint defect detection model using the training set and a loss function, validate the trained solder joint defect detection model using the validation set, and test the validated solder joint defect detection model using the test set; A solder joint defect detection model deployment module is used to compress, drift compensate and deploy the solder joint defect detection model that has passed the test; The defect detection module is used to perform PCBA solder point defect detection by using the deployed solder point defect detection model.

[0016] Furthermore, the dataset construction module is specifically used to: A large number of historical PCBA solder joint images with different lighting conditions, shooting angles, and PCBA models are acquired. Each of the historical PCBA solder joint images is preprocessed, including at least cropping, contrast adjustment, exposure adjustment, and size adjustment. The preprocessed historical PCBA solder joint images are labeled with defect types and defect locations using the labelimg annotation tool. A dataset is constructed based on the labeled historical PCBA solder joint images. The defect types include at least normal, kneeling foot, excessive solder, insufficient solder, and continuous solder.

[0017] Furthermore, in the solder joint defect detection model creation module, the feature extraction layer is constructed based on the backbone network of the RT-DETR model, and is used to extract shallow features and deep features from the input PCBA solder joint image, and input the shallow features and deep features into the feature fusion layer; The feature fusion layer is constructed based on the local feature processing module, the global feature processing module and the feature interaction output module; The local feature processing module is constructed based on an input channel adjustment unit, a local enhancement unit, a structure optimization unit, and a residual connection unit; the input channel adjustment unit is used to perform channel compression and preliminary feature extraction on the input shallow features and deep features through a 1x1 first convolution normalization activation layer to obtain initial features; the local enhancement unit is used to enhance the local perception ability of the initial features and introduce nonlinear transformation through two stacked local enhancement sub-units to obtain enhanced initial features; the structure optimization unit is used to fuse the two-branch structures of the two local enhancement sub-units into a single 3x3 convolution layer in the inference stage; the residual connection unit is used to fuse the enhanced initial features, shallow features, and deep features to obtain local features, and input the local features into the global feature processing module; The global feature processing module is constructed based on an attention generation unit, a channel space mapping unit, and a spatial compression unit; the attention generation unit is used to fuse the local features through global average pooling, global maximum pooling, and a Softmax function to obtain a fused attention feature; the channel space mapping unit is used to perform spatial mapping on the local features through a 1x1 second convolution normalized activation layer to obtain a channel space mapping feature; the spatial compression unit is used to perform spatial compression on the local features through a 1x1 third convolution normalized activation layer to obtain a spatial compression feature; The feature interaction output module is used to perform matrix multiplication on the fused attention feature and the channel space mapping feature to obtain a spatial enhancement feature, perform matrix multiplication on the channel space mapping feature and the spatial compression feature to obtain a channel enhancement feature, input the spatial enhancement feature into the 1x1 fourth convolution normalized activation layer to obtain a spatial attention map, and input the channel enhancement feature into the unnormalized convolution activation layer to obtain a channel attention map; perform element-by-element multiplication on the spatial attention map and the channel attention map to obtain an initial fused feature, perform a residual connection on the initial fused feature and the local feature to obtain an enhanced fused feature and output it to the prediction output layer; The prediction output layer is constructed based on the decoder of the RT-DETR model, and is used to map the enhanced fusion features into PCBA solder joint defect detection results carrying defect types and defect locations; The formula of the loss function is: ; in, Represents the loss value of the loss function; represents the defect classification loss; represents the bounding box regression loss; represents the bounding box overlap loss; represents feature consistency loss; 、 、 、 Both represent weight coefficients.

[0018] Furthermore, the solder joint defect detection model training module is specifically: Dividing the data set into a training set, a validation set, and a test set in a ratio of 8:1:1 using a stratified sampling method, setting hyperparameters including at least a batch size, an optimizer, a learning rate, a weight decay rate, and a training cycle, and training a solder joint defect detection model using the training set and the hyperparameters until a loss value of the loss function is less than a preset loss threshold or a preset early stopping condition is met; The average precision mean, Giga floating point operations per second, parameter count, and frames per second are calculated using the validation set to verify the trained solder joint defect detection model. If the verification fails, the training set is expanded to continue training. If the verification passes, then: The confidence level is calculated using the test set to test the verified solder joint defect detection model. If the test fails, the training set is expanded to continue training; if the test passes, the training is terminated.

[0019] Furthermore, the solder joint defect detection model deployment module is specifically used to: The solder joint defect detection model that has passed the test is compressed using quantization technology and dynamic pruning technology, and the performance of the compressed solder joint defect detection model is verified. Actual PCBA solder joint images are collected, and drift compensation training is performed on the performance-verified solder joint defect detection model using each of the actual PCBA solder joint images. The solder joint defect detection model after drift compensation training is deployed using containerization technology.

[0020] The advantages of the present invention are: 1. Build a data set by acquiring a large number of historical PCBA solder joint images; then create a solder joint defect detection model based on the feature extraction layer, feature fusion layer and prediction output layer, and set the loss function of the solder joint defect detection model; divide the data set into training set, validation set and test set, train the solder joint defect detection model through the training set and loss function, verify the trained solder joint defect detection model through the validation set, test the verified solder joint defect detection model through the test set, compress, drift compensate and deploy the tested solder joint defect detection model, and finally perform PCBA solder joint defect detection through the deployed solder joint defect detection model; the feature extraction layer is built based on the backbone network of the RT-DETR model, which is used to extract shallow features and deep features from the input PCBA solder joint image, and input the shallow features and deep features into the feature fusion layer; the feature fusion layer is built based on the local feature processing module, the global feature processing module and the feature interaction output module. It is used to fuse shallow features and deep features to obtain enhanced fusion features and output them to the prediction output layer; the prediction output layer is constructed based on the decoder of the RT-DETR model, which is used to map the enhanced fusion features into PCBA solder joint defect detection results carrying defect types and defect locations; that is, by reconstructing the RepC3 module of the RT-DETR model, replacing the traditional RepC3 module with the feature fusion layer, while retaining the efficient backbone network and decoder of the RT-DETR model to maintain real-time performance, the local feature processing module is used to enhance the perception of small target details, and the attention mechanism of the global feature processing module and the spatial-channel collaborative optimization of the feature interaction output module are combined to effectively bridge the gap between shallow details and deep semantics, and significantly improve the recognition ability of subtle defects in solder joints; at the same time, with the combination of diversified working condition data training, feature consistency loss function constraints and model compression deployment technology, it is finally achieved while meeting the real-time detection requirements and greatly improving the accuracy of PCBA solder joint defect detection.

[0021] 2. The feature fusion layer adopts a unique three-level structure of "local feature processing module + global feature processing module + feature interaction output module", with clear hierarchy and division of labor, which can more effectively integrate feature information of different scales and semantic levels.

[0022] 3. Two stacked local enhancement sub-units enhance the model's perception and nonlinear modeling capabilities for local micro-areas (such as solder joint defects), which is crucial for identifying small solder joint defects (such as kneeling feet and insufficient solder). In the inference stage, the dual-branch structure is fused into a single 3x3 convolutional layer, which significantly improves the inference speed (reduces the amount of computation) while maintaining the enhancement capability during training, which is beneficial for industrial deployment. The enhanced features are residually connected with the original shallow features (containing detailed information) and deep features (containing semantic information), effectively fusing information at different levels of abstraction, so that the local features contain both detailed and semantic information.

[0023] 4. Use global average pooling, maximum pooling and Softmax to generate fused attention features, which can focus on more important areas in the image; through independent channel space mapping and spatial compression operations, feature information of different dimensions can be extracted and refined respectively.

[0024] 5. Perform matrix multiplication on the fused attention features and the channel spatial mapping features to obtain spatial enhancement features, and perform matrix multiplication on the channel spatial mapping features and the spatial compression features to obtain channel enhancement features. This interactive method can better capture the complex relationship between features than simple splicing or addition; further convert the spatial enhancement and channel enhancement features into spatial attention maps and channel attention maps, and perform deep fusion through element-by-element multiplication to form initial fusion features; finally, the initial fusion features after deep interactive fusion are residually connected with the original local features, which not only retains the original information but also incorporates highly refined global perception information. The final output "enhanced fusion features" have a stronger ability to discriminate against minor defects.

[0025] 6. The loss function combines defect classification loss, bounding box regression loss, bounding box overlap loss, and feature consistency loss. The feature consistency loss aims to constrain the feature representation learned by the model to be consistent (possibly for similar normal or defective samples). This helps improve the model's generalization ability, robustness to noise and small changes, and prevent overfitting, thereby improving actual detection accuracy and stability in complex industrial scenarios.

[0026] 7. By collecting images with different lighting conditions, different shooting angles, and different PCBA models, and performing pre-processing such as cropping, contrast / exposure / size adjustment, this greatly enhances the diversity and coverage of the dataset, which is the basis for the model to have strong generalization capabilities; using stratified sampling (8:1:1) to divide the training / validation / test sets helps ensure the representativeness of the data distribution and more objectively evaluate model performance; the verification phase focuses not only on accuracy indicators (such as mean average precision (mAP)), but also on efficiency indicators (thousand frames per second (FPS), giga floating-point operations per second (GFLOPS)) and model size (number of parameters) to ensure that the model meets actual deployment requirements.

[0027] 8. Use quantization and dynamic pruning techniques to compress the trained model, directly optimizing for resource constraints during deployment (such as computing power and memory of embedded devices), reducing computational complexity and storage requirements. Use containerization technology for deployment, which improves deployment convenience, portability, maintainability, and resource utilization, in line with modern industrial software deployment trends. After deployment, the model is trained for drift compensation by collecting actual PCBA solder joint images, effectively coping with changes in the actual production environment that may occur over time (such as equipment aging, material batch differences, subtle environmental changes, etc.), maintaining the model's detection accuracy and stability during long-term operation, and solving the key industrial pain point of model "aging."

[0028] 9. By innovatively constructing a feature fusion layer consisting of a local feature processing module, a global feature processing module, and a feature interaction output module, combined with designs such as stacked local enhancement units, attention mechanisms, and residual connections, the model's local perception ability and feature discrimination accuracy for minor PCBA solder joint defects (such as kneeling feet and insufficient solder) are significantly improved; the introduction of a four-element loss function containing feature consistency loss and a diversified dataset construction strategy enhances the robustness and generalization of the model in complex industrial scenarios; at the same time, by optimizing the structure in the inference stage (such as fusing two branches into a single convolution), adopting quantized pruning and compression technology, containerized deployment, and drift compensation training, it effectively balances detection accuracy and real-time efficiency, and ensures the stability and adaptability of the model in long-term industrial applications, making it particularly suitable for high-precision and high-efficiency PCBA solder joint defect detection needs. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0030] Figure 1 The present invention is a flow chart of a PCBA solder joint defect detection method based on improved RT-DETR.

[0031] Figure 2 It is a structural schematic diagram of a PCBA solder joint defect detection system based on improved RT-DETR of the present invention.

[0032] Figure 3 It is a structural schematic diagram of the feature fusion layer of the present invention.

[0033] Figure 4 It is a structural schematic diagram of the structural optimization unit of the present invention.

[0034] Figure 5 It is a structural diagram of the traditional RT-DETR model.

[0035] Figure 6This is a comparative thermal diagram of the solder joint defect detection model of the present invention and the traditional RT-DETR model. DETAILED DESCRIPTION

[0036] The technical solution in the embodiments of the present application has the following overall idea: reconstructing the RepC3 module of the RT-DETR model, replacing the traditional RepC3 module with a feature fusion layer, and using a local feature processing module to enhance the perception of small target details while retaining the efficient backbone network and decoder of the RT-DETR model to maintain real-time performance. Combining the attention mechanism of the global feature processing module with the spatial-channel collaborative optimization of the feature interaction output module effectively bridges the gap between shallow details and deep semantics, and significantly improves the ability to identify subtle defects in solder joints. At the same time, combined with diversified working condition data training, feature consistency loss function constraints and model compression deployment technology, it is possible to achieve the improvement of PCBA solder joint defect detection accuracy while meeting real-time detection requirements.

[0037] Please refer to Figures 1 to 6 As shown, a preferred embodiment of the PCBA solder joint defect detection method based on improved RT-DETR of the present invention includes the following steps: Step S1: Acquire a large number of historical PCBA solder joint images, pre-process and annotate each of the historical PCBA solder joint images, and then construct a data set; Step S2: creating a solder joint defect detection model based on the feature extraction layer, the feature fusion layer, and the prediction output layer, and setting a loss function of the solder joint defect detection model; The feature extraction layer is constructed based on the backbone network of the RT-DETR model, and is used to extract shallow features and deep features from the input PCBA solder joint image, and input the shallow features and deep features into the feature fusion layer; The feature fusion layer is constructed based on the local feature processing module, the global feature processing module and the feature interaction output module; The feature fusion layer adopts a unique three-level structure of "local feature processing module + global feature processing module + feature interaction output module", with clear hierarchy and division of labor, which can more effectively integrate feature information of different scales and semantic levels.

[0038] The local feature processing module is constructed based on an input channel adjustment unit, a local enhancement unit, a structure optimization unit, and a residual connection unit; the input channel adjustment unit is used to perform channel compression and preliminary feature extraction on the input shallow features and deep features through a 1x1 first convolution normalization activation layer (1×1CBS, consisting of a convolution operation, batch normalization, and SiLU activation function) to obtain initial features; the local enhancement unit is used to perform local perception on the initial features through two stacked local enhancement sub-units (RepLEBlock, comprising two parallel 3×3CBS branches and a 1×1CBS branch, the outputs of which are processed by a nonlinear activation function (SiLU) after element-by-element addition. Enhance and introduce nonlinear transformation to obtain enhanced initial features; the structural optimization unit is used to fuse the two-branch structures of the two local enhancement sub-units into a single 3x3 convolution layer during the inference phase (by folding the convolution kernel and the batch normalization parameter (i.e., fusing the convolution and normalization operations), and zero-padding the 1×1 convolution kernel to expand it to a 3×3 size, so that the two branches can be merged into a standard convolution operation); the residual connection unit is used to fuse the enhanced initial features, shallow features, and deep features to obtain local features (a four-dimensional feature tensor of size [n, c, h, w], where n represents the batch size, c represents the channel, and h and w represent the height and width of the feature map, respectively), and input the local features into the global feature processing module; Two stacked local enhancement sub-units enhance the model's perception and nonlinear modeling capabilities for local micro-areas (such as solder joint defects), which is crucial for identifying small solder joint defects (such as kneeling feet and insufficient solder). In the inference stage, the dual-branch structure is fused into a single 3x3 convolutional layer, which significantly improves the inference speed (reduces the amount of computation) while maintaining the enhancement capabilities during training, which is beneficial for industrial deployment. The enhanced features are residually connected with the original shallow features (containing detailed information) and deep features (containing semantic information), effectively fusing information at different levels of abstraction so that local features contain both detailed and semantic information.

[0039] The global feature processing module is constructed based on the attention generation unit, the channel space mapping unit and the space compression unit; the attention generation unit is used to fuse the local features through global average pooling, global maximum pooling and Softmax function to obtain fused attention features (the input features (local features) are respectively sent to the two sub-branches, and global average pooling and global maximum pooling operations are performed on the two sub-branches to generate two channel compression features with a size of [n, c, 1, 1], and then the Softmax function is applied to the two features respectively, and the channel dimension (i.e., the second dimension) is rearranged to the last dimension, that is, the size is adjusted to [n, 1, 1, c], and then the two features are spliced on the channel dimension (i.e., the second dimension) to obtain a fused attention feature with a size of [n, 2, 1, c]). The channel space mapping unit is used to perform spatial mapping on each of the local features through a 1x1 second convolution normalization activation layer to obtain a channel space mapping feature (that is, the input feature first passes through a 1×1 CBS to obtain a tensor [n, c, h, w] with the same shape as the original input, and then expands the tensor into [n, c, 1, hw] in the spatial dimension and rearranges it into [n, 1, c, hw], where hw = h×w); the spatial compression unit is used to perform spatial compression on each of the local features through a 1x1 third convolution normalization activation layer to obtain a spatial compression feature (that is, the input feature first passes through a 1×1 CBS to obtain a feature map with an output dimension of [n, 1, h, w], and then flattens its spatial dimension to [n, 1, 1, hw] and adjusts it to [n, 1, hw, 1]); Global average pooling, maximum pooling and Softmax are used to generate fused attention features, which can focus on more important areas in the image; through independent channel space mapping and spatial compression operations, feature information of different dimensions can be extracted and refined respectively.

[0040] The feature interaction output module is used to perform matrix multiplication on the fusion attention feature and the channel space mapping feature to obtain a spatial enhancement feature (matrix multiplication of [n,2,1,c] and [n,1,c,hw] is performed to obtain a tensor of size [n,2,1,hw], and the shape is adjusted to [n,2,h,w]), and to perform matrix multiplication on the channel space mapping feature and the spatial compression feature to obtain a channel enhancement feature (matrix multiplication of [n,1,c,hw] and [n,1,hw,1] is performed to obtain a tensor of size [n,1,c,1], and the shape is adjusted to [n,c,1,1]), and the spatial enhancement feature is input into the fourth convolution normalized activation layer of 1x1 to obtain a spatial attention map (the spatial enhancement feature [ n,2,h,w] is fed into a 1×1 CBS to obtain a spatial attention map of dimension [n,1,h,w]), the channel enhancement feature is input into an unnormalized convolution activation layer (composed of a convolution operation and a SiLU activation function) to obtain a channel attention map (the channel enhancement feature [n,c,1,1] is fed into an unnormalized convolution activation layer (CS) to obtain an enhanced channel attention map of dimension [n,c,1,1]); the spatial attention map and the channel attention map are element-wise multiplied to obtain an initial fusion feature (shape [n,c,h,w]), the initial fusion feature is residually connected with the local feature to obtain an enhanced fusion feature (shape still [n,c,h,w]) and output to the prediction output layer; Matrix multiplication is performed on the fused attention features and the channel space mapping features to obtain spatial enhancement features, and matrix multiplication is performed on the channel space mapping features and the spatial compression features to obtain channel enhancement features. This interactive method can better capture the complex relationship between features than simple splicing or addition; the spatial enhancement and channel enhancement features are further converted into spatial attention maps and channel attention maps, and deep fusion is performed through element-by-element multiplication to form initial fusion features; finally, the initial fusion features after deep interactive fusion are residually connected with the original local features, which not only retains the original information but also incorporates highly refined global perception information. The final output "enhanced fusion features" have a stronger ability to discriminate against minor defects.

[0041] The prediction output layer is constructed based on the decoder of the RT-DETR model, and is used to map the enhanced fusion features into PCBA solder joint defect detection results carrying defect types and defect locations; Step S3, dividing the data set into a training set, a validation set, and a test set, training a solder joint defect detection model using the training set and a loss function, validating the trained solder joint defect detection model using the validation set, and testing the validated solder joint defect detection model using the test set; Step S4: compressing, drift compensation training, and deploying the solder joint defect detection model that has passed the test; Step S5: Perform PCBA solder point defect detection using the deployed solder point defect detection model.

[0042] The step S1 is specifically as follows: A large number of historical PCBA solder joint images with different lighting conditions, shooting angles, and PCBA models are acquired. Each of the historical PCBA solder joint images is preprocessed, including at least cropping, contrast adjustment, exposure adjustment, and size adjustment. The preprocessed historical PCBA solder joint images are labeled with defect types and defect locations using the labelimg annotation tool. A dataset is constructed based on the labeled historical PCBA solder joint images. The defect types include at least normal, kneeling foot, excessive solder, insufficient solder, and continuous solder.

[0043] In step S2, the formula of the loss function is: ; in, Represents the loss value of the loss function; represents the defect classification loss; represents the bounding box regression loss; represents the bounding box overlap loss; represents feature consistency loss; 、 、 、 Both represent weight coefficients.

[0044] ; in, represents the number of positive samples (the number of predictions that match the true bounding box); represents the predicted defect category probability vector; Represents the true category one-hot vector; represents the focal loss function; ; in, Represents the predicted normalized bounding box coordinates; represents the real bounding box coordinates; represents the L1 norm; ; ; in, represents the spatial attention map output; Represents the channel attention map output; Represents the input feature tensor (H×W×C); represents the generalized intersection-over-union loss function.

[0045] The loss function combines defect classification loss, bounding box regression loss, bounding box overlap loss, and feature consistency loss. The feature consistency loss aims to constrain the feature representation learned by the model to be consistent (possibly for similar normal or defective samples). This helps improve the model's generalization ability, robustness to noise and small changes, and prevent overfitting, thereby improving actual detection accuracy and stability in complex industrial scenarios.

[0046] The step S3 is specifically as follows: The data set is divided into a training set, a validation set, and a test set in a ratio of 8:1:1 by a stratified sampling method. Hyperparameters including at least the number of batch training, the optimizer, the learning rate, the weight decay rate, and the training cycle are set. The solder joint defect detection model is trained using the training set and the hyperparameters until the loss value of the loss function is less than a preset loss threshold or the preset early stopping condition is met. The number of batch training is 8; the optimizer uses AdamW; the learning rate is 0.0001; the weight decay rate is 0.0001; and the training cycle is 216 rounds.

[0047] The mean average precision (mAP), gigaflops (GFLOPs), parameters (Params), and frames per second (FPS) are calculated using the validation set to verify the trained solder joint defect detection model. If the verification fails, the training set is expanded to continue training. If the verification passes, then: The confidence level is calculated using the test set to test the verified solder joint defect detection model. If the test fails, the training set is expanded to continue training; if the test passes, the training is terminated.

[0048] The step S4 is specifically as follows: The solder joint defect detection model that has passed the test is compressed using quantization technology and dynamic pruning technology, and the performance of the compressed solder joint defect detection model is verified. Actual PCBA solder joint images are collected, and drift compensation training is performed on the performance-verified solder joint defect detection model using each of the actual PCBA solder joint images. The solder joint defect detection model after drift compensation training is deployed using containerization technology.

[0049] Quantization and dynamic pruning techniques are used to compress the trained model, directly optimizing for resource constraints during deployment (such as computing power and memory of embedded devices), reducing computational complexity and storage requirements. Containerization technology is used for deployment, improving deployment convenience, portability, maintainability, and resource utilization, in line with modern industrial software deployment trends. After deployment, the model is trained for drift compensation by collecting actual PCBA solder joint images, effectively responding to changes in the actual production environment that may occur over time (such as equipment aging, material batch differences, subtle environmental changes, etc.), maintaining the model's detection accuracy and stability during long-term operation, and resolving the key industrial pain point of model "aging."

[0050] By innovatively constructing a feature fusion layer consisting of a local feature processing module, a global feature processing module, and a feature interaction output module, combined with designs such as stacked local enhancement units, an attention mechanism, and residual connections, the model's local perception ability and feature discrimination accuracy for minor PCBA solder joint defects (such as kneeling feet and insufficient solder) are significantly improved; the introduction of a four-element loss function including feature consistency loss and a diversified dataset construction strategy enhances the robustness and generalization of the model in complex industrial scenarios; at the same time, by optimizing the structure in the inference stage (such as fusing two branches into a single convolution), adopting quantized pruning and compression technology, containerized deployment, and drift compensation training, it effectively balances detection accuracy and real-time efficiency, and ensures the stability and adaptability of the model in long-term industrial applications. It is particularly suitable for high-precision and high-efficiency PCBA solder joint defect detection needs.

[0051] A preferred embodiment of the PCBA solder joint defect detection system based on the improved RT-DETR of the present invention includes the following modules: A data set construction module is used to obtain a large number of historical PCBA solder joint images, pre-process and annotate each of the historical PCBA solder joint images, and then construct a data set; A solder joint defect detection model creation module is used to create a solder joint defect detection model based on the feature extraction layer, the feature fusion layer and the prediction output layer, and set the loss function of the solder joint defect detection model; The feature extraction layer is constructed based on the backbone network of the RT-DETR model, and is used to extract shallow features and deep features from the input PCBA solder joint image, and input the shallow features and deep features into the feature fusion layer; The feature fusion layer is constructed based on the local feature processing module, the global feature processing module and the feature interaction output module; The feature fusion layer adopts a unique three-level structure of "local feature processing module + global feature processing module + feature interaction output module", with clear hierarchy and division of labor, which can more effectively integrate feature information of different scales and semantic levels.

[0052] The local feature processing module is constructed based on an input channel adjustment unit, a local enhancement unit, a structure optimization unit, and a residual connection unit; the input channel adjustment unit is used to perform channel compression and preliminary feature extraction on the input shallow features and deep features through a 1x1 first convolution normalization activation layer (1×1CBS, consisting of a convolution operation, batch normalization, and SiLU activation function) to obtain initial features; the local enhancement unit is used to perform local perception on the initial features through two stacked local enhancement sub-units (RepLEBlock, comprising two parallel 3×3CBS branches and a 1×1CBS branch, the outputs of which are processed by a nonlinear activation function (SiLU) after element-by-element addition. Enhance and introduce nonlinear transformation to obtain enhanced initial features; the structural optimization unit is used to fuse the two-branch structures of the two local enhancement sub-units into a single 3x3 convolution layer during the inference phase (by folding the convolution kernel and the batch normalization parameter (i.e., fusing the convolution and normalization operations), and zero-padding the 1×1 convolution kernel to expand it to a 3×3 size, so that the two branches can be merged into a standard convolution operation); the residual connection unit is used to fuse the enhanced initial features, shallow features, and deep features to obtain local features (a four-dimensional feature tensor of size [n, c, h, w], where n represents the batch size, c represents the channel, and h and w represent the height and width of the feature map, respectively), and input the local features into the global feature processing module; Two stacked local enhancement sub-units enhance the model's perception and nonlinear modeling capabilities for local micro-areas (such as solder joint defects), which is crucial for identifying small solder joint defects (such as kneeling feet and insufficient solder). In the inference stage, the dual-branch structure is fused into a single 3x3 convolutional layer, which significantly improves the inference speed (reduces the amount of computation) while maintaining the enhancement capabilities during training, which is beneficial for industrial deployment. The enhanced features are residually connected with the original shallow features (containing detailed information) and deep features (containing semantic information), effectively fusing information at different levels of abstraction so that local features contain both detailed and semantic information.

[0053] The global feature processing module is constructed based on the attention generation unit, the channel space mapping unit and the space compression unit; the attention generation unit is used to fuse the local features through global average pooling, global maximum pooling and Softmax function to obtain fused attention features (the input features (local features) are respectively sent to the two sub-branches, and global average pooling and global maximum pooling operations are performed on the two sub-branches to generate two channel compression features with a size of [n, c, 1, 1], and then the Softmax function is applied to the two features respectively, and the channel dimension (i.e., the second dimension) is rearranged to the last dimension, that is, the size is adjusted to [n, 1, 1, c], and then the two features are spliced on the channel dimension (i.e., the second dimension) to obtain a fused attention feature with a size of [n, 2, 1, c]). The channel space mapping unit is used to perform spatial mapping on each of the local features through a 1x1 second convolution normalization activation layer to obtain a channel space mapping feature (that is, the input feature first passes through a 1×1 CBS to obtain a tensor [n, c, h, w] with the same shape as the original input, and then expands the tensor into [n, c, 1, hw] in the spatial dimension and rearranges it into [n, 1, c, hw], where hw = h×w); the spatial compression unit is used to perform spatial compression on each of the local features through a 1x1 third convolution normalization activation layer to obtain a spatial compression feature (that is, the input feature first passes through a 1×1 CBS to obtain a feature map with an output dimension of [n, 1, h, w], and then flattens its spatial dimension to [n, 1, 1, hw] and adjusts it to [n, 1, hw, 1]); Global average pooling, maximum pooling and Softmax are used to generate fused attention features, which can focus on more important areas in the image; through independent channel space mapping and spatial compression operations, feature information of different dimensions can be extracted and refined respectively.

[0054] The feature interaction output module is used to perform matrix multiplication on the fusion attention feature and the channel space mapping feature to obtain a spatial enhancement feature (matrix multiplication of [n,2,1,c] and [n,1,c,hw] is performed to obtain a tensor of size [n,2,1,hw], and the shape is adjusted to [n,2,h,w]), and to perform matrix multiplication on the channel space mapping feature and the spatial compression feature to obtain a channel enhancement feature (matrix multiplication of [n,1,c,hw] and [n,1,hw,1] is performed to obtain a tensor of size [n,1,c,1], and the shape is adjusted to [n,c,1,1]), and the spatial enhancement feature is input into the fourth convolution normalized activation layer of 1x1 to obtain a spatial attention map (the spatial enhancement feature [ n,2,h,w] is fed into a 1×1 CBS to obtain a spatial attention map of dimension [n,1,h,w]), the channel enhancement feature is input into an unnormalized convolution activation layer (composed of a convolution operation and a SiLU activation function) to obtain a channel attention map (the channel enhancement feature [n,c,1,1] is fed into an unnormalized convolution activation layer (CS) to obtain an enhanced channel attention map of dimension [n,c,1,1]); the spatial attention map and the channel attention map are element-wise multiplied to obtain an initial fusion feature (shape [n,c,h,w]), the initial fusion feature is residually connected with the local feature to obtain an enhanced fusion feature (shape still [n,c,h,w]) and output to the prediction output layer; Matrix multiplication is performed on the fused attention features and the channel space mapping features to obtain spatial enhancement features, and matrix multiplication is performed on the channel space mapping features and the spatial compression features to obtain channel enhancement features. This interactive method can better capture the complex relationship between features than simple splicing or addition; the spatial enhancement and channel enhancement features are further converted into spatial attention maps and channel attention maps, and deep fusion is performed through element-by-element multiplication to form initial fusion features; finally, the initial fusion features after deep interactive fusion are residually connected with the original local features, which not only retains the original information but also incorporates highly refined global perception information. The final output "enhanced fusion features" have a stronger ability to discriminate against minor defects.

[0055] The prediction output layer is constructed based on the decoder of the RT-DETR model, and is used to map the enhanced fusion features into PCBA solder joint defect detection results carrying defect types and defect locations; a solder joint defect detection model training module, configured to divide the data set into a training set, a validation set, and a test set, train the solder joint defect detection model using the training set and a loss function, validate the trained solder joint defect detection model using the validation set, and test the validated solder joint defect detection model using the test set; A solder joint defect detection model deployment module is used to compress, drift compensate and deploy the solder joint defect detection model that has passed the test; The defect detection module is used to perform PCBA solder point defect detection by using the deployed solder point defect detection model.

[0056] The dataset construction module is specifically used for: A large number of historical PCBA solder joint images with different lighting conditions, shooting angles, and PCBA models are acquired. Each of the historical PCBA solder joint images is preprocessed, including at least cropping, contrast adjustment, exposure adjustment, and size adjustment. The preprocessed historical PCBA solder joint images are labeled with defect types and defect locations using the labelimg annotation tool. A dataset is constructed based on the labeled historical PCBA solder joint images. The defect types include at least normal, kneeling foot, excessive solder, insufficient solder, and continuous solder.

[0057] In the solder joint defect detection model creation module, the loss function formula is: ; in, Represents the loss value of the loss function; represents the defect classification loss; represents the bounding box regression loss; represents the bounding box overlap loss; represents feature consistency loss; 、 、 、 Both represent weight coefficients.

[0058] ; in, represents the number of positive samples (the number of predictions that match the true bounding box); represents the predicted defect category probability vector; Represents the true category one-hot vector; represents the focal loss function; ; in, Represents the predicted normalized bounding box coordinates; represents the real bounding box coordinates; represents the L1 norm; ; ; in, represents the spatial attention map output; Represents the channel attention map output; Represents the input feature tensor (H×W×C); represents the generalized intersection-over-union loss function.

[0059] The loss function combines defect classification loss, bounding box regression loss, bounding box overlap loss, and feature consistency loss. The feature consistency loss aims to constrain the feature representation learned by the model to be consistent (possibly for similar normal or defective samples). This helps improve the model's generalization ability, robustness to noise and small changes, and prevent overfitting, thereby improving actual detection accuracy and stability in complex industrial scenarios.

[0060] The solder joint defect detection model training module is specifically: The data set is divided into a training set, a validation set, and a test set in a ratio of 8:1:1 by a stratified sampling method. Hyperparameters including at least the number of batch training, the optimizer, the learning rate, the weight decay rate, and the training cycle are set. The solder joint defect detection model is trained using the training set and the hyperparameters until the loss value of the loss function is less than a preset loss threshold or the preset early stopping condition is met. The number of batch training is 8; the optimizer uses AdamW; the learning rate is 0.0001; the weight decay rate is 0.0001; and the training cycle is 216 rounds.

[0061] The mean average precision (mAP), gigaflops (GFLOPs), parameters (Params), and frames per second (FPS) are calculated using the validation set to verify the trained solder joint defect detection model. If the verification fails, the training set is expanded to continue training. If the verification passes, then: The confidence level is calculated using the test set to test the verified solder joint defect detection model. If the test fails, the training set is expanded to continue training; if the test passes, the training is terminated.

[0062] The solder joint defect detection model deployment module is specifically used to: The solder joint defect detection model that has passed the test is compressed using quantization technology and dynamic pruning technology, and the performance of the compressed solder joint defect detection model is verified. Actual PCBA solder joint images are collected, and drift compensation training is performed on the performance-verified solder joint defect detection model using each of the actual PCBA solder joint images. The solder joint defect detection model after drift compensation training is deployed using containerization technology.

[0063] The trained model is compressed using quantization techniques and dynamic pruning techniques, which are directly optimized for resource limitations during deployment (such as the computing power and memory of embedded devices), reducing the computational complexity and storage requirements. Containerization technology is adopted for deployment, improving the convenience, portability, maintainability, and resource utilization rate of deployment, conforming to the trend of modern industrial software deployment. After deployment, drift compensation training is performed on the model by collecting actual PCBA solder joint images, which can effectively address the changes that may occur in the actual production environment over time (such as equipment aging, material batch differences, subtle environmental changes, etc.), maintaining the detection accuracy and stability of the model during long-term operation, and solving the key industrial pain point of model "aging".

[0064] By innovatively constructing a feature fusion layer composed of a local feature processing module, a global feature processing module, and a feature interaction output module, combined with designs such as stacked local enhancement units, attention mechanisms, and residual connections, the local perception ability and feature discrimination accuracy of the model for PCBA micro solder joint defects (such as kneeling feet and less solder) are significantly improved. Introducing a quadruple loss function containing feature consistency loss and a diverse dataset construction strategy enhances the robustness and generalization ability of the model in complex industrial scenarios. At the same time, optimizing the structure during the inference stage (such as fusing double branches into a single convolution), adopting quantization pruning compression technology, containerized deployment, and drift compensation training effectively balances detection accuracy and real-time efficiency, and ensures the stability and adaptive ability of the model in long-term industrial applications, especially suitable for high-precision and high-efficiency PCBA solder joint defect detection requirements.

[0065] Compare the present invention with the Faster-RCNN, SSD, Deformable DETR, RT-DETR-R50 detection methods in the prior art, and the comparison results are as follows:

[0066] Among them, mAP 50 Meaning: Select IoU = 0.5, the average precision detection index of the validation set data; mAP 75 Meaning: Select IoU = 0.75, the average precision detection index of the validation set data; mAP 50:95 Meaning: Select 0.5 < IoU < 0.95, the average precision detection index of the validation set data; Params(MB) Meaning: The size of the detection model parameters, in MB as the unit; GFLOPs Meaning: The number of gigafloating-point operations per second performed by the detection model; FPS(f / s) Meaning: The number of frames that can be detected per second.

[0067] From the comparison results, it can be seen that the present invention shows significant performance advantages in the detection task of PCBA multi-type solder joint defects. In terms of accuracy, the present invention in mAP 50 、mAP75 and mAP 50:95 The three indicators reached 79.6%, 79.2% and 63.8% respectively, which are better than the original RT-DETR-R50 and other comparison models, especially the mAP at high IoU thresholds. 75 The optimal performance was achieved, demonstrating a stronger ability to precisely locate complex solder joints. Compared to RT-DETR-R50, this method reduces model parameters from 49.80MB to 45.65MB and GFLOPs from 63.92 to 58.70, while maintaining improved accuracy. This demonstrates higher model efficiency and lower computational resource consumption. Furthermore, the inference speed was slightly improved, reaching 74.09 FPS, further demonstrating the feasibility and practical value of this method in actual industrial inspection applications.

[0068] To further verify the effectiveness of the present invention in improving the ability to focus on solder joint targets, a heatmap visualization analysis of the feature responses on the test images was performed. The original RT-DETR, without the improvements, showed a relatively scattered response area in the heatmap, and some solder joint defects were not effectively activated, reflecting its insufficient attention ability in the small-target solder joint defect detection task. The present invention significantly enhanced the overall response of the solder joint area, with all solder joint regions receiving a response, demonstrating its excellent performance in fusing local details with global semantic features, helping to improve the quality of multi-scale feature expression.

[0069] In summary, the advantages of the present invention are: 1. Build a data set by acquiring a large number of historical PCBA solder joint images; then create a solder joint defect detection model based on the feature extraction layer, feature fusion layer and prediction output layer, and set the loss function of the solder joint defect detection model; divide the data set into training set, validation set and test set, train the solder joint defect detection model through the training set and loss function, verify the trained solder joint defect detection model through the validation set, test the verified solder joint defect detection model through the test set, compress, drift compensate and deploy the tested solder joint defect detection model, and finally perform PCBA solder joint defect detection through the deployed solder joint defect detection model; the feature extraction layer is built based on the backbone network of the RT-DETR model, which is used to extract shallow features and deep features from the input PCBA solder joint image, and input the shallow features and deep features into the feature fusion layer; the feature fusion layer is built based on the local feature processing module, the global feature processing module and the feature interaction output module. It is used to fuse shallow features and deep features to obtain enhanced fusion features and output them to the prediction output layer; the prediction output layer is constructed based on the decoder of the RT-DETR model, which is used to map the enhanced fusion features into PCBA solder joint defect detection results carrying defect types and defect locations; that is, by reconstructing the RepC3 module of the RT-DETR model, replacing the traditional RepC3 module with the feature fusion layer, while retaining the efficient backbone network and decoder of the RT-DETR model to maintain real-time performance, the local feature processing module is used to enhance the perception of small target details, and the attention mechanism of the global feature processing module and the spatial-channel collaborative optimization of the feature interaction output module are combined to effectively bridge the gap between shallow details and deep semantics, and significantly improve the recognition ability of subtle defects in solder joints; at the same time, with the combination of diversified working condition data training, feature consistency loss function constraints and model compression deployment technology, it is finally achieved while meeting the real-time detection requirements and greatly improving the accuracy of PCBA solder joint defect detection.

[0070] 2. The feature fusion layer adopts a unique three-level structure of "local feature processing module + global feature processing module + feature interaction output module", with clear hierarchy and division of labor, which can more effectively integrate feature information of different scales and semantic levels.

[0071] 3. Two stacked local enhancement sub-units enhance the model's perception and nonlinear modeling capabilities for local micro-areas (such as solder joint defects), which is crucial for identifying small solder joint defects (such as kneeling feet and insufficient solder). In the inference stage, the dual-branch structure is fused into a single 3x3 convolutional layer, which significantly improves the inference speed (reduces the amount of computation) while maintaining the enhancement capability during training, which is beneficial for industrial deployment. The enhanced features are residually connected with the original shallow features (containing detailed information) and deep features (containing semantic information), effectively fusing information at different levels of abstraction, so that the local features contain both detailed and semantic information.

[0072] 4. Use global average pooling, maximum pooling and Softmax to generate fused attention features, which can focus on more important areas in the image; through independent channel space mapping and spatial compression operations, feature information of different dimensions can be extracted and refined respectively.

[0073] 5. Perform matrix multiplication on the fused attention features and the channel spatial mapping features to obtain spatial enhancement features, and perform matrix multiplication on the channel spatial mapping features and the spatial compression features to obtain channel enhancement features. This interactive method can better capture the complex relationship between features than simple splicing or addition; further convert the spatial enhancement and channel enhancement features into spatial attention maps and channel attention maps, and perform deep fusion through element-by-element multiplication to form initial fusion features; finally, the initial fusion features after deep interactive fusion are residually connected with the original local features, which not only retains the original information but also incorporates highly refined global perception information. The final output "enhanced fusion features" have a stronger ability to discriminate against minor defects.

[0074] 6. The loss function combines defect classification loss, bounding box regression loss, bounding box overlap loss, and feature consistency loss. The feature consistency loss aims to constrain the feature representation learned by the model to be consistent (possibly for similar normal or defective samples). This helps improve the model's generalization ability, robustness to noise and small changes, and prevent overfitting, thereby improving actual detection accuracy and stability in complex industrial scenarios.

[0075] 7. By collecting images with different lighting conditions, different shooting angles, and different PCBA models, and performing pre-processing such as cropping, contrast / exposure / size adjustment, this greatly enhances the diversity and coverage of the dataset, which is the basis for the model to have strong generalization capabilities; using stratified sampling (8:1:1) to divide the training / validation / test sets helps ensure the representativeness of the data distribution and more objectively evaluate model performance; the verification phase focuses not only on accuracy indicators (such as mean average precision (mAP)), but also on efficiency indicators (thousand frames per second (FPS), giga floating-point operations per second (GFLOPS)) and model size (number of parameters) to ensure that the model meets actual deployment requirements.

[0076] 8. Use quantization and dynamic pruning techniques to compress the trained model, directly optimizing for resource constraints during deployment (such as computing power and memory of embedded devices), reducing computational complexity and storage requirements. Use containerization technology for deployment, which improves deployment convenience, portability, maintainability, and resource utilization, in line with modern industrial software deployment trends. After deployment, the model is trained for drift compensation by collecting actual PCBA solder joint images, effectively coping with changes in the actual production environment that may occur over time (such as equipment aging, material batch differences, subtle environmental changes, etc.), maintaining the model's detection accuracy and stability during long-term operation, and solving the key industrial pain point of model "aging."

[0077] 9. By innovatively constructing a feature fusion layer consisting of a local feature processing module, a global feature processing module, and a feature interaction output module, combined with designs such as stacked local enhancement units, attention mechanisms, and residual connections, the model's local perception ability and feature discrimination accuracy for minor PCBA solder joint defects (such as kneeling feet and insufficient solder) are significantly improved; the introduction of a four-element loss function containing feature consistency loss and a diversified dataset construction strategy enhances the robustness and generalization of the model in complex industrial scenarios; at the same time, by optimizing the structure in the inference stage (such as fusing two branches into a single convolution), adopting quantized pruning and compression technology, containerized deployment, and drift compensation training, it effectively balances detection accuracy and real-time efficiency, and ensures the stability and adaptability of the model in long-term industrial applications, making it particularly suitable for high-precision and high-efficiency PCBA solder joint defect detection needs.

[0078] Although the specific embodiments of the present invention are described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included within the scope of protection of the claims of the present invention.

Claims

1. A PCBA solder joint defect detection method based on improved RT-DETR, characterized by: The steps include: Step S1: Acquire a large number of historical PCBA solder joint images, pre-process and annotate each of the historical PCBA solder joint images, and then construct a data set; Step S2: creating a solder joint defect detection model based on the feature extraction layer, the feature fusion layer, and the prediction output layer, and setting a loss function of the solder joint defect detection model; Step S3, dividing the data set into a training set, a validation set, and a test set, training a solder joint defect detection model using the training set and a loss function, validating the trained solder joint defect detection model using the validation set, and testing the validated solder joint defect detection model using the test set; Step S4: compressing, drift compensation training, and deploying the solder joint defect detection model that has passed the test; Step S5: Perform PCBA solder point defect detection using the deployed solder point defect detection model.

2. A PCBA solder joint defect detection method based on improved RT-DETR according to claim 1, characterized in that: The step S1 is specifically as follows: A large number of historical PCBA solder joint images with different lighting conditions, shooting angles, and PCBA models are acquired. Each of the historical PCBA solder joint images is preprocessed, including at least cropping, contrast adjustment, exposure adjustment, and size adjustment. The preprocessed historical PCBA solder joint images are labeled with defect types and defect locations using the labelimg annotation tool. A dataset is constructed based on the labeled historical PCBA solder joint images. The defect types include at least normal, kneeling foot, excessive solder, insufficient solder, and continuous solder.

3. A PCBA solder joint defect detection method based on improved RT-DETR as claimed in claim 1, characterized in that: In step S2, the feature extraction layer is constructed based on the backbone network of the RT-DETR model, and is used to extract shallow features and deep features from the input PCBA solder joint image, and input the shallow features and deep features into the feature fusion layer; The feature fusion layer is constructed based on the local feature processing module, the global feature processing module and the feature interaction output module; The local feature processing module is constructed based on an input channel adjustment unit, a local enhancement unit, a structure optimization unit, and a residual connection unit; the input channel adjustment unit is used to perform channel compression and preliminary feature extraction on the input shallow features and deep features through a 1x1 first convolution normalization activation layer to obtain initial features; The local enhancement unit is used to enhance the local perception capability of the initial feature and introduce nonlinear transformation through two stacked local enhancement sub-units to obtain enhanced initial features; The structure optimization unit is used to fuse the two-branch structures of the two local enhancement sub-units into a single 3x3 convolutional layer during the inference phase; the residual connection unit is used to fuse the enhanced initial features, shallow features, and deep features to obtain local features, and input the local features into the global feature processing module; The global feature processing module is constructed based on an attention generation unit, a channel space mapping unit, and a spatial compression unit; the attention generation unit is used to fuse the local features through global average pooling, global maximum pooling, and a Softmax function to obtain a fused attention feature; the channel space mapping unit is used to perform spatial mapping on the local features through a 1x1 second convolution normalized activation layer to obtain a channel space mapping feature; the spatial compression unit is used to perform spatial compression on the local features through a 1x1 third convolution normalized activation layer to obtain a spatial compression feature; The feature interaction output module is used to perform a matrix multiplication operation on the fusion attention feature and the channel space mapping feature to obtain a spatial enhancement feature, perform a matrix multiplication operation on the channel space mapping feature and the spatial compression feature to obtain a channel enhancement feature, input the spatial enhancement feature into the 1x1 fourth convolution normalized activation layer to obtain a spatial attention map, and input the channel enhancement feature into the unnormalized convolution activation layer to obtain a channel attention map; Performing element-by-element multiplication on the spatial attention map and the channel attention map to obtain an initial fusion feature, performing a residual connection on the initial fusion feature and the local feature to obtain an enhanced fusion feature and output it to the prediction output layer; The prediction output layer is constructed based on the decoder of the RT-DETR model, and is used to map the enhanced fusion features into PCBA solder joint defect detection results carrying defect types and defect locations; The formula of the loss function is: ; in, Represents the loss value of the loss function; represents the defect classification loss; represents the bounding box regression loss; represents the bounding box overlap loss; represents feature consistency loss; 、 、 、 Both represent weight coefficients.

4. A PCBA solder joint defect detection method based on improved RT-DETR as claimed in claim 1, characterized in that: The step S3 is specifically as follows: Dividing the data set into a training set, a validation set, and a test set in a ratio of 8:1:1 using a stratified sampling method, setting hyperparameters including at least a batch size, an optimizer, a learning rate, a weight decay rate, and a training cycle, and training a solder joint defect detection model using the training set and the hyperparameters until a loss value of the loss function is less than a preset loss threshold or a preset early stopping condition is met; The average precision mean, Giga floating point operations per second, parameter count, and frames per second are calculated using the validation set to verify the trained solder joint defect detection model. If the verification fails, the training set is expanded to continue training. If the verification passes, then: The confidence level is calculated using the test set to test the verified solder joint defect detection model. If the test fails, the training set is expanded to continue training; if the test passes, the training is terminated.

5. The PCBA solder joint defect detection method based on improved RT-DETR according to claim 1, characterized in that: The step S4 is specifically as follows: The solder joint defect detection model that has passed the test is compressed using quantization technology and dynamic pruning technology, and the performance of the compressed solder joint defect detection model is verified. Actual PCBA solder joint images are collected, and drift compensation training is performed on the performance-verified solder joint defect detection model using each of the actual PCBA solder joint images. The solder joint defect detection model after drift compensation training is deployed using containerization technology.

6. A PCBA solder joint defect detection system based on improved RT-DETR, characterized by: Includes the following modules: A data set construction module is used to obtain a large number of historical PCBA solder joint images, pre-process and annotate each of the historical PCBA solder joint images, and then construct a data set; A solder joint defect detection model creation module is used to create a solder joint defect detection model based on the feature extraction layer, the feature fusion layer and the prediction output layer, and set the loss function of the solder joint defect detection model; a solder joint defect detection model training module, configured to divide the data set into a training set, a validation set, and a test set, train the solder joint defect detection model using the training set and a loss function, validate the trained solder joint defect detection model using the validation set, and test the validated solder joint defect detection model using the test set; A solder joint defect detection model deployment module is used to compress, drift compensate and deploy the solder joint defect detection model that has passed the test; The defect detection module is used to perform PCBA solder point defect detection by using the deployed solder point defect detection model.

7. A PCBA solder joint defect detection system based on improved RT-DETR according to claim 6, characterized in that: The dataset construction module is specifically used for: A large number of historical PCBA solder joint images with different lighting conditions, shooting angles, and PCBA models are acquired. Each of the historical PCBA solder joint images is preprocessed, including at least cropping, contrast adjustment, exposure adjustment, and size adjustment. The preprocessed historical PCBA solder joint images are labeled with defect types and defect locations using the labelimg annotation tool. A dataset is constructed based on the labeled historical PCBA solder joint images. The defect types include at least normal, kneeling foot, excessive solder, insufficient solder, and continuous solder.

8. The PCBA solder joint defect detection system based on improved RT-DETR according to claim 6, characterized in that: In the solder joint defect detection model creation module, the feature extraction layer is constructed based on the backbone network of the RT-DETR model, and is used to extract shallow features and deep features from the input PCBA solder joint image, and input the shallow features and deep features into the feature fusion layer; The feature fusion layer is constructed based on the local feature processing module, the global feature processing module and the feature interaction output module; The local feature processing module is constructed based on an input channel adjustment unit, a local enhancement unit, a structure optimization unit, and a residual connection unit; the input channel adjustment unit is used to perform channel compression and preliminary feature extraction on the input shallow features and deep features through a 1x1 first convolution normalization activation layer to obtain initial features; The local enhancement unit is used to enhance the local perception capability of the initial feature and introduce nonlinear transformation through two stacked local enhancement sub-units to obtain enhanced initial features; The structure optimization unit is used to fuse the two-branch structures of the two local enhancement sub-units into a single 3x3 convolutional layer during the inference phase; the residual connection unit is used to fuse the enhanced initial features, shallow features, and deep features to obtain local features, and input the local features into the global feature processing module; The global feature processing module is constructed based on an attention generation unit, a channel space mapping unit, and a spatial compression unit; the attention generation unit is used to fuse the local features through global average pooling, global maximum pooling, and a Softmax function to obtain a fused attention feature; the channel space mapping unit is used to perform spatial mapping on the local features through a 1x1 second convolution normalized activation layer to obtain a channel space mapping feature; the spatial compression unit is used to perform spatial compression on the local features through a 1x1 third convolution normalized activation layer to obtain a spatial compression feature; The feature interaction output module is used to perform a matrix multiplication operation on the fusion attention feature and the channel space mapping feature to obtain a spatial enhancement feature, perform a matrix multiplication operation on the channel space mapping feature and the spatial compression feature to obtain a channel enhancement feature, input the spatial enhancement feature into the 1x1 fourth convolution normalized activation layer to obtain a spatial attention map, and input the channel enhancement feature into the unnormalized convolution activation layer to obtain a channel attention map; Performing element-by-element multiplication on the spatial attention map and the channel attention map to obtain an initial fusion feature, performing a residual connection on the initial fusion feature and the local feature to obtain an enhanced fusion feature and output it to the prediction output layer; The prediction output layer is constructed based on the decoder of the RT-DETR model, and is used to map the enhanced fusion features into PCBA solder joint defect detection results carrying defect types and defect locations; The formula of the loss function is: ; in, Represents the loss value of the loss function; represents the defect classification loss; represents the bounding box regression loss; represents the bounding box overlap loss; represents feature consistency loss; 、 、 、 Both represent weight coefficients.

9. The PCBA solder joint defect detection system based on improved RT-DETR according to claim 6, characterized in that: The solder joint defect detection model training module is specifically: Dividing the data set into a training set, a validation set, and a test set in a ratio of 8:1:1 using a stratified sampling method, setting hyperparameters including at least a batch size, an optimizer, a learning rate, a weight decay rate, and a training cycle, and training a solder joint defect detection model using the training set and the hyperparameters until a loss value of the loss function is less than a preset loss threshold or a preset early stopping condition is met; The average precision mean, Giga floating point operations per second, parameter count, and frames per second are calculated using the validation set to verify the trained solder joint defect detection model. If the verification fails, the training set is expanded to continue training. If the verification passes, then: The confidence level is calculated using the test set to test the verified solder joint defect detection model. If the test fails, the training set is expanded to continue training; if the test passes, the training is terminated.

10. The PCBA solder joint defect detection system based on improved RT-DETR according to claim 6, characterized in that: The solder joint defect detection model deployment module is specifically used to: The solder joint defect detection model that has passed the test is compressed using quantization technology and dynamic pruning technology, and the performance of the compressed solder joint defect detection model is verified. Actual PCBA solder joint images are collected, and drift compensation training is performed on the performance-verified solder joint defect detection model using each of the actual PCBA solder joint images. The solder joint defect detection model after drift compensation training is deployed using containerization technology.

Citation Information

Patent Citations

  • PCB defect detection method based on small target enhanced feature pyramid

    CN119785175A

  • Surface defect detection method for multi-scale and small target features

    CN119810522A

  • Subway track defect detection method based on improved RT-DETR

    CN120279506A

  • Deep-learning-based target detection method for defects of image of inner side of commutator

    WO2024208102A1

Cited By

  • YOLOv5-based Cuiguan pear surface defect detection method and system

    CN121482777A

  • PCB through hole welding spot defect detection method based on improved RT-DETR

    CN122199552A