# ETAFHrNet: A Transformer-Based Multi-Scale Network for Asymmetric Pavement Crack Segmentation
## 3 Methods
### Cross-Scale Hybrid Attention Module (CSHAM)  
In the original HRNet architecture, the multi-scale feature fusion stage performs feature alignment across different resolution branches via upsampling, followed by direct fusion through summation or concatenation. This rigid fusion strategy lacks both adaptive weighting across scales and directional feature enhancement, which limits its effectiveness in pavement crack segmentation, particularly for elongated structures and scenes involving the coexistence of multi-scale cracks. In such scenarios, critical morphological information is often lost due to the uniform treatment of features with varying semantic granularity. To overcome these limitations, we introduce the Cross-Scale Hybrid Attention Module (CSHAM) into the multi-scale fusion stage of HRNet. Specifically, after all feature maps are upsampled to a unified spatial resolution, CSHAM is inserted in place of naive fusion (as illustrated in Figure 4), enabling both cross-scale adaptive fusion [50] and axial attention enhancement [39]. This design ensures that the segmentation head receives a comprehensive, structurally-aware representation that integrates multi-scale contextual information while preserving directional cues critical for detecting complex crack morphologies. The Cross-Scale Hybrid Attention Module (CSHAM) adopts a hierarchical connection structure designed to perform adaptive scale-wise feature weighting alongside directional feature enhancement. The process begins with a cross-scale attention mechanism, which evaluates the relative importance of each scale-specific feature by aggregating global contextual information. The computation is formally expressed as:  
\[G=\frac{1}{N}\sum_{i=1}^{N}F_{i} \tag{5}\]  
Let \(F_{i}\) denote the feature map at scale \(i\), where \(i=1,2,\ldots,N\) and \(N\) is the total number of scales. To compute the importance of each scale, a channel dimension reduction operation is first applied, followed by a weight prediction module that assigns learnable importance scores. These weights are then used to reweight the corresponding feature maps,  
Figure 4: The Cross-Scale Hybrid Attention Module (CSHAM). enabling the network to dynamically emphasize informative scales while suppressing less relevant representations. \[W=\text{Softmax}(W_{2}\,\delta(W_{1}\,G)) \tag{6}\]  
\[F_{\text{fused}}=\sum_{i=1}^{N}W_{i}\cdot F_{i} \tag{7}\]  
Here, \(W_{1}\) and \(W_{2}\) are learnable projection matrices used for dimensionality reduction and expansion, respectively, and \(\delta\) represents the ReLU activation function. Once the attention weights are computed and scale-wise feature reweighting is performed, a fused feature map \(F_{\text{fused}}\) is obtained. To further enhance directional awareness, directional attention is applied by employing one-dimensional convolutions to generate attention maps along the horizontal and vertical axes. These attention maps are then element-wise multiplied with \(F_{\text{fused}}\) to selectively amplify features aligned with directional crack patterns. This process is formally defined as:  
\[F_{\text{axial}}=\sigma(\text{Conv}_{h}(F_{\text{fused}}))\odot\sigma(\text{ Conv}_{v}(F_{\text{fused}})) \tag{8}\]  
In this context, \(\text{Conv}_{h}\) and \(\text{Conv}_{v}\) refer to one-dimensional convolution operations performed along the horizontal and vertical axes, respectively. The function \(\sigma\) represents the Sigmoid activation, and \(\odot\) denotes element-wise multiplication. This design is particularly effective in enhancing the model's sensitivity to linear crack structures, regardless of orientation. During backpropagation, the gradients of the cross-scale attention weights can be computed as:  
\[\frac{\partial L}{\partial W_{i}}=\frac{\partial L}{\partial F_{\text{out}}} \cdot\frac{\partial F_{\text{out}}}{\partial F_{\text{fused}}}\cdot F_{i} \tag{9}\]  
Let \(L\) denote the loss function, which quantifies the discrepancy between model predictions and ground truth labels.