Printed circuit board defect detection method based on double-branch gating fusion network

By employing a dual-branch backbone network, multi-scale gated attention fusion, polarized multi-mechanism encoders, and weighted frequency downsampling technology, the detection accuracy and efficiency of PCB defect detection are improved, solving the problem of insufficient detection accuracy and efficiency in existing technologies and adapting to PCB defect detection at different scales.

CN122156093APending Publication Date: 2026-06-05SHANGHAI UNIV OF ENG SCI

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANGHAI UNIV OF ENG SCI
Filing Date
2026-02-10
Publication Date
2026-06-05

Smart Images

  • Figure CN122156093A_ABST
    Figure CN122156093A_ABST
Patent Text Reader

Abstract

The present application relates to a printed circuit board defect detection method based on a double-branch gating fusion network, and relates to the technical field of computer vision, and the present application aims at the problems in the prior art that a single main network is difficult to simultaneously consider the calculation efficiency and the feature expression ability, a fixed fusion strategy cannot adaptively adjust the multi-scale feature weight, the encoder feature interaction ability is limited, the receptive field expansion is insufficient, and the information loss in the down-sampling process, etc., through the synergistic effect of Stem shared double-branch main network, multi-scale gating attention fusion, polarized multi-mechanism encoder, expanded reparameterization neck network and weighted frequency down-sampling, efficient and accurate PCB defect detection is realized, the detection precision and the generalization ability of the model are improved while the calculation efficiency is maintained, thereby solving the challenges faced by the prior art, and a PCB defect detection method with efficient structure, flexible fusion, good real-time performance and accuracy is proposed to cope with the complex and changeable defect detection requirements in the industrial production line.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer vision technology, and in particular to a method for detecting defects in printed circuit boards based on a dual-branch gated fusion network. Background Technology

[0002] In modern electronics manufacturing, printed circuit boards (PCBs) are the core components of electronic devices. PCB defect detection is a crucial step in ensuring product quality and reliability. Traditional PCB defect detection mainly relies on manual visual inspection and optical inspection (AOI) equipment. However, as electronic products develop towards higher density and miniaturization, the types of defects are becoming increasingly diverse, and traditional methods face problems such as low detection accuracy, low efficiency, and high labor costs.

[0003] With the rapid development of deep learning technology, object detection algorithms based on convolutional neural networks (CNNs) have been widely used in the field of PCB defect detection. Existing methods are mainly divided into two categories: one is a single-stage detector based on the YOLO series, characterized by fast detection speed but relatively low accuracy; the other is a two-stage detector based on Faster R-CNN, which has higher accuracy but slower inference speed. In recent years, DETR (DEtection Transformer) has been proposed as an end-to-end object detection framework based on Transformer. It achieves global feature modeling through an attention mechanism and has achieved excellent performance on multiple detection tasks.

[0004] RT-DETR (Real-Time Detection Transformer) is a real-time improvement version of the DETR series proposed by Baidu in 2023. It uses ResNet, CSPDarkNet, or HGNetv2 as the backbone network (e.g., ResNet-18 outputs feature maps C3, C4, and C5 with strides of 8, 16, and 32 through four residual stages) for feature extraction. The core consists of a backbone network, a hybrid encoder, and a decoder. The hybrid encoder includes an AIFI module (multi-head self-attention for single-scale feature interaction) and a CCFM module (cross-scale fusion of multi-level information). The decoder uses a standard Transformer structure, combining learnable target queries with encoder features for cross-attention calculation, ultimately generating detection boxes and category predictions. By optimizing the encoder structure and achieving efficient feature extraction, it significantly improves inference speed while maintaining accuracy, becoming one of the representative methods in the field of PCB defect detection. In recent years, numerous studies have explored the application of RT-DETR in PCB defect detection. Some works directly fine-tune pre-trained RT-DETR models on PCB datasets, focusing primarily on optimizing training strategies and data augmentation methods without modifying the model structure. Other studies attempt to replace or enhance the RT-DETR backbone network, for example, by using lightweight MobileNetV3 to reduce the number of model parameters or introducing a pyramid visual transformer (PVT) to improve the detection capability for small-sized defects. Addressing the diverse nature of PCB defects, some works introduce additional attention mechanisms, such as channel attention modules (SE-Net) or spatial attention mechanisms, on top of the AIFI module to enhance the response to key features and defect locations. Still other studies focus on improving the feature pyramid structure, proposing enhanced feature pyramid networks that enhance multi-scale feature fusion through bidirectional feature flow or adaptive feature aggregation modules.

