# An Improved YOLOv5s-Based Helmet Recognition Method for Electric Bikes
## 4 Materials and Methods
### Improved YOLOv5s Helmet Detection Algorithm
#### 4.2.2 Modify The CRARFE Upsampling Method  
Traditional upsampling methods such as Nearest Upsample [34] and Linear Upsample [34] mainly focus on spatial pixel positions when determining the upsampling kernel. These methods have limitations in fully utilizing semantic information from the feature maps, resulting in limited perception domains. Deconvolution is another upsampling technique that has two key drawbacks: it applies a unified kernel throughout the entire image, ignores local changes, and involves a large number of parameters.  
To address the issue of insufficient semantic correlation in upsampling, this paper introduces CARAFE as an alternative to Nearest Upsample. CARAFE is a pixel-level semantic segmentation network upsampling method that reconstructs feature maps by learning pixel correlations, resulting in higher resolution feature maps. CARAFE consists of two essential modules: the Kernel Prediction Module (KPM) and the Content-Aware Reassembly Module (CARM). The information flow of CARAFE is shown in Figure 5.  
The KPM utilizes separable convolution to generate convolutional kernels for downsampling input feature maps and convolving them with the downsampled feature maps. Initially, the input feature map of size \(H\times W\times C\) is decomposed using a \(1\times 1\) convolutional layer for channel compression. This compression reduces the number of channels to \(C_{m}\), thereby reducing the number of parameters used for subsequent operations. The compressed feature map is then convolved using a convolutional layer with dimensions \(K_{encoder}\times K_{encoder}\). This convolutional layer is responsible for line content encoding. Furthermore, the feature map is extended in the spatial dimension to obtain an upsampling kernel of size \({k_{up}}^{2}\times\sigma H\times\sigma W\). The upsampling kernel is normalized using the Softmax function to ensure that the sum of the convolutional kernel weights is equal to 1. This process helps to learn and reconstruct pixel correlations within the convolutional kernel. The generation of convolution kernels depends on two key hyperparameters: \(k_{up}\), which determines the size of the reconstructed convolution kernel, and \(\sigma\), which represents the reconstruction factor.  
The CARM is responsible for reconstructing the feature maps from the previous layer to achieve upsampling. It begins by applying a pixel shuffle operation [35] to the downsampled feature map, followed by converting it to a higher-resolution feature map using separable convolution. The resulting feature map is then normalized using the Softmax function and divided into smaller blocks. A dot-product of each pixel in the upper feature map and its corresponding smaller blocks is performed, resulting in an output feature map of size \(C\times\sigma H\times\sigma W\).  
By integrating KPM and CARM modules, CARAFE achieves pixel-level feature recombination to generate higher resolution feature maps. In practical segmentation tasks, CARAFE has demonstrated excellent segmentation accuracy and computational efficiency in various scenarios.