# EGS-YOLO: A Fast and Reliable Safety Helmet Detection Method Modified Based on YOLOv7
## 3 Proposed Method EGS-YOLO
### SE (Squeeze and Excitation Block)  
As for limited computational power, the attention mechanism can distribute computational power to the more important parts of the task. Attention mechanisms are widely used in deep learning to enhance the performance of models [29]. Currently, attention mechanisms are categorized into three types. The squeeze excitation network (SENet) [30] is a typical representative of channel attention. The second type is the spatial attention mechanism, with SAM [31] as a typical example. The third type is the mixed frequency domain mechanism, with CBAM [32] as its representative. SE is able to reduce the problem of vanishing gradients by re-weighting the channel features. To speed up the model's inference time and lighten the model, we introduced GhostModule. However, this weakened the model's feature extraction capability, leading to a loss in accuracy. To address this, we incorporated attention mechanisms. Figure 9: The structure of ELAN-G, ELAN-HG, and SPPCSPC-G (G is the GhostModule). The SE (Squeeze-and-Excitation) module can mitigate the problem of accuracy loss due to the different significance attributed to various channels. This unit adaptively recalibrates the channel feature response by explicitly modeling the interdependencies between channels. The goal is to improve the quality of the representations produced by the network by highlighting valuable parts and suppressing less meaningful information. SE allows networks to use overall information to selectively emphasize significant features. The context of construction sites is usually complex and diverse, causing many interferences and difficulties in helmet detection. SE suppresses insignificant information in the image, making it effective for tasks like helmet detection with mixed backgrounds. And we have experimented with a variety of attention mechanisms to conclude that SE is the most appropriate choice. SE is more lightweight and has almost no effect on the parameters. The structure of SE is visible in Figure 10; the image input is first subjected to a Squeeze-and-Excitation operation, followed by a scale operation to generate the final feature map. An SE block is equivalent to a calculation unit. The feature map \(U\) is generated by passing the input \(X\) through the transformation operation, as shown in Equation (5). The output is expressed as \(U=[u_{1},\ u_{2},\ \cdots,\ u_{c}]\). \[u_{c}=v_{c}*X=\sum_{s=1}^{c^{\prime}}v_{c}^{s}*x^{s} \tag{5}\]  
\(v_{c}\) indicates the 2D spatial kernel of a single channel, which acts on the correspondent channel of \(X\). There are two key steps in the SE block: the compression operation and the excitation operation. The compression procedure is essentially a process of global average pooling. It compresses the global spatial information into the channel descriptor. The channel statistics are generated by using global average pooling, resulting in a feature map as a 1*1*C vector, where a numerical value represents each channel. This operation is shown in Equation (6). \[z_{c}=F_{sq}(u_{c})=\frac{1}{H\times W}\sum_{i=1}^{H}\sum_{j=1}^{W}u_{c}(i,j) \tag{6}\]  
Here, \(H\) and \(W\) are, respectively, the height and width of the feature map. The second step is the excitation operation, which obtains channel-related reliance relationships using the information aggregated during the compression operation. This is done through two fully connected layers, as shown in Equation (7). \[s=F_{ex}(z,W)=\sigma(g(z,W))=\sigma(W_{2}\delta(W_{1}z)) \tag{7}\]  
\(W\) is the weight, through which the required weight information is generated, and the value of \(W\) is produced by learning. \(\delta\) is the ReLU function. Figure 10: The structure of SE (Squeeze-and-Excitation). The final output of the block is to weight the generated weight \(s\) to the feature map \(U\), as shown in Equation (8).