[0005] The aforementioned research has enabled RT-DETR-based PCB defect detection technology to achieve good detection results on multiple public datasets. Directly applying the RT-DETR model and combining it with appropriate training strategies can achieve high detection accuracy. Introducing a lightweight backbone network or an enhanced feature pyramid structure can significantly improve inference speed while maintaining detection accuracy. The use of a multi-head self-attention mechanism and a cross-scale feature fusion encoder design enhances the model's ability to detect PCB defects at different scales. The application of an end-to-end training paradigm and ensemble prediction loss function simplifies the post-processing workflow and improves detection efficiency. These technical solutions have demonstrated good real-time performance and accuracy in practical PCB production line applications, providing effective technical support for industrial defect detection.

[0006] While existing RT-DETR-based PCB defect detection technologies have achieved some success, they still suffer from the following shortcomings in practical applications: Existing technologies often employ a single backbone network for feature extraction. Lightweight networks offer high computational efficiency but have limited feature representation capabilities, while deep networks offer rich features but suffer from high computational cost and slow inference speed, making it difficult to simultaneously balance efficiency and performance. Multi-scale feature fusion uses fixed fusion strategies such as FPN or PANet, failing to dynamically adjust the weights of information at each scale based on specific defect features. Furthermore, features at different levels differ in spatial resolution and semantic level, and simple concatenation or addition can easily lead to feature misalignment. The AIFI module attention mechanism of the encoder is relatively simple, making it difficult to simultaneously capture local details and global context. It lacks explicit modeling of channel dimensions, and the nonlinear transformation capability of the feedforward network is limited. The neck network of the feature pyramid often uses standard 3×3 convolutions, and the fixed receptive field limits its adaptability to defects of different sizes. It lacks multi-scale receptive field design and parameter reuse mechanisms. Downsampling uses max pooling, average pooling, or stride convolutions to uniformly process all positions and channels, failing to adaptively preserve important features and neglecting the role of frequency domain information in capturing texture and edge details. To address the aforementioned technical deficiencies, a solution is proposed. Summary of the Invention

[0007] The purpose of this invention is to achieve efficient and accurate PCB defect detection through the synergistic effect of technologies such as Stem shared dual-branch backbone network, multi-scale gated attention fusion, polarization multi-mechanism encoder, extended reparameterized neck network, and weighted frequency downsampling.

[0008] To achieve the above objectives, the present invention adopts the following technical solution: a printed circuit board defect detection method based on a dual-branch gated fusion network, comprising the following steps: S1. HGStem is used as a shared Stem module to perform preliminary feature extraction on the input image. Basic features are efficiently extracted in the shallow network through convolutional layers and downsampling operations. The two branches share the output of the Stem module, avoiding repeated computation of the same shallow features and significantly reducing computational redundancy. Two parallel branches are constructed from the Stem output, including a lightweight branch and an enhanced branch. The lightweight branch uses a C2f module to achieve effective feature extraction while maintaining low computational complexity through cross-layer connections and bottleneck structures. The lightweight design has 64, 128, and 256 output channels at the P3, P4, and P5 levels, respectively. The enhancement branch uses the HGBlock module, which significantly improves feature representation capabilities by moderately increasing computational cost through hierarchical convolutional structures and residual connections. The enhancement branch repeats HGBlock 3 times at the P3 level, 3 times at the P4 level, and 1 time at the P5 level. The output channel corresponds to the lightweight branch. The lightweight branch and the enhancement branch complement each other. The lightweight branch ensures inference speed, while the enhancement branch ensures detection accuracy. S2. Construct a polarization multi-mechanism encoder layer and integrate four complementary mechanisms to achieve powerful feature interaction capabilities.

