# An Improved YOLOv5s-Based Helmet Recognition Method for Electric Bikes
## 4 Materials and Methods
### Improved YOLOv5s Helmet Detection Algorithm
#### 4.2.4 Introduction of the CSPCM model  
(1)  
DFC attention  
The Decoupled Fully Connected (DFC) [36] attention mechanism is a hardware-friendly technology specifically designed to capture the wide relationship between pixels while ensuring the computational efficiency of lightweight convolutional neural networks. Its design involves the utilization of fully connected layers that can be efficiently executed on standard hardware. The DFC attention mechanism decomposes a fully connected layer into two different components: a horizontal fully connected layer and a vertical fully connected layer. These two layers are responsible for gathering the information about pixels in the 2D feature map from the convolutional neural network. By combining these separate, fully connected layers, the DFC attention mechanism effectively captures long-range dependencies along the horizontal and vertical directions, resulting in a comprehensive perception field. A significant advantage of the DFC attention mechanism is its compatibility with hardware implementations, as it can efficiently execute on a common hardware platform. By using the computationally efficient full connection layer, the DFC attention mechanism achieves a balance between capturing long-range dependencies and maintaining the overall execution efficiency of lightweight convolutional neural networks. For a given feature map \(Z\in R^{H\times W\times C}\), it can be considered a set of HW tokens, denoted as \(Z=z_{11},z_{12},\cdots,z_{HW}\). The direct approach to constructing the attention graph through a fully connected layer can be formulated by the following equation:  
\[a_{hw}=\sum_{h^{\prime},w^{\prime}}F_{hw,h^{\prime}w^{\prime}}\odot z_{h^{ \prime}w^{\prime}} \tag{4}\]  
In Equation (4), the symbol \(\odot\) denotes element-wise multiplication, \(F\) represents the learnable weights within the fully connected layer, \(H\) and \(W\) denote the height and width of the feature map, and \(C\) represents the number of channels in the feature map. The resulting attention map is represented by \(A=a_{11},a_{12},\cdots,a_{HW}\). Equation (4) effectively captures global information by aggregating all the patches together using the learnable weights, which is simpler than traditional self-attention methods [37]. To further simplify Equation (4), it can be decomposed into two fully connected (FC) layers, where features are aggregated separately along the horizontal and vertical directions. This decomposition can be expressed by Formula as follows:  
\[a^{\prime}_{hw}=\sum_{h^{\prime}=1}^{H}F^{H}_{h,h^{\prime}w}\odot z_{h^{\prime }w};h=1,2,\cdots,H;w=1,2,\cdots,W \tag{5}\]  
\[a_{hw}=\sum_{w^{\prime}=1}^{W}F^{W}_{w,h^{\prime}w}\odot a^{\prime}_{h^{\prime }w^{\prime}};h=1,2,\cdots,H;w=1,2,\cdots,W \tag{6}\]  
In Equation (5), \(F^{H}\) represents the transformation weight used to capture remote dependencies along the horizontal direction, while in Equation (6), \(F^{W}\) represents the transformation weight used to capture remote dependencies along the vertical direction. These transformation weights are applied to the original feature \(Z\) to capture long-range dependencies in each direction. By continuously applying Equations (5) and (6) to features, decoupled fully connected (DFC) attention operations are performed. The information flow of the DFC attention is illustrated in Figure 9. The DFC's attention module reduces the computational complexity to \(O\left(H^{2}W+HW^{2}\right)\) by decoupling the horizontal and vertical transformations. In Equation (4), all patches within the square region directly participate in the calculation of the focus patch. However, in the DFC, a patch is directly aggregated by the patches on its vertical/horizontal line, while other patches are indirectly related to the focus patch through the generation of the patches on the vertical/horizontal line. Therefore, the calculation of patches also involves all patches in the square region.