## 2 Methodology
### Dynamic Hybrid Attention Module  
For PCB soldering defect images, the similarity interference in the background is severe due to the small spacing and high similarity between PCB components. Introducing attention mechanisms can alleviate background interference by directing the model's focus toward the critical parts of the defect areas, thereby improving the segmentation accuracy. This paper proposes a dynamic hybrid attention module, which combines channel attention and dynamic spatial attention in parallel. By integrating different attention perspectives from the channels and spatial dimensions, this module comprehensively considers the features of the attention area, filters out other information with substantial similarity interference in the image, and selects critical information from the defect area to enhance the model's feature-capturing capability. Additionally, dynamic convolution [26] is introduced into the spatial attention, adapting the convolution kernel weights flexibly based on different input channels to enhance the adaptability to differently scaled context information and improve the feature representation capabilities. This paper incorporates the DHAM into the skip connections between each encoder and decoder, replacing the  
Figure 1: The improved UNet network architecture. simple connection operation in the original UNet network. It selects essential feature information from multiple scales and focuses more specifically on features of different scales, thereby further improving the model's performance. The DHAM, shown in Figure 2, comprises channel attention and dynamic spatial attention. In the channel attention module (CAM), average pooling is utilized to aggregate the feature maps of each channel, followed by two fully connected layers to learn the characteristics of each channel and determine which channels are more significant. Subsequently, the output scale is adjusted through a batch normalization layer to obtain the channel attention weights. The calculation of the CAM is as follows:  
\[f_{\alpha}=BN(FC_{2}(FC_{1}(Avg(f_{in})))) \tag{1}\]  
where \(f_{in}\) denotes the input feature, \(Avg\) represents average pooling, \(FC\) represents the fully connected layer, and \(BN\) represents batch normalization. Dynamic convolution involves utilizing multiple convolutional kernels in a single layer and dynamically aggregating these kernels using an attention mechanism in a non-linear manner. The attention mechanism is input-dependent. In a single layer, dynamic convolution sets up k parallel convolutional kernels. For each input datum \(x\), dynamic convolution calculates an input-dependent attention weight \(\pi_{k}\). Based on the calculated attention weights, the output of each convolutional kernel is multiplied by the corresponding attention weight, and these weighted outputs are then summed to obtain the final convolution result. The attention weights \(\pi_{k}\) are obtained by compressing the global spatial information using global average pooling. This is followed by two fully connected layers (with a ReLU activation function introduced in between) and a softmax function. The dynamic convolution structure is computationally efficient and has small kernel sizes, greatly enhancing the model's feature representation capabilities. The expression for dynamic convolution is as follows:  
\[ \begin{split}& y=g(\widetilde{W}^{T}(x)x+\widetilde{b}(x))\\ &\widetilde{W}(x)=\sum\limits_{k=1}^{K}\pi_{k}(x)\widetilde{W}_{k },\widetilde{b}(x)=\sum\limits_{k=1}^{K}\pi_{k}(x)\widetilde{b}_{k}\\ &\text{s.t. }0\leq\pi_{k}(x)\leq 1,\sum\limits_{k=1}^{K}= 1\end{split}  \tag{2}\]  
where the aggregated weight \(\widetilde{W}(x)\) and bias \(\widetilde{b}(x)\) are functions of the input. \(g\) is an activation function. \(\pi_{k}\) is the attention weight for the \(k^{th}\) linear function \(\widetilde{W}_{k}^{T}x+\widetilde{b}_{k}\). In the branch of the dynamic spatial attention module (DSAM), the process starts by compressing and integrating the feature maps using a \(1\times 1\) convolution.