[0009] S3. In the feature pyramid neck network, the dilated reparameterized C3 module is used to replace the traditional RepC3 module. The dilated reparameterized C3 module adopts a multi-branch parallel structure, and each branch uses convolutional kernels with different dilation rates, so as to obtain receptive fields of different sizes with the same number of parameters. Among them, the small dilation rate focuses on local detailed features and is suitable for detecting small-sized defects, while the large dilation rate obtains a wider range of contextual information and is suitable for detecting large-sized defects, so that the model can adapt to PCB defects of different sizes at the same time. S4. In the downsampling process of the feature pyramid, weighted frequency convolution wConv2d is used instead of traditional stride convolution. By using frequency domain weighting, key information is preserved to the maximum extent while reducing the resolution of the feature map. S5. Using Wise-Focaler-ShapeIoU as the bounding box regression loss function, the following improvements are achieved: The shape-aware mechanism is used to consider the overlapping area of ​​bounding boxes while focusing on the shape similarity of the bounding boxes. By calculating the aspect ratio and scale difference, it guides the model to learn a more accurate bounding box shape. The focus strategy is used to assign higher weights to samples that are difficult to regress, thereby improving the detection capability of small targets and occluded targets; The intelligent weighting mechanism dynamically adjusts the loss weights based on the target's size and aspect ratio, employing differentiated optimization strategies for targets with different characteristics. Focal Loss is used for classification to address the foreground-background class imbalance, and the overall loss function is a weighted combination of the classification loss and the bounding box regression loss.

[0010] Furthermore, the specific process in S1 is as follows: S11. Multi-scale gated attention fusion modules are introduced at the three feature levels of P3 (stride=8), P4 (stride=16), and P5 (stride=32). If the number of channels of the lightweight branch and the enhanced branch are different, they are adjusted to the same dimension by 1×1 convolution. Then, the features of the two branches are processed at multiple scales by the multi-scale gated attention fusion module. The multi-scale gated attention fusion module uses convolution kernels of different sizes (1×1, 3×3, 5×5) to extract features in parallel and capture multi-level information from local details to global context. S12. Generate a dual-channel attention map by passing the multi-scale fused features through a 1×1 convolutional layer, and then generate the weights A and B of the two branches through Softmax normalization, where x is the lightweight branch feature and g is the enhanced branch feature: S13. Apply attention weights to the two branch features, perform weighted modulation, and add a residual connection: S14. Achieve bidirectional information exchange of dual-branch features through Sigmoid gating: S15. The interactive features are activated by a projection layer and a Sigmoid function, multiplied with the original lightweight branch features, and then output as the final fused features after convolutional blocks and batch normalization.

[0011] By applying this fusion strategy at three levels, the model can achieve effective feature fusion at different levels of semantic abstraction, preserving fine-grained local details while capturing high-level global semantic information.

[0012] Furthermore, the processing flow of the encoder layer in S2 is as follows: S21. The input features are processed by polarized linear attention and then passed through residual connections and Dropout; then they are processed by the first dynamic Tanh activation and Mona normalization module. S22, processed by an enhanced dynamic feedforward network and through residual connections and Dropout; S23. After passing through the dynamic Tanh activation and Mona normalization modules again, the final features are output. The entire process can be represented as follows: .

[0013] Furthermore, the specific process in S3 is as follows: During the training phase, multiple dilated convolutional branches independently learn feature representations and optimize their parameters through gradient backpropagation, thereby enhancing the model's expressive power. The inference phase employs reparameterization, linearly combining the weights of multiple dilated convolutions into a single, larger convolutional kernel, achieving efficient inference without sacrificing expressive power. This multi-branch training and single-branch inference strategy balances performance and efficiency. In the neck network, DRBC3 is applied to the post-feature fusion processing. Each DRBC3 module is repeated three times, with a scaling factor of 0.5 and a uniform output channel count of 256, ensuring effective processing and transmission of features at each level of the feature pyramid.

