A helmet wearing detection method based on YOLOv5s
By introducing a hollow coordinated attention mechanism and reconstructing a bidirectional feature pyramid into the YOLOv5s model, the problems of low accuracy and poor robustness in small target detection in helmet wearing detection are solved, achieving high-precision and real-time helmet wearing detection, which is suitable for intelligent monitoring of non-motorized vehicle riders.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-08
- Publication Date
- 2026-03-10
AI Technical Summary
Existing helmet-wearing detection algorithms suffer from low accuracy and poor robustness in detecting small targets in complex backgrounds, and require a large amount of computation, making it difficult to meet real-time requirements. Furthermore, the lack of a rich dataset of helmet-wearing data for non-motorized vehicle riders affects the detection results.
A helmet-wearing detection method based on YOLOv5s is adopted. By adding a Dilated Convolution In Coordinate Attention (DICA) mechanism and a Re-Bidirectional Feature Pyramid (Re-BiFPN) to the backbone network, feature extraction and fusion are enhanced to obtain multi-scale feature information, thereby improving the attention to and detection accuracy of small targets.
It achieves accurate detection of helmet wearing by non-motorized vehicle riders in complex environments, with a detection accuracy of 94.3%, meeting the requirements for real-time detection and suitable for practical application scenarios.
Smart Images

