## 3 Proposed Method
### Detect_DyHead: Enhancing Detection with 3D Decoupled Attention  
In industrial defect detection tasks, the static fusion strategies of traditional detection heads struggle to adapt to the complex characteristics of defect targets. For instance, micron-level scratches require high-resolution features for precise localization, while randomly distributed point defects necessitate robust spatial context modeling. Furthermore, conventional classification-regression shared convolutions often lack task-specific feature decoupling, leading to semantic confusion within the detection head against noisy backgrounds. To mitigate the aforementioned problems, this paper integrates the Detect_DyHead, built upon a three-dimensional decoupling attention structure. As shown in Figure 6, Detect_DyHead achieves efficient collaboration across multi-scale and multi-task aspects in object detection through multi-task decoupling branches and a fine-grained dynamic router. By introducing a self-attention mechanism, Detect_DyHead decomposes the feature tensor into three orthogonal dimensions--level, space, and channel--to construct a cascaded dynamic attention module. This design enhances the model's sensitivity to fine-grained defect regions while also reinforcing the synergistic optimization between classification and regression tasks, thereby boosting its effectiveness in handling complex industrial defect detection scenarios [29]. As shown in Figure 7, Detect_DyHead's three perception enhancement modules achieve feature optimization through attention mechanisms in different dimensions, and the specific attention formulas are as follows:  
\[W(\mathcal{F})=\pi_{C}(\pi_{S}(\pi_{L}(\mathcal{F})\mathcal{F})\mathcal{F}) \mathcal{F}, \tag{8}\]  
Here, three distinct attention functions, \(\pi_{L}\), \(\pi_{S}\), and \(\pi_{C}\), operate along the \(L\), \(S\), and \(C\) dimensions, respectively. \(L\) represents the feature pyramid level, \(S=H\times W\) denotes spatial dimensions (\(H\): height, \(W\): width), and \(C\) represents the channel dimension. The attention functions for the three dimensions are described below:  
\(\pi_{L}\) is a scale-aware attention mechanism that employs global average pooling (GAP) to compress spatial and channel dimensions, generating scale-sensitive feature descriptors. Combined with \(1\times 1\) convolutions and a hard Sigmoid function, it dynamically allocates level weights. This enables adaptive feature selection and fusion based on scale importance. The specific formula is as follows:  
\[\pi_{L}(\mathcal{F})\mathcal{F}=\sigma\Bigg{(}f\Bigg{(}\frac{1}{SC}\sum_{S,C }\mathcal{F}\Bigg{)}\Bigg{)}\mathcal{F}, \tag{9}\]  
Figure 6: Structure of the Detect_DyHead, integrating a three-dimensional decoupled attention mechanism to enhance object detection performance. The figure illustrates how feature tensors are decomposed into level, space, and channel dimensions, and highlights how multi-task decoupling branches and a fine-grained dynamic router facilitate efficient collaboration across multi-scale and multi-task aspects. Here, \(f()\) is analogous to a linear transformation, composed of \(1\times 1\) convolutional operations. The hard sigmoid activation \(\sigma(x)=max(0,min(1,x+1/2))\) is applied for non-linear processing. \(\pi_{S}\) is a spatially-aware attention mechanism that focuses on spatial-location-related information. It uses deformable convolutions to let attention learn sparsification. By adjusting sparse-sampling positions via learnable offsets (\(\Delta p_{k}\)), the convolution kernel adaptively fits defect geometry (e.g., crack propagation direction) and aggregates elements from different levels at corresponding spatial positions. \[\pi_{S}(\mathcal{F})\mathcal{F}=\frac{1}{L}\sum_{l=1}^{L}\sum_{k=1}^{K}w_{l,k} \cdot\mathcal{F}(l;p_{k}+\Delta p_{k};c)\cdot\Delta m_{k}, \tag{10}\]  
Here, \(k\) specifies the count of sparse sampling locations. \(p_{k}+\Delta p_{k}\) incorporates learned spatial offsets, with \(\Delta p_{k}\) being derived through deformable convolution operations.