[0014] Furthermore, the specific process in S4 is as follows: S41. The core of wConv2d is to construct a frequency domain weighting matrix Φ. Given a density parameter α=0.9, a frequency weight vector is constructed, and then a two-dimensional weighting matrix is ​​generated through outer product. The size of the two-dimensional weighting matrix is ​​the same as the size of the convolution kernel (3×3). S42. Frequency domain modulation is achieved by element-wise weighting of the convolution kernel weights, where W is the original convolution kernel weights. The weights after frequency domain weighting: S43. Through frequency domain weighting, high-frequency components are given higher weights, while redundant low-frequency information is appropriately suppressed. This adaptive weighting mechanism allows the downsampling process to selectively retain the most important feature information, avoiding the loss of key information caused by traditional downsampling methods. In the network, wConv2d is applied to the downsampling operation of the neck network (stride=2), with 256 output channels, ensuring the continuity and integrity of detailed information throughout the feature stream.

[0015] Furthermore, the specific process in S5 is as follows: Training is conducted end-to-end without post-processing steps. The optimizer is AdamW, the initial learning rate is set to 1e-4, and a cosine annealing learning rate scheduling strategy is used. The total number of training epochs is 150, and the batch size is set to 4. A warmup strategy was adopted, with the learning rate increasing linearly over the first 10 epochs; A multi-scale training strategy is adopted during the training process, in which the size of the input image is randomly varied within a certain range to enhance the robustness of the model to inputs of different scales.

[0016] Model evaluation uses mean accuracy as the main indicator, including mAP@0.5 and mAP@0.5:0.95. It also evaluates inference speed, number of model parameters and computational cost to comprehensively measure the model's performance in detection accuracy, inference efficiency and model complexity.

[0017] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are: This printed circuit board (PCB) defect detection method based on a dual-branch gated fusion network addresses the challenges of existing technologies, such as the difficulty of a single backbone network in simultaneously balancing computational efficiency and feature representation capabilities, the inability of fixed fusion strategies to adaptively adjust multi-scale feature weights, limited encoder feature interaction capabilities, insufficient receptive field expansion, and information loss during downsampling. By leveraging the synergistic effects of Stem-shared dual-branch backbone network, multi-scale gated attention fusion, polarization multi-mechanism encoder, extended reparameterized neck network, and weighted frequency downsampling, this method achieves efficient and accurate PCB defect detection. It maintains computational efficiency while improving the model's detection accuracy and generalization ability, thus solving the challenges faced by existing technologies. This method proposes a structurally efficient, flexible, and real-time-efficient PCB defect detection approach to meet the complex and ever-changing defect detection needs of industrial production lines. Attached Figure Description

[0018] Figure 1 A schematic diagram of the overall structure of the present invention is shown; Figure 2 A schematic diagram of the RT-DETR network structure of the present invention is shown; Figure 3 A schematic diagram of the DGFN-DETR network structure of the present invention is shown; Figure 4 A schematic diagram of the polarization multi-mechanism encoder of the present invention is shown. Detailed Implementation

[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0020] Example: like Figures 1-4 As shown, the printed circuit board defect detection method based on a dual-branch gated fusion network includes the following steps: S1. HGStem is used as a shared Stem module to perform preliminary feature extraction on the input image. Basic features are efficiently extracted in the shallow network through convolutional layers and downsampling operations. The two branches share the output of the Stem module, avoiding repeated computation of the same shallow features and significantly reducing computational redundancy. Two parallel branches are constructed from the Stem output, including a lightweight branch and an enhanced branch. The lightweight branch uses a C2f module to achieve effective feature extraction while maintaining low computational complexity through cross-layer connections and bottleneck structures. The lightweight design has 64, 128, and 256 output channels at the P3, P4, and P5 levels, respectively. The enhancement branch uses the HGBlock module, which significantly improves feature representation capabilities by moderately increasing computational cost through hierarchical convolutional structures and residual connections. The enhancement branch repeats HGBlock 3 times at the P3 level, 3 times at the P4 level, and 1 time at the P5 level. The output channel corresponds to the lightweight branch. The lightweight branch and the enhancement branch complement each other. The lightweight branch ensures inference speed, while the enhancement branch ensures detection accuracy. The specific process in S1 is as follows: S11. Multi-scale gated attention fusion modules are introduced at the three feature levels of P3 (stride=8), P4 (stride=16), and P5 (stride=32). If the number of channels of the lightweight branch and the enhanced branch are different, they are adjusted to the same dimension by 1×1 convolution. Then, the features of the two branches are processed at multiple scales by the multi-scale gated attention fusion module. The multi-scale gated attention fusion module uses convolution kernels of different sizes (1×1, 3×3, 5×5) to extract features in parallel and capture multi-level information from local details to global context. S12. Generate a dual-channel attention map by passing the multi-scale fused features through a 1×1 convolutional layer, and then generate the weights A and B of the two branches through Softmax normalization, where x is the lightweight branch feature and g is the enhanced branch feature: S13. Apply attention weights to the two branch features, perform weighted modulation, and add a residual connection: S14. Achieve bidirectional information exchange of dual-branch features through Sigmoid gating: S15. The interactive features are activated by a projection layer and a Sigmoid function, multiplied with the original lightweight branch features, and then output as the final fused features after convolutional blocks and batch normalization.

