# Detection of Welding Defects Using the YOLOv8-ELA Algorithm
## 2 Methodology
### HS-FPN Feature Fusion Module  
The Hierarchical Scale-based Feature Pyramid Network (HS-FPN) improves the multi-scale feature extraction through a hierarchical framework, thereby enhancing the detection of small defects. In this architecture (Figure 2), S3, S4, and S5 in the backbone section denote feature maps at three distinct scales. The CA attention mechanism refers to channel attention, while SFF represents the Selective Feature Fusion module (Figure 3). At the initial stage, multi-scale feature representations are processed through a gated attention-based selection mechanism, which dynamically filters and weights the informative channels based on their spatial-semantic significance. Subsequently, an adaptive cross-layer fusion module with learnable connection weights is employed to establish the context-aware feature interactions across different hierarchical levels, enabling the network to preserve both high-resolution spatial details and semantically rich contextual information. The key distinction between HS-FPN and traditional FPN/PANet lies in the introduction of a channel attention mechanism and a multi-level fusion strategy in HS-FPN. Traditional FPN employs a top-down one-way path to fuse multi-layer features, while PANet further enhances this by adding a bottom-up path to supplement finer details. However, both approaches rely on simple addition or concatenation for feature fusion, which  
Figure 3: HS-FPN feature fusion module. Figure 2: YOLOv8-ELA frame diagram. can easily result in semantic gaps and information losses. In contrast, HS-FPN leverages a channel attention module to dynamically weight low-level features using high-level features as guidance, and it then integrates them with high-level features to effectively enhance the feature representation, particularly for multi-scale targets. Additionally, HS-FPN incorporates a deformable self-attention mechanism in the encoder to extract global context features, addressing the issue of feature sparsity more effectively. Compared with FPN/PANet, HS-FPN demonstrates superior multi-scale modeling capabilities in complex scenarios, such as medical image analysis and small object detection. Feature Selection Module: In this module (Figure 4), the CA mechanism first processes the input feature map \(f_{in}\in\mathbb{R}^{C\times H\times W}\), where \(C\) represents the number of channels, \(H\) is the height, and \(W\) signifies the width. The input features are processed by two pooling layers: max pooling and average pooling. The pooled features from each channel are aggregated and passed through a Sigmoid activation function to determine the weight for each channel, resulting in the channel-wise attention map \(f_{CA}\in\mathbb{R}^{c\times 1\times 1}\). Feature Integration Module: The hierarchical feature representations extracted from the backbone network exhibit a characteristic trade-off between semantic richness and localization precision. While high-level features demonstrate enhanced semantic abstraction with compromised spatial resolution, their low-level counterparts maintain superior localization accuracy at the expense of semantic expressiveness. Traditional fusion methodologies typically employ direct element-wise summation of upsampled high-level features with their low-level counterparts, which inevitably leads to information redundancy and suboptimal feature interaction. To address these limitations, the proposed Selective Feature Fusion (SFF) mechanism implements a weighted attention-guided fusion paradigm, where high-level semantic descriptors serve as adaptive attention weights to selectively amplify the informative patterns in low-level features while suppressing redundant or noisy activations. This hierarchical attention mechanism enables context-aware feature enhancement without compromising the spatial fidelity of low-level representations.