# LG-YOLOv8: A Lightweight Safety Helmet Detection Algorithm Combined with Feature Enhancement
## 3 Materials and Methods
### LG-YOLOv8 Algorithm
#### 3.2.2 BiFPN  
The neck design of YOLOv8 draws inspiration from PANet [27], enhancing feature fusion by combining the Path Aggregation Network (PAN) and Feature Pyramid Network (FPN) architectures, as illustrated in Figure 5a,b. Unlike YOLOv5 [28] and YOLOv7, YOLOv8's FPN architecture employs top-down fusion, where high-level features are upsampled and integrated into low-level features, enriching them with semantic details. Conversely, PAN adopts a bottom-up strategy, downsampling low-level features and incorporating them into high-level features, thereby augmenting spatial precision. The integration of these techniques forms the PANet structure, facilitating adaptive fusion of shallow and deep features, which substantially enhances the model's capability to discern fine details. Nonetheless, when merging features of disparate resolutions, the features are typically aggregated through straightforward summation, resulting in unequal contributions from various layers. As the network progresses deeper, the impact of high-level features intensifies, while low-level features diminish. To address this, [PERSON] et al. [29] proposed BiFPN to produce feature maps with more enriched semantic content. BiFPN introduces bi-directional connectivity between neighboring levels of the feature pyramid, which means that information can flow from higher level features to lower level features (top-down path) or from lower level features to higher level features (bottom-up  
Figure 4: Comparison of C2f and C2f-GhostDynamicConv modules: (**a**) C2f module; (**b**) C2f-GhostDynamicConv module. Figure 5: (**a**) FPN introduces a top-down path to fuse multiscale features from the third to the seventh level (P3–P7); (**b**) PANet enhances the FPN (Feature Pyramid Network) by incorporating an additional bottom-up pathway; and (**c**) BiFPN offers a superior balance between accuracy and efficiency. path), which greatly enhances semantic representation and differentiation. BiFPN adopts separated convolution and lightweight design, which can improve efficiency and also reduce the number of parameters and computation. For the helmet detection task, the bidirectional feature pyramid can better solve the situation that small targets are not well recognized, which in turn leads to omission and misdetection [30]. As illustrated in Figure 5c, BiFPN is constructed upon bidirectional cross-scale connections and weighted multi-scale feature fusion. Distinct from PANet, BiFPN incorporates learnable weights to assess the significance of various input features during both top-down and bottom-up processes. The BiFPN network excludes nodes with a single input edge; such nodes are deemed insufficient for effective feature fusion due to their limited information content and reduced contribution to the feature network. Incorporating additional edges between input and output nodes within the same layer and obtaining higher-level fused features through iterative stacking enhances the feature fusion efficiency and accuracy of the BiFPN network, thereby boosting the model's capability to extract features pertinent to a specific scene. By configuring the learning parameters to ensure that the input layers are of uniform size and augmenting each feature layer with additional weights, the BiFPN network is capable of effectively merging input features of varying resolutions and evaluating their contribution to the output. The fast normalized fusion method is employed to weight the feature layer, specifically through the BiFPN weighted feature fusion technique:  
\[\text{O}=\sum_{\text{i}}\frac{\text{w}_{\text{i}}\cdot\text{I}_{\text{i}}}{ \sum_{\text{j}}\text{w}_{\text{j}}+\epsilon} \tag{7}\]  
O represents the output from the BiFPN network; I\({}_{\text{i}}\) denotes the feature from the ith layer; w\({}_{\text{i}}\) signifies the weight associated with the ith layer feature; and w\({}_{\text{j}}\) refers to the jth weight within the ith layer; \(\epsilon=0.001\) is used to avoid numerical instabilities, as indicated by the notation.