[0021] By applying this fusion strategy at three levels, the model can achieve effective feature fusion at different levels of semantic abstraction, preserving fine-grained local details while capturing high-level global semantic information.

[0022] S2. Construct a polarization multi-mechanism encoder layer and integrate four complementary mechanisms to achieve powerful feature interaction capabilities.

[0023] The processing flow of the encoder layer in S2 is as follows: S21. The input features are processed by polarized linear attention and then passed through residual connections and Dropout; then they are processed by the first dynamic Tanh activation and Mona normalization module. S22, processed by an enhanced dynamic feedforward network and through residual connections and Dropout; S23. After passing through the dynamic Tanh activation and Mona normalization modules again, the final features are output. The entire process can be represented as follows: The polarized linear attention mechanism decomposes multi-head self-attention into two parallel branches: channel polarized attention and spatial polarized attention. Channel polarized attention adaptively adjusts the importance weights of each channel through channel-dimensional self-attention calculation, while spatial polarized attention captures global context information through spatial-dimensional self-attention calculation. The two branches are combined through a gating fusion mechanism, which significantly reduces computational complexity compared to traditional attention.

[0024] The EDFFN module achieves parameter-efficient nonlinear feature transformation through dynamic convolution and gated linear units. First, it expands the receptive field of features by dilating convolutional layers (by a factor of 2.0), then uses gated linear units for selective information transmission, achieving adaptive feature selection and effectively suppressing noise and redundant information. The Mona module designs an adaptive normalization strategy to address the statistical differences in features at different scales. It groups input features into multiple scales, each group using independent normalization parameters. An attention mechanism learns the relative importance of different groups, maintaining the uniqueness and complementarity of features at each scale. DynamicTanh replaces the traditional normalization layer, dynamically adjusting the nonlinear transformation curve based on the statistical characteristics of the input features through learnable scaling and offset parameters, enabling the network to learn the activation mode best suited for the current task. Through the synergistic effect of these four mechanisms, PME-Layer can achieve multi-dimensional and multi-layered feature enhancement within a single encoder layer, significantly improving the encoder's feature interaction and expressive capabilities.

[0025] S3. In the feature pyramid neck network, the dilated reparameterized C3 module is used to replace the traditional RepC3 module. The dilated reparameterized C3 module adopts a multi-branch parallel structure, and each branch uses convolutional kernels with different dilation rates, so as to obtain receptive fields of different sizes with the same number of parameters. Among them, the small dilation rate focuses on local detailed features and is suitable for detecting small-sized defects, while the large dilation rate obtains a wider range of contextual information and is suitable for detecting large-sized defects, so that the model can adapt to PCB defects of different sizes at the same time. The specific process in S3 is as follows: During the training phase, multiple dilated convolutional branches independently learn feature representations and optimize their parameters through gradient backpropagation, thereby enhancing the model's expressive power. The inference phase employs reparameterization, linearly combining the weights of multiple dilated convolutions into a single, larger convolutional kernel, achieving efficient inference without sacrificing expressive power. This multi-branch training and single-branch inference strategy balances performance and efficiency. In the neck network, DRBC3 is applied to the post-feature fusion processing. Each DRBC3 module is repeated three times, with a scaling factor of 0.5 and a uniform output channel count of 256, ensuring effective processing and transmission of features at each level of the feature pyramid.