Figure CN115619766B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a helmet wearing detection method based on YOLOv5s. Background Technology
[0002] Private electric bicycles and shared electric bikes have become an increasingly popular mode of transportation, bringing convenience but also safety hazards. Therefore, some cities have issued initiatives promoting helmet use, requiring non-motorized vehicle riders to wear helmets to ensure safety. Currently, monitoring helmet use by non-motorized vehicle riders mainly relies on traffic police on-site inspections and warnings. This is not only manpower-intensive but also prone to missed checks and inefficient in inclement weather. Therefore, using automated monitoring management can effectively address the shortcomings of manual monitoring. Object detection, a hot topic in computer vision, offers significant advantages for intelligent monitoring.
[0003] Traditional object detection algorithms are suitable for detecting targets with obvious features and simple backgrounds. However, in practical applications, the backgrounds are often varied and the targets are complex, which cannot achieve good detection results. With the development of convolutional neural networks in the field of object detection, deep learning-based object detection algorithms have been widely used in road vehicle monitoring, medical research, mask wearing detection, video surveillance security detection, image classification, and other fields. Deep learning-based object detection algorithms mainly include two-stage algorithms based on region extraction and single-stage algorithms based on regression. Two-stage object detection algorithms first extract regions of interest from the input image to generate candidate boxes, and then perform regression classification on the candidate boxes. Common two-stage algorithms include RegionCNN (R-CNN), Fast R-CNN, and Faster R-CNN. Single-stage object detection algorithms omit the step of generating candidate regions and directly perform feature extraction, object regression, and classification in the same convolutional network. These mainly include the Single Shot MultiBox Detector (SSD) and You Only Look Once (YOLO) series of algorithms. Experiments show that deep learning-based two-stage object detection algorithms are superior to single-stage detection algorithms in detection accuracy, but single-stage algorithms are faster.
[0004] Currently, helmet detection for non-motorized vehicle riders based on deep learning is still in its early stages of research, but it is similar to helmet detection for motorcycles and safety helmets on construction sites. Yogameena et al. first used a Gaussian model to segment the foreground target, and then used Faster R-CNN to detect helmet wearing on both the motorcycle and the detected motorcyclist. Mohan et al. applied both Faster R-CNN and SSD algorithms to the field of motorcycle rider helmet detection. They compared and analyzed the detection results to determine the suitable application scenarios for different algorithms. The results showed that Faster R-CNN is slower in capturing images but performs better in terms of accuracy, making it suitable for deployment in areas with slow traffic. SSD is faster but less accurate, making it suitable for deployment in fast-moving traffic scenarios such as highways. Mistry et al. used two YOLOv2 models to detect motorcyclists and helmets respectively. The first YOLOv2 model was trained on the COCO dataset to detect motorcyclists, and then the detected people were used as input to the second YOLOv2 network to finally detect whether the motorcyclist was wearing a helmet, achieving a detection accuracy of 94.7%. Wu et al. used the YOLO-Densebackbone deep neural network to detect whether workers were wearing helmets. They replaced the original Darknet53 backbone network of YOLOv3 with DenseNet for feature extraction, effectively solving problems such as complex helmet colors, partial occlusion, multiple targets, and low image resolution. Jia et al. improved upon YOLOv5 by adding a triple attention mechanism to the last layer of the backbone network, using three parallel branch structures. Two branches extract the inter-dimensional dependencies between spatial and channel dimensions, while the third extracts spatial feature dependencies, better addressing the occlusion problem in crowded scenes. Hanet et al. proposed a cross-layer attention mechanism to refine the feature information of the target region. Based on the SSD model, they applied a spatial attention mechanism to low-level features and a channel attention mechanism to high-level features. Cheng et al., based on the lightweight algorithm YOLOv3-Tiny, used the hourglass residual model in the feature extraction process to reduce the network parameters and computational cost. Li et al. proposed an improved hierarchical matching positive sample strategy, using the Intersection over Union (IoU) ratio between the predicted and labeled boxes as the basis. When IoU is 0.1 < IoU < 0.2, the feature point at the center of the bounding box is selected as a positive sample. When IoU is 0.2 < IoU < 0.5, the two adjacent feature points of the center of the bounding box at the grid position are used as additional positive samples. When IoU > 0.5, the four feature points closest to the center point are selected as positive samples. This hierarchical strategy effectively improves the feature learning ability of the network.
[0005] In the task of detecting helmet use by non-motorized vehicle riders, targets in surveillance footage are characterized by their large number, low pixel count, rich colors, and shapes similar to ordinary hats, making them difficult to accurately capture in complex and ever-changing real-world scenarios. Furthermore, the detection task has strict real-time requirements, needing to achieve rapid detection while non-motorized vehicles are in motion. Currently, deep learning-based helmet detection algorithms are developing rapidly, but they still suffer from low accuracy in detecting small targets, poor robustness, and high computational cost. Additionally, there is a lack of abundant datasets of non-motorized vehicle rider helmet use to comprehensively evaluate the performance of these algorithms.
[0006] Therefore, it is necessary to design a new method for detecting helmet wearing. Summary of the Invention
[0007] The technical problem to be solved by the present invention is to provide a helmet wearing detection method based on YOLOv5s, which has high detection accuracy and is easy to implement.
[0008] The technical solution of the invention is as follows:
[0009] A helmet-wearing detection method based on YOLOv5s is proposed, which processes helmet-wearing images based on the YOLOv5s model and adds a diffusing coordination attention mechanism to the backbone network.
[0010] The dilated coordinating attention mechanism combines dilated convolution with a coordinating attention mechanism, employs a multi-branch dilated convolution structure, sets different dilation rates, and obtains multi-scale feature information.
[0011] To obtain a larger receptive field, dilated convolution is performed on the input feature map. The dilated convolution structure is set with a kernel size of 3×3, a stride of 2, and dilation rates of 1, 2, and 3, respectively. The receptive fields after convolution are 3×3, 5×5, and 7×7, respectively. The feature maps obtained after the three-branch convolution have the same number of channels as the input feature map, but the size is reduced by 1 / 2.
[0012] T i =DConv(P)
[0013] Among them, T i represents the output feature map of the i-th (i = 1, 2, 3) branch, DConv represents the dilated convolution operation, and P represents the input feature map;
[0014] The feature maps obtained from the three branches are concatenated, and then the number of channels is restored through a 1×1 convolution to obtain the feature map U, where U = [u1, u2, ..., u]. c ]∈R c×H×W Where C, H, and W represent the number of channels, height, and width of the feature map U, respectively;
[0015] The formula for generating feature map U is:
[0016] U = F1([T1, T2, T3])
[0017] Where [·,·,·] represents the concatenation operation of three feature maps T1, T2, and T3 in the channel dimension, and F1 represents the 1×1 convolution transformation function.
[0018] The feature map U is then divided into horizontal and vertical directions, and each channel is encoded using pooling layers with kernel sizes of (H, 1) and (1, W) respectively, to obtain the output of each channel in both directions;
[0019]
[0020]
[0021]
[0022]
[0023] Where H and W are the height and width of the feature map U, respectively. This represents the output of the c-th channel at height h, z h This represents the horizontal feature map obtained from the encoding. For the output of the c-th channel with width w, z w This represents the feature map obtained in the vertical direction after encoding.
[0024] Next, aggregate the feature map z h and z w The data is concatenated, reduced in dimensionality using a shared 1×1 convolution, and then batch normalized before being fed into an activation function to obtain the feature map f, which is:
[0025] f=δ(F1([z h , z w ]))
[0026] Where δ represents a nonlinear activation function, f represents intermediate feature maps obtained by encoding spatial information in the horizontal and vertical directions, and f∈R C / r×(H+W) r is the scaling factor that controls the size of the control module; r is set to 32.
[0027] Next, the feature map f is split into two separate tensors f. h and f w , where f h ∈R C / r×H f w ∈R C / r×W ; Use two 1×1 convolution transformation functions F respectively h and F wThe number of channels is restored to match the input feature map U; after passing through the Sigmoid activation function, the attention weights g of the feature map in height and width are obtained respectively. h and g w ;
[0028] have:
[0029] g h =σ(F h (f h ));
[0030] g w =σ(F w (f w ));
[0031] Where σ represents the Sigmoid activation function, g h ∈R C×H×1 g w ∈R C×1×W .
[0032] Finally, the output feature map Y of the hollow coordinated attention mechanism module is obtained by multiplicative weighted calculation on the original feature map, Y = [y1, y2, ..., y]. c ]∈R CxH×W ,have:
[0033]
[0034] Reconstructing the bidirectional feature pyramid (Re-BiFPN) is used as the feature extraction network to fuse feature maps of different scales. Based on BiFPN, cross-scale connections are added to nodes with two inputs to ensure that each node contains at least three inputs, effectively reducing the loss of feature information.
[0035] Re-BiFPN adds skip connections between high-level input nodes to low-level nodes, fusing rich semantic information from high-level feature maps. It also adds connections between low-level nodes to high-level nodes, leveraging the high resolution of low-level feature maps to fuse rich contour and edge information from low-level feature maps with high-level feature maps.
[0036] In Re-BiFPN, a total of three layers of input nodes and three layers of output nodes are set up;
[0037] Large target detection layer Input feature map of size 80×80 in the same layer Low-level 40×40 input feature map and Convolution The three feature maps are fused to obtain:
[0038] Intermediate target detection layer Input feature maps of size 40×40 in the same layer Convolution and a large target detection layer with a size of 80×80 The feature map is obtained by feature fusion of the three feature maps;
[0039] Small target detection layer Feature map of size 20×20 in the same layer Output feature map of 40×40 size for high-rise buildings and Convolution The feature fusion is performed to obtain the result.
[0040] The output expression of the three-layer detection layer is:
[0041]
[0042]
[0043]
[0044]
[0045] In the formula, and These represent the input layer and detection layer, respectively, of an 80×80 feature map of the upper layer. and These represent the input layer and detection layer, respectively, of the 40×40 feature map in the intermediate layer. and These represent the input layer and detection layer, respectively, of the 40×40 feature map at the lower level. represent The intermediate feature layer obtained by convolution, w i ,w″ i ,w′″ i (i = 1, 2, 3) represent the weights of different nodes obtained from network training, respectively, in each w i Then, the ReLU activation function is used to ensure the weights w i The value of the output weight is ≥0, and the value is controlled between 0 and 1 through regularization. The learning rate is set to 0.0001 to avoid numerical instability. Conv represents the convolution operation and Resize represents the sampling operation.
[0046] Beneficial effects:
[0047] Detecting helmet wearing status among non-motorized vehicle riders is crucial for traffic control. Currently, most helmet detection methods are susceptible to interference from complex backgrounds, exhibiting low accuracy and poor robustness in small target detection, making them unsuitable for practical applications. To address these issues, this invention proposes a novel helmet-wearing detection algorithm, YOLOv5s-DR, based on the YOLOv5s model. Firstly, a Dilated Convolution InCoordinate Attention (DICA) mechanism is added to the backbone network. This increases the network's receptive field, allowing it to acquire more contextual information. Simultaneously, it reduces the network's learning of unnecessary background features, focusing on smaller targets. Secondly, a Rebuild Bidirectional Feature Pyramid Network (Re-BiFPN) is used as the feature extraction network. Cross-scale feature fusion combines high-level semantic information features with low-level spatial information features, facilitating the model's learning of target features at different scales. The results were validated on the proposed HelmetWearing dataset for Non-motor vehicle Drivers (HWND), and the results show that the proposed model outperforms current detection algorithms and can achieve accurate detection of targets in complex backgrounds with an accuracy of 94.3%.
[0048] This invention first creates a new dataset, HWND, containing different image attributes (e.g., different categories, different angles, different weather conditions, etc.) to reproduce the real environment of the detection scene as accurately as possible. Furthermore, this invention selects and improves upon the YOLOv5s network, a single-stage detection algorithm known for its high accuracy and speed, to achieve intelligent detection of helmet wearing by non-motorized vehicle riders. The main contributions of this invention are as follows:
[0049] 1. A dataset on helmet wearing among non-motorized vehicle riders was created. Part of the dataset comes from images taken in real traffic scenarios during this invention process. It contains 1332 high-quality images with multiple targets, multiple categories, and complex backgrounds. The images cover non-motorized vehicle riders under various road conditions, angles, lighting conditions, and levels of congestion. Another part comes from the public dataset "BikeHelmetsDetection," containing 764 images.
[0050] 2. A helmet-wearing detection model for non-motorized vehicle riders, YOLOv5s-DR, is proposed. This invention combines dilated convolution with an attention mechanism to increase the receptive field, allowing the network to acquire more information. Simultaneously, it establishes dependencies between target features in both channel and spatial dimensions, enabling the model to focus more on small targets such as helmets and heads, thus enhancing the network's ability to detect small targets. Feature extraction is performed using a reconstructed bidirectional feature pyramid, and feature fusion is performed across scales. The fused feature map contains rich semantic and positional information at different levels. Attached Figure Description
[0051] Figure 1 This is a partial instance diagram of the training sample set;
[0052] Figure 2 For the validation set samples, where Figure 2 (a) shows various helmet samples. Figure 2 (b) consists of various non-helmet samples (interference set);
[0053] Figure 3 A comparison chart showing the number of labels in the augmented dataset;
[0054] Figure 4 This is a diagram of the YOLOv5 network structure.
[0055] Figure 5 This is a diagram of the network component structure.
[0056] Figure 6 This is a diagram of the YOLOv5s-DR network structure.
[0057] Figure 7 Flowchart of the DICA module;
[0058] Figure 8 For various feature extraction networks; where (ad represents FPN, PANet, BiFPN and Re-BiFPN respectively).
[0059] Figure 9 A comparison chart of accuracy for each category across different models;
[0060] Figure 10 This is a sample image set of test results for YOLOv5s-DR (where af represents the test results under various conditions). Detailed Implementation
[0061] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments:
[0062] Example 1:
[0063] Dataset
[0064] This invention proposes a high-quality helmet-wearing detection dataset for non-motor vehicle drivers, named "Helmet Wearing dataset for Non-motor vehicle Drivers (HWND)," primarily covering electric bicycles. HWND consists of two parts: one is the publicly available dataset "BikeHelmets Detection" from Kaggle, and the other is self-captured images, totaling 2096 JPG images. The process of creating the benchmark dataset and its composition are described below.
[0065] Image filtering and annotation
[0066] A portion of the dataset consists of images provided by this invention. First, these images were filtered, removing samples with similar content or a single target. High-quality images with a large number of targets, diverse categories, and complex backgrounds were retained. The filtered dataset contains 1332 images. These images include non-motorized vehicle riders from different time periods, on different roads, at different angles, and under different lighting conditions, with a resolution of 4032×3024 pixels. The images were manually labeled by category using LabelImg software: electric vehicles were labeled "non-motor," helmets worn by riders were labeled "helmet," and riders not wearing helmets or wearing hats were labeled "head." Finally, this invention reconstructed all labeled coordinates onto the images and manually verified each one. Each image ultimately generates a corresponding XML annotation file, containing information such as the image filename, target category name, and the target's bounding box coordinates.
[0067] The other part is the publicly available dataset "BikeHelmetsDetection" from Kaggle's official website. This dataset contains 764 images of cyclists wearing helmets and their XML-formatted annotation files, including two categories: "Withhelmet" and "Withouthelmet". To standardize the label names, this invention modifies them to "helmet" and "head" respectively.
[0068] Dataset Description
[0069] The experiment used 1757 images as the training set, including 1070 self-taken images and 687 images from the "BikeHelmetsDetection" dataset. To increase the diversity of the training set, the photos taken in this invention included various scenarios. Images of non-motorized vehicle riders were acquired under various road conditions, including intersections, non-motorized vehicle lanes, and sidewalks. Images were acquired from various angles, including front, rear, and side views. Images of various riding situations were acquired, including single riders, two-person riders, and three-person riders. Images of various types of electric bicycles were acquired, including shared bicycles, ordinary household electric bicycles, and delivery electric bicycles. Images under various lighting intensities were acquired, including bright sunlight on sunny days, dim light on cloudy days, and tree shadows. Images of various types of clothing were acquired, including helmets and ordinary hats. Images with backgrounds of varying complexity were acquired, including scenes with high traffic density, scenes where the target color is similar to the background color, and scenes with many obstructions. The training set samples are shown below. Figure 1 .
[0070] A validation set of 339 images was selected, including 262 self-taken images and 77 images from "BikeHelmetsDetection". The images in the validation set included helmets of various colors and shapes. There were also various distracting scenarios, such as helmets worn with baseball caps or sun hats, and helmets placed inside bicycle baskets. This diverse validation set helps to comprehensively evaluate the model. The validation set samples are shown below. Figure 2 As shown.
[0071] Considering the impact of complex road conditions on helmet detection in real-world scenarios, methods such as horizontal flipping, random rotation, altering image brightness and contrast, and adding noise were used to increase the training set to 14056 images. The number of images per label in the dataset is as follows: Figure 3 As shown.
[0072] YOLOv5
[0073] YOLOv5 is a one-stage object detection algorithm proposed by the Ultralytics team in 2020. It significantly improves both detection accuracy and speed, reducing the weight file to 1 / 9 of YOLOv4. Four official versions of the detection network are released: YOLOv5s, YOLOv5m, YOLOv51, and YOLOv5x. YOLOv5s has the smallest network depth and feature map width; the other three versions are deeper and wider versions of YOLOv5s. This invention uses the smallest YOLOv5s network to detect helmet wearing status among non-motorized vehicle riders. The YOLOv5s structure is as follows: Figure 4As shown, it is mainly divided into four parts: the input end for reading images, the backbone network for feature extraction, the neck network for feature fusion, and the output end for predicting the target.
[0074] The input images are preprocessed using an adaptive anchor box calculation method, which adaptively calculates the optimal anchor box values before each training iteration. An adaptive image scaling method is used to resize the input images to a fixed size of 640×640. Simultaneously, Mosaic data augmentation is used during training to expand the dataset online.
[0075] The backbone network uses Focus, Cross Stage Partial (CSP), and Spatial Pyramid Pooling (SPP). Figure 5 This section demonstrates the structure of the basic components of the YOLOv5 network. The Focus structure slices a 640×640×3 image, transforming the planar information of the image into a channel dimension, resulting in a 320×320×12 feature map. The Focus module replaces convolutional operations to implement downsampling, ensuring information integrity while reducing computational cost. CSP enables cross-layer connections, increasing network depth, improving the network's ability to learn features, and reducing model size. The YOLOv5 network uses different CSP structures in the Backbone and Neck parts to enhance the network's feature fusion capabilities. In the Backbone, this is represented as CSP1_X, and in the Neck, as CSP2_X. The difference lies in the fact that CSP2_X does not use residual components. The SPP module extracts and fuses high-level features without changing the feature map size, improving the network's convergence.
[0076] The Neck section combines a Feature Pyramid Network (FPN) with a Path Aggregation Network (PANet). The FPN transmits strong semantic features from top to bottom, while the PANet transmits strong localization information from bottom to top. Finally, the extracted features are fused and passed to the prediction layer.
[0077] The prediction section is responsible for generating the bounding boxes and categories of the targets. The bounding box loss function uses CompleteIntersection over Union_Loss (CIoU_Loss). Non-maximum suppression (NMS) is used to filter multiple predicted boxes, retaining those with high confidence. The final output consists of three feature maps of different sizes: 80×80, 40×40, and 20×20, corresponding to the predictions of small, medium, and large targets, respectively.
[0078] YOLOv5s-DR
[0079] To address the issues of low accuracy, poor robustness, and high computational cost in current helmet detection algorithms, this invention optimizes the YOLOv5s network and proposes the YOLOv5s-DR model, with the following structure: Figure 6 This invention adds the DICA mechanism before the SPP module, replacing the original CBL module, and sets the DICA stride to 2 to achieve feature map downsampling. DICA combines dilated convolution with the CA mechanism to obtain denser information by expanding the receptive field. The attention mechanism ignores irrelevant information in the background, improving the network's focus on small targets. Re-BiFPN is used for feature extraction, removing nodes without feature fusion and adding a cross-scale feature extraction layer to improve the model's feature fusion capability. The DICA mechanism and Re-BiFPN proposed in this invention are described in detail below.
[0080] Hollow Coordination Attention Mechanism
[0081] In computer vision tasks, there is always information closely related to the research and some irrelevant information. Attention mechanisms can help algorithms focus on analyzing important information while ignoring irrelevant information. In recent years, attention mechanisms have been widely used in various tasks such as semantic segmentation, image classification, and object detection, achieving significant results. However, most attention mechanisms have limited receptive fields and are not easy to capture contextual information at different scales. Therefore, this invention proposes a Dilated Convolution In Coordinate Attention (DICA) mechanism, combining dilated convolution with Coordinate Attention (CA). A multi-branch dilated convolution structure is used, with different dilation rates set to obtain multi-scale feature information. The DICA mechanism structure is as follows: Figure 7 As shown.
[0082] First, dilated convolutions are performed on the input feature map to obtain a larger receptive field. In this invention, the added dilated convolution structure is configured with a kernel size of 3×3, a stride of 2, and dilation rates of 1, 2, and 3, respectively, resulting in receptive fields of 3×3, 5×5, and 7×7. The feature maps obtained after the three-branch convolution have the same number of channels as the input feature map, but their size is reduced by half.
[0083] T i =DConv(P)#(1)
[0084] In Formula 1, T i represents the output feature map of the i-th (i = 1, 2, 3) branch, DConv represents the dilated convolution operation, and P represents the input feature map.
[0085] The feature maps obtained from the three branches are concatenated (Concat), and then the number of channels is restored through a 1×1 convolution to obtain feature map U. As shown in Equation 2, [·,·,·] represents the concatenation operation of the three feature maps T1, T2, and T3 in the channel dimension, and F1 represents the 1×1 convolution transformation function.
[0086] U=F1([T1,T2,T3])#(2)
[0087] Next, the feature map U is divided into horizontal and vertical directions, and each channel is encoded using pooling layers with kernel sizes of (H, 1) and (1, W) respectively, resulting in the output for each channel in both directions. The calculation process is shown in Equations 3 and 4.
[0088]
[0089]
[0090] Where H and W are the height and width of the feature map U, respectively. This represents the output of the c-th channel at height h. This is the output of the c-th channel with width w.
[0091] Next, the aggregated feature map z generated by formulas 3 and 4 will be... h and z w After performing concat, dimensionality reduction using a shared 1×1 convolution is applied, followed by batch normalization. Finally, the result is fed into an activation function to obtain the feature map f. In Equation 5, δ represents the non-linear activation function, f represents the intermediate feature map obtained by encoding spatial information in the horizontal and vertical directions, and f∈R. C / r×(H+W) r is the scaling factor of the control module size, which is set to 32 in the experiment.
[0092] f=δ(F1([z h, z w ]))#(5)
[0093] Next, the feature map f is split into two separate tensors, resulting in fi. h ∈R C / r×H and f w ∈R C / r×W Two 1×1 convolution transformation functions F are used respectively. h and F w The number of channels is restored to match the input feature map U. After passing through the Sigmoid activation function, the attention weights g of the feature map in height and width are obtained respectively. h and g w The detailed expression is shown in Equations 6 and 7, where σ represents the Sigmoid activation function.
[0094] g h =σ(F h (f h ))#(6)
[0095] g w =σ(F w (fw))#(7)
[0096] Finally, the output feature map Y of DICAblock is obtained by multiplicative weighted calculation on the original feature map, as shown in the formula below.
[0097]
[0098] This invention adds the DICA module to the backbone, placing it before the SPP module to replace the original CBL module. The DICA mechanism sets different dilation rates for the multi-branch dilated convolutional network, expanding the receptive field at different scales. The convolutional feature map obtains more high-resolution information from the shallow feature maps. Then, the channel and position information of the feature map are encoded simultaneously to obtain attention feature maps in both horizontal and vertical directions. Each element of the feature map can intuitively reflect whether the target exists in the corresponding row and column.
[0099] Reconstructing the bidirectional feature pyramid
[0100] The dataset proposed in this invention contains a large number of helmet and head labels. These small targets have few pixel values and their feature information is not obvious. As the number of network layers increases, excessive convolutions can lead to a reduction or even disappearance of feature information for small targets. Therefore, to improve the feature representation capability of small targets, this invention proposes a RebuildBidirectional Feature Pyramid Network (Re-BiFPN) to fuse feature maps of different scales. Based on BiFPN, cross-scale connections are added to nodes with two inputs to ensure that each node contains at least three inputs, effectively reducing the loss of feature information. Figure 8 The Re-BiFPN of this invention is compared with the structures of other feature extraction networks.
[0101] The Re-BiFPN proposed in this invention adds skip connections to higher-level input nodes to the lower-level nodes, such as... Figure 8 As shown by the dashed arrows pointing downwards, this incorporates rich semantic information from high-level feature maps. Connections to lower-level nodes are added to high-level nodes. Figure 8 As shown by the dashed arrows pointing upwards from the bottom, this method leverages the high resolution of low-level feature maps to fuse rich contour, edge, and other information from them with higher-level feature maps.
[0102] In Bi-FPN, the original large target detection layer Feature map of the same layer with dimensions of 80×80 The convolution with the lower-level 40×40 feature map is obtained Feature fusion is performed to obtain, The expression is shown in Equation 9. The original small target detection layer. Feature map of size 20×20 in the same layer Output feature map of 40×40 size for high-rise buildings The feature fusion is performed to obtain the result. Re-BiFPN adds one more input line to this. and The passage, finally The output is expressed as in Formula 10, Formula 11, and Formula 12.
[0103]
[0104]
[0105]
[0106]
[0107] In the formula, w i The weights represent those obtained during network training, in each wi Then, the ReLU activation function is used to ensure the weights w i The value of the output weights is set to ≥0, and regularization is used to control the value between 0 and 1. The learning rate is set to 0.0001 to avoid numerical instability. This represents the intermediate feature layer of the fourth layer in the top-down path. Conv represents the convolution operation, and Resize represents the upsampling or downsampling operation.
[0108] Experimental Results and Analysis
[0109] This section describes the experimental setup and implementation details. To evaluate the effectiveness of the proposed module, several ablation studies were conducted. The proposed method was evaluated for the task of detecting helmet use by non-motorized vehicle riders and compared with other target detection algorithms.
[0110] Experimental setup and training
[0111] In this experiment, the momentum was set to 0.937, the weight decay rate to 0.005, and the initial learning rate to 0.001, using the SGD optimizer. Before training, the K-means algorithm was used to recalculate the anchor values of the model, resulting in optimal anchor values of (7, 9), (13, 18), (21, 30), (28, 39), (38, 57), (52, 86), (80, 122), (138, 197), and (230, 309). Because this experiment improved the original YOLOv5s network structure, the official pre-trained weights could not be used. Therefore, this invention retrained the improved YOLOv5s-DR model on the dataset. The batch size was set to 32, and the iterations were 200 rounds. Training platform parameters are detailed in Table 1.
[0112] Table 1: Experimental Hardware and Software Platform
[0113]
[0114] ablation experiment of YOLOv5s-DR
[0115] To explore the impact of different improvement methods on the model, the DICA module and Re-biFPN were applied sequentially to the original YOLOv5s model to evaluate the rationality and effectiveness of the proposed methods. Table 2 shows the test results.
[0116] Table 2: Ablation Experiment
[0117]
[0118] Analyzing Table 2, compared to the original YOLOv5s, adding the DICA module improved mAP by 2%. Using Re-BiFPN for feature fusion improved mAP by 1.1%. Combining the two components improved mAP by 2.3%. Comparisons were made for different target categories, such as... Figure 9 As shown, the accuracy improved for targets of different scales. For small targets such as helmets and heads, the addition of the DICA module resulted in improvements of 2.2% and 1.6%, respectively. Experimental results indicate that the DICA module preserves detailed information while increasing the receptive field, effectively improving the network's feature extraction capability. Integrating spatial and channel information of feature maps at a larger scale makes it easier to capture the feature information of small targets, effectively improving the network's focus on small targets. The use of the Re-biFPN module resulted in improvements of 0.9% and 1.2% for small targets such as helmets and heads, respectively. Experimental results show that the improved Re-BiFPN obtains richer contextual information, enhances the feature representation capability of small targets, and effectively improves the accuracy of helmet and head detection.
[0119] Visualize the test results, such as Figure 10 As shown. Figure 10 (a), (b), and (f) demonstrate that the target can be accurately detected even when multiple non-motorized vehicles obstruct the view or have incomplete outlines. Figure 10 In (c), accurate detection can be achieved even when the target is at a relatively far distance. Figure 10 In (d), when the target is in shadow and its color is similar to the background, small targets such as helmets are accurately detected. Figure 10 In (e), the sun hat was not mistakenly classified as a helmet. These experimental results demonstrate that YOLOv5s-DR can effectively distinguish between ordinary hats and helmets, and can efficiently detect targets of different scales even against complex backgrounds.
[0120] Performance comparison of different models
[0121] To further analyze the detection performance of the YOLOv5s-DR model, our data was tested on other object detection models, such as YOLOv5s, Faster-RCNN, and YOLOv4. Comparing and analyzing the experimental results, our model achieves a 2.3% higher mAP than YOLOv5s, a 33.2% higher mAP than Faster-RCNN, and a 26.3% higher mAP than YOLOv4. Detailed metric comparisons are shown in Table 3. Experiments demonstrate that the proposed YOLOv5s-DR model effectively improves object detection accuracy to 94.3%. It can recognize 81 images per second, meeting the requirements for real-time detection and can be applied to traffic monitoring in practical scenarios.
[0122] Table 3: Performance Comparison of Different Models
[0123]
[0124] Summarize
[0125] This invention proposes a helmet-wearing detection dataset for non-motorized vehicle riders called HWND. It includes 1332 images captured using this invention and 764 real helmet-wearing images from publicly available datasets, with detailed annotations. A helmet-wearing detection model for non-motorized vehicle riders, YOLOv5s-DR, is also proposed. This model incorporates a DICA mechanism combining dilated convolution and attention in YOLOv5. This expands the receptive field, facilitating the extraction of high-level semantic features, and enhances the network's ability to model dependencies between channels and utilize location information to acquire features of regions of interest, thereby extracting more accurate information and effectively improving the model's feature representation capabilities. Furthermore, to enhance the network's feature fusion capabilities, a reconstructed bidirectional feature pyramid (Re-BiFPN) is used for feature extraction, reducing computational cost while enriching the contextual information in the feature maps. To verify the performance of the proposed method, it is tested on the HWND dataset. Experimental results show that the proposed method effectively improves the accuracy of helmet detection while meeting real-time detection requirements, providing an effective solution for helmet-wearing detection of non-motorized vehicle riders in real-world scenarios.
Claims
1. A YOLOv5s-based helmet-wearing detection method, characterized in that, The helmet wearing image is processed based on a YOLOv5s model, and a cavity coordination attention mechanism is added to the backbone network; The cavity coordination attention mechanism combines the cavity convolution and the coordination attention mechanism, adopts a multi-branch cavity convolution structure, sets different expansion rates, and obtains multi-scale feature information. Dilated convolution is performed on the input feature map to obtain a larger receptive field, the dilated convolution structure is set to a convolution kernel size of 3*3, a step of 2, and expansion rates of 1, 2 and 3, and the receptive fields after convolution are 3*3, 5*5 and 7*7 respectively; the feature maps obtained after convolution of the three branches have the same channel number as the input feature map, but the size is reduced by 1 / 2; T i = DConv(P) wherein T i represents the output feature map of the i-th (i = 1, 2, 3) branch, DConv represents a dilated convolution operation, and P represents an input feature map; The three branch feature maps are spliced, and the channel number is restored through 1x1 convolution to obtain a feature map U, U=[u1, u2, …, u c ]∈R C×H×W , wherein C, H, and W represent the channel number, height, and width of the feature map U, respectively. The generation formula of the feature map U is: U=F1([T1,T2,T3]) Where [·,·,·] represents the concatenation operation of the three feature maps T1, T2 and T3 in the channel dimension, and F1 represents a 1*1 convolution transformation function; Then the feature map U is divided into horizontal and vertical directions, and a pooling layer with a kernel size of (H, 1) and (1, W) is used to encode each channel respectively to obtain the output of each channel in the two directions. wherein H, W are height and width of the feature map U, respectively, denotes the output of the c-th channel of height h, z h denotes the encoded horizontal feature map, denotes the output of the c-th channel of width w, z w denotes the encoded vertical feature map; Then the aggregated feature map z h and z w are spliced, dimensionally reduced using a shared 1x1 convolution, batch normalized, and finally fed into an activation function to obtain a feature map f, which has: f = δ(F1([z h , z w ])) Wherein, δ represents a nonlinear activation function, f represents an intermediate feature map obtained by encoding spatial information in the horizontal direction and the vertical direction, and f∈R C / r×(H+W) r is a reduction rate of the size of the control module, and r is set to 32. Then the feature map f is divided into two separate tensors f h and f w , where f h ∈R C / r×H , f w ∈R C / r×W ; the channel number is restored to be consistent with the input feature map U using two 1x1 convolution transformation functions F h and F w , respectively; and the attention weights g h and g w of the feature map in the height and width directions are obtained after passing through the Sigmoid activation function, respectively; There are: g h = σ (F h (f h )) ; g w = σ (F w (f w )) ; wherein σ denotes a sigmoid activation function, g h ∈R C×H×1 , g w ∈R C×1×W ; Finally, the output feature map Y of the cavity coordination attention mechanism module is obtained by multiplication weighting calculation on the original feature map, Y = [y1, y2, …, y c ]∈R C×H×W , and has:
2. The YOLOv5s-based helmet-wearing detection method of claim 1, wherein, Re-BiFPN is used as the feature extraction network to fuse feature maps of different scales, and cross-scale connections are added to the nodes with two inputs based on BiFPN to ensure that each node contains at least three inputs, effectively reducing the loss of feature information.
3. The YOLOv5s-based helmet-wearing detection method of claim 2, wherein, Re-BiFPN adds a skip connection from the high-level input node to the bottom node, fuses the rich semantic information of the high-level feature map, adds a connection from the low-level node to the high-level node, and utilizes the high resolution of the low-level feature map to fuse the rich contour and edge information of the low-level feature map with the high-level feature map.
4. The helmet wearing detection method based on YOLOv5s according to claim 3, characterized in that In Re-BiFPN, three layers of input nodes and three layers of output nodes are set; Large target detection layer from the same layer 80x80 size input feature map Low layer 40x40 size input feature map And Convolution obtained Three feature maps are fused to obtain; intermediate target detection layer from the input feature map of the same layer 40x40 size convolution and the large target detection layer of 80x80 size feature fusion is performed on the three feature maps Small target detection layer From the same layer 20x20 size feature map High layer 40x40 size output feature map And Convolution gets Feature fusion is carried out The output expression of the three detection layers is: In the formula, and These represent the input layer and detection layer, respectively, of an 80×80 feature map of the upper layer. and These represent the input layer and detection layer, respectively, of the 40×40 feature map in the intermediate layer. and These represent the input layer and detection layer, respectively, of the lower-level 40×40 feature map. represent The intermediate feature layer obtained by convolution, w i ,w″ i w″′i (i = 1, 2, 3) represent the weights of different nodes obtained from network training, respectively. i Then, the ReLU activation function is used to ensure the weights w i The value of the output weight is ≥0, and the value is controlled between 0 and 1 through regularization. The learning rate is set to 0.0001 to avoid numerical instability. Conv represents the convolution operation and Resize represents the sampling operation.
Citation Information
Patent Citations
A helmet detection method with lightweight backbone based on yolov3 network
AU2020100705A4
Safety helmet wearing detection method and device based on deep learning, equipment and medium
CN114782986A