[0026] S4. In the downsampling process of the feature pyramid, weighted frequency convolution wConv2d is used instead of traditional stride convolution. By using frequency domain weighting, key information is preserved to the maximum extent while reducing the resolution of the feature map. The specific process in S4 is as follows: S41. The core of wConv2d is to construct a frequency domain weighting matrix Φ. Given a density parameter α=0.9, a frequency weight vector is constructed, and then a two-dimensional weighting matrix is ​​generated through outer product. The size of the two-dimensional weighting matrix is ​​the same as the size of the convolution kernel (3×3). S42. Frequency domain modulation is achieved by element-wise weighting of the convolution kernel weights, where W is the original convolution kernel weights. The weights after frequency domain weighting: S43. Through frequency domain weighting, high-frequency components are given higher weights, while redundant low-frequency information is appropriately suppressed. This adaptive weighting mechanism allows the downsampling process to selectively retain the most important feature information, avoiding the loss of key information caused by traditional downsampling methods. In the network, wConv2d is applied to the downsampling operation of the neck network (stride=2), with 256 output channels, ensuring the continuity and integrity of detailed information throughout the feature stream.

[0027] S5. Using Wise-Focaler-ShapeIoU as the bounding box regression loss function, the following improvements are achieved: The shape-aware mechanism is used to consider the overlapping area of ​​bounding boxes while focusing on the shape similarity of the bounding boxes. By calculating the aspect ratio and scale difference, it guides the model to learn a more accurate bounding box shape. The focus strategy is used to assign higher weights to samples that are difficult to regress, thereby improving the detection capability of small targets and occluded targets; The intelligent weighting mechanism dynamically adjusts the loss weights based on the target's size and aspect ratio, employing differentiated optimization strategies for targets with different characteristics. Focal Loss is used for classification to address the foreground-background class imbalance, and the overall loss function is a weighted combination of the classification loss and the bounding box regression loss.

[0028] The specific process in S5 is as follows: Training is conducted end-to-end without post-processing steps. The optimizer is AdamW, the initial learning rate is set to 1e-4, and a cosine annealing learning rate scheduling strategy is used. The total number of training epochs is 150, and the batch size is set to 4. A warmup strategy was adopted, with the learning rate increasing linearly over the first 10 epochs; A multi-scale training strategy is adopted during the training process, in which the size of the input image is randomly varied within a certain range to enhance the robustness of the model to inputs of different scales.

[0029] Model evaluation uses mean accuracy as the main indicator, including mAP@0.5 and mAP@0.5:0.95. It also evaluates inference speed, number of model parameters and computational cost to comprehensively measure the model's performance in detection accuracy, inference efficiency and model complexity.

Claims

1. A method for detecting defects in printed circuit boards based on a dual-branch gated fusion network, characterized in that, Includes the following steps: S1. HGStem is used as a shared Stem module to perform preliminary feature extraction on the input image. Basic features are efficiently extracted in the shallow network through convolutional layers and downsampling operations. Two parallel branches are constructed from the Stem output, including a lightweight branch and an enhanced branch. The lightweight branch uses a C2f module to achieve effective feature extraction while maintaining low computational complexity through cross-layer connections and bottleneck structures. The enhancement branch uses the HGBlock module, which significantly improves feature representation capabilities by moderately increasing computational cost through hierarchical convolutional structures and residual connections. S2. Construct a polarization multi-mechanism encoder layer and integrate four complementary mechanisms to achieve powerful feature interaction capabilities; S3. In the feature pyramid neck network, the dilated reparameterized C3 module is used to replace the traditional RepC3 module. The dilated reparameterized C3 module adopts a multi-branch parallel structure, and each branch uses convolutional kernels with different dilation rates, so as to obtain receptive fields of different sizes with the same number of parameters. S4. In the downsampling process of the feature pyramid, weighted frequency convolution wConv2d is used instead of traditional stride convolution. By using frequency domain weighting, key information is preserved to the maximum extent while reducing the resolution of the feature map. S5. Using Wise-Focaler-ShapeIoU as the bounding box regression loss function, the following improvements are achieved: The shape-aware mechanism is used to consider the overlapping area of ​​bounding boxes while focusing on the shape similarity of the bounding boxes. By calculating the aspect ratio and scale difference, it guides the model to learn a more accurate bounding box shape. The focus strategy is used to assign higher weights to samples that are difficult to regress, thereby improving the detection capability of small targets and occluded targets; The intelligent weighting mechanism is used to dynamically adjust the loss weights based on the target's size and aspect ratio, and to adopt differentiated optimization strategies for targets with different characteristics.

2. The printed circuit board defect detection method based on a dual-branch gated fusion network according to claim 1, characterized in that, The specific process in S1 is as follows: S11. Multi-scale gated attention fusion modules are introduced at the three feature levels of P3, P4 and P5 respectively. If the number of channels of the lightweight branch and the enhanced branch are different, they are adjusted to the same dimension by 1×1 convolution. Then, the features of the two branches are processed at multiple scales by the multi-scale gated attention fusion module. The multi-scale gated attention fusion module uses convolution kernels of different sizes to extract features in parallel and capture multi-level information from local details to global context. S12. Generate a dual-channel attention map by passing the multi-scale fused features through a 1×1 convolutional layer, and then generate the weights A and B of the two branches through Softmax normalization, where x is the lightweight branch feature and g is the enhanced branch feature: S13. Apply attention weights to the two branch features, perform weighted modulation, and add a residual connection: S14. Achieve bidirectional information exchange of dual-branch features through Sigmoid gating: S15. The interactive features are activated by a projection layer and a Sigmoid function, multiplied with the original lightweight branch features, and then output as the final fused features after convolutional blocks and batch normalization.

3. The printed circuit board defect detection method based on a dual-branch gated fusion network according to claim 1, characterized in that, The processing flow of the encoder layer in S2 is as follows: S21. The input features are processed by polarized linear attention and then passed through residual connections and Dropout; then they are processed by the first dynamic Tanh activation and Mona normalization module. S22, processed by an enhanced dynamic feedforward network and through residual connections and Dropout; S23. After passing through the dynamic Tanh activation and Mona normalization modules again, the final features are output. The entire process can be represented as follows: 。 4. The printed circuit board defect detection method based on a dual-branch gated fusion network according to claim 1, characterized in that, The specific process in S3 is as follows: During the training phase, multiple dilated convolutional branches independently learn feature representations and optimize their parameters through gradient backpropagation, thereby enhancing the model's expressive power. The inference phase employs a reparameterization technique, which linearly combines the weights of multiple dilated convolutions into a single, larger convolutional kernel, achieving efficient inference without sacrificing expressive power.

5. The printed circuit board defect detection method based on a dual-branch gated fusion network according to claim 1, characterized in that, The specific process in S4 is as follows: S41. The core of wConv2d is to construct a frequency domain weighting matrix Φ. Given a density parameter α=0.9, a frequency weight vector is constructed, and then a two-dimensional weighting matrix is ​​generated through outer product. The size of the two-dimensional weighting matrix is ​​the same as the size of the convolution kernel (3×3). S42. Frequency domain modulation is achieved by element-wise weighting of the convolution kernel weights, where W is the original convolution kernel weights. The weights after frequency domain weighting: S43. Through frequency domain weighting, high-frequency components are given higher weights, and redundant low-frequency information is appropriately suppressed.

6. The printed circuit board defect detection method based on a dual-branch gated fusion network according to claim 1, characterized in that, The specific process in S5 is as follows: Training is conducted end-to-end without post-processing steps. The optimizer is AdamW, the initial learning rate is set to 1e-4, and a cosine annealing learning rate scheduling strategy is used. The total number of training epochs is 150, and the batch size is set to 4. A warmup strategy was adopted, with the learning rate increasing linearly over the first 10 epochs.