Safety helmet wearing detection method, device and equipment and readable storage medium
By introducing the Swin Transformer module, the Ghost module and the attention mechanism ECA into the YOLOv8 model, the problem of difficulty in identifying the wearing position of the helmet at the tunnel construction site was solved, and the accurate judgment of the helmet wearing status of the construction workers was achieved, which improved the safety of the construction site. Security.
Patent Information
- Application Number
- CN202410913585.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-08-30
AI Technical Summary
Existing technology makes it difficult to accurately identify whether construction workers are wearing safety helmets at tunnel construction sites. Especially when the safety helmets are placed on the back of the body or underground, image detection cannot distinguish the wearing position, leading to potential safety hazards.
The YOLOv8 model is used, combined with the Swin Transformer module, the Ghost module and the attention mechanism ECA, to perform image processing to identify whether the construction worker is wearing a helmet in the head area, and determine the wearing status of the helmet through feature extraction and fusion.
It improves the accuracy and reliability of helmet wearing detection, ensures that all identified helmets are worn on the heads of construction workers, and enhances the safety of the construction site.
Smart Images

Figure CN118570737A
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and more specifically, to a helmet wearing detection method, device, equipment and readable storage medium. Background Art
[0002] In tunnel construction sites, wearing a helmet can effectively prevent and reduce accidental injuries to construction workers during the operation process. Based on this, in order to ensure construction safety, the existing technology adds a helmet detection technology to tunnel construction operations.
[0003] However, the detection process of the prior art is to use a neural network to detect whether there is a helmet in the image. If there is, it is determined that the construction worker is wearing a helmet. However, the presence of a helmet in the image does not mean that the construction worker is wearing a helmet. The construction worker may place the helmet on the back of the body or underground, which may cause the presence of a helmet in the image. Therefore, it is of great significance to provide a detection method for identifying whether a helmet is worn on the head of a construction worker. Summary of the invention
[0004] In view of this, the present application provides a safety helmet wearing detection method, device, equipment and readable storage medium for identifying whether the safety helmet is worn on the head of a construction worker.
[0005] In order to achieve the above objectives, the proposed solution is as follows:
[0006] A method for detecting the wearing of a safety helmet, comprising:
[0007] Obtain a tunnel image to be detected containing construction workers and a helmet recognition model, wherein the helmet recognition model is a trained YOLOv8 model with a Swin Transformer module added to the Backbone layer and a Ghost module and an attention mechanism ECA added to the Neck layer;
[0008] The helmet recognition model is used to locate the head of the tunnel image to be detected, and a target detection frame corresponding to each head area is generated in the tunnel image to be detected; the Backbone layer with a Swin Transformer module is used to extract features of the head area calibrated by each target detection frame to obtain multiple detection features; the Neck layer with a Ghost module and an attention mechanism ECA is used to fuse multiple detection features to obtain fused features corresponding to each head area; based on the fused features of each head area, it is judged whether the tunnel image to be detected indicates that there are construction workers who are not wearing helmets.
[0009] Optionally, obtain a helmet recognition model, including:
[0010] Build the YOLOv8 model;
[0011] Adding a Swin Transformer module to the Backbone layer of the YOLOv8 model, and adding a Ghost module and an attention mechanism ECA to the Neck layer to form a target YOLOv8 model;
[0012] Two types of training images are obtained, one type of training images is an image of a tunnel without construction workers, and the other type of training images contains one or more bounding boxes for marking the head area, and each head area has a label indicating whether the corresponding head area is wearing a helmet;
[0013] The target YOLOv8 model is trained using each training image in turn, and the target YOLOv8 model finally trained is used as a helmet recognition model.
[0014] Optionally, a Swin Transformer module is added to the Backbone layer of the YOLOv8 model, including:
[0015] A SwinTransformer module is added after the multiple conv structures at the Backbone level of the YOLOv8 model.
[0016] Optionally, the Ghost module and the attention mechanism ECA are added in the Neck layer, including:
[0017] Use the Ghost module to replace the convolutional block of the C2f structure in the Neck layer;
[0018] The attention mechanism ECA is added to the Neck layer as the neighborhood connection structure of the Concat structure in the Neck layer.
[0019] Optionally, the acquiring two types of training images includes:
[0020] Using web crawler technology, multiple tunnel images were screened from various websites and image datasets;
[0021] For each tunnel image, determine whether there are construction workers in the tunnel image. If so, add a bounding box to mark the head area in the tunnel image. Evaluate whether each head area is wearing a safety helmet. If so, add a safety helmet label to the corresponding head area. If not, add a no-safety helmet label to the corresponding head area.
[0022] Optionally, the training of the target YOLOv8 model using each training image in turn includes:
[0023] Input each training image into the target YOLOv8 model in turn, use the target YOLOv8 model to predict the head area in each training image, and predict whether a helmet is worn in each head area, and generate a prediction result corresponding to each training image;
[0024] Based on each training image and its corresponding prediction result, the loss value is calculated, and the loss value is used to adjust the parameters of the Backbone layer with the Swin Transformer module added and the Neck layer with the Ghost module and the attention mechanism ECA added.
[0025] Optionally, also include:
[0026] When the image of the tunnel to be detected shows that there are construction workers who are not wearing safety helmets, a warning is issued.
[0027] A safety helmet wearing detection device, comprising:
[0028] An acquisition module is used to acquire a tunnel image to be detected containing construction workers and a helmet recognition model, wherein the helmet recognition model is a trained YOLOv8 model with a Swin Transformer module added to the Backbone layer and a Ghost module and an attention mechanism ECA added to the Neck layer;
[0029] A judgment module is used to use the helmet recognition model to perform head positioning on the tunnel image to be detected, and generate a target detection frame corresponding to each head area in the tunnel image to be detected; use the Backbone layer with the SwinTransformer module added to perform feature extraction on the head area calibrated by each target detection frame to obtain multiple detection features; use the Neck layer with the Ghost module and the attention mechanism ECA added to perform feature fusion on the multiple detection features to obtain the fusion feature corresponding to each head area; based on the fusion feature of each head area, it is judged whether the tunnel image to be detected indicates that there are construction workers who are not wearing helmets.
[0030] A helmet wearing detection device comprises a memory and a processor;
[0031] The memory is used to store programs;
[0032] The processor is used to execute the program to implement the various steps of the above-mentioned helmet wearing detection method.
[0033] A readable storage medium stores a computer program thereon, characterized in that when the computer program is executed by a processor, each step of the above-mentioned helmet wearing detection method is implemented.
[0034] It can be seen from the above technical solutions that the helmet wearing detection method provided by the present application can obtain a tunnel image to be detected containing construction workers, and use the helmet recognition model to locate the head of the tunnel image to be detected, and generate a target detection frame corresponding to each head area in the tunnel image to be detected; use the Backbone layer with the Swin Transformer module added to the helmet recognition model to extract features of the head area calibrated by each target detection frame to obtain multiple detection features; use the Neck layer with the Ghost module and the attention mechanism ECA added to the helmet recognition model to fuse multiple detection features to obtain fused features corresponding to each head area; based on the fused features of each head area, it is judged whether the tunnel image to be detected indicates that there are construction workers who are not wearing helmets. Based on this, the helmet recognition model can be used to first locate the head area of the construction workers in the tunnel image to be detected, and then evaluate whether the head area is wearing a helmet, which can ensure that all identified helmets are worn on the heads of construction workers, and confirm that the helmets are worn on the heads of construction workers. In addition, this application uses a trained YOLOv8 model with a SwinTransformer module added to the Backbone level and a Ghost module and an attention mechanism ECA added to the Neck level for image detection. The combination of the Swin Transformer module, the Ghost module and the attention mechanism ECA can integrate the self-attention mechanism, the adaptive adjustment of channel weights and the cross-scale feature fusion, so as to improve the key feature capture capability of the model and the detection capability of targets of different sizes, and further improve the detection reliability and detection accuracy of this application. It can be seen that this application can accurately determine whether each construction worker in the tunnel wears a helmet on his head, ensuring the safety of the construction work. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0036] Figure 1 A flowchart of a helmet wearing detection method disclosed in an embodiment of the present application;
[0037] Figure 2 A schematic diagram of a helmet recognition model structure provided in an embodiment of the present application;
[0038] Figure 3 A schematic diagram of the structure of an ECA provided in an embodiment of the present application;
[0039] Figure 4 This is a structural block diagram of a helmet wearing detection device disclosed in an embodiment of the present application;
[0040] Figure 5 This is a hardware structure block diagram of a helmet wearing detection device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0041] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0042] The helmet wearing detection method of the present application can be used in many general or special computing device environments or configurations, such as personal computers, server computers, smart cameras, smart monitoring or portable devices, tablet devices, multi-processor devices, and distributed computing environments including any of the above devices or equipment.
[0043] Next, combine Figure 1 The helmet wearing detection method of the present application is introduced in detail, including the following steps:
[0044] Step S1, obtaining a tunnel image to be detected including construction workers and a helmet recognition model.
[0045] Specifically, the image of the tunnel to be detected can be obtained in a variety of ways. For example, a surveillance video can be intercepted to obtain the image of the tunnel to be detected, or a drone can be used to directly collect the image of the tunnel to be detected.
[0046] The helmet recognition model can be a trained YOLOv8 model with multiple Swin Transformer modules added to the Backbone layer and multiple Ghost modules and multiple attention mechanisms ECA added to the Neck layer, such as Figure 2 shown.
[0047] Among them, the Swin Transformer module can use the Transformer with global information modeling capabilities to build a hierarchical feature map. At the same time, the Swin Transformer module integrates the idea of locality, limits the self-attention calculation to non-overlapping windows, allows the movement of windows for feature interaction, has linear computational complexity, and effectively completes feature extraction.
[0048] The working process of the Swin Transformer module is to perform layer segmentation on the input image of size (H, W, 3), divide each 4×4 adjacent pixels into a patch, and expand them in the channel direction to transform the image dimension into (H / 4, W / 4, 48). Then, the linear embedding layer linearly transforms the channel data of each pixel, transforms the image dimension into (H / 4, W / 4, C), and normalizes the feature dimension. In the process of constructing the hierarchical feature map of the image, the image is downsampled through the tile splicing layer, and the adjacent pixels with an interval of 2 are divided into patches and then the channel splicing operation is performed, so that the scale of the feature map is halved. Subsequently, the normalization layer is used for normalization, and finally the number of channels of the feature map is linearly halved through the fully connected layer to achieve compression and fusion of the feature map. As the network depth increases, the receptive field of the node is also expanding. After constructing feature maps of different scales, the features of the image are extracted. The Swin Transformer module replaces the standard Multi-head self-attention module (MSA) in the traditional Transformer module with a window-based Multi-head self-attention module composed of alternating window Multi-head self-attention layers (W-MSA) and sliding window Multi-head self-attention layers (SW-MSA), which evenly divides the input image into non-overlapping windows and limits the attention calculation to each independent window.
[0049] The Swin Transformer module includes 4 LN layers, one W-MSA layer, one SW-MSA layer, two multilayer perceptrons (MLPs), 4 path dropout layers (DropPath), and 4 residual connection layers. The feature map input to the Swin Transformer module is first normalized by LN, and then the features are extracted by the W-MSA layer. The features obtained by the residual operation are normalized by the LN layer. A two-layer MLP with a GELU nonlinear activation function in the middle performs a linear transformation on the channel dimension, and then uses a residual connection to obtain the output feature, which is then input into a similar structure containing a SW-MSA layer. The role of the path dropout layer is to regularize the multi-branch path of the Swin Transformer module to improve the generalization ability of the model and prevent overfitting. At the same time, the residual connection structure is used to solve the degradation problem in the neural network.
[0050] The W-MSA layer in the Swin Transformer module uses a conventional window partitioning strategy starting from the upper left pixel of the input image, which includes a window partition unit, a window reorganization unit, and an MSA unit. The window partition unit is used to divide the input feature map into multiple non-overlapping independent windows of M×M adjacent pixels; the window reorganization unit is used to restore and splice the Multi-head self-attention features of each independent window into a complete Multi-head Self-attention feature map; the MSA unit is used to perform multi-head scaled dot product attention calculations on each independent window. The calculation steps include: linearly transforming the tile vector of each independent window in the channel dimension to double the number of channels, and dividing it into h subspaces in the feature dimension (h is the number of attention heads); using h different parameter matrices to linearly transform the query Q (Query), key K (Key) and weight V (Value) of each pixel in the h subspaces, and perform scaled dot product attention calculations. The h calculation results are spliced and fused through a learnable weight matrix to combine the feature information learned from different subspaces to obtain the multi-head self-attention feature. Among them, the expression of the scaled dot product attention calculation result of the i-th attention head is shown as follows:
[0051]
[0052] In the formula, , , are the i-th parameter matrices respectively; , , , Attention () is a normalized scaled dot product model, and its expression is as follows:
[0053]
[0054] In the formula, , It is the process of information interaction between different features. The dot product is used to calculate the similarity between different features. Dividing by √d for scaling can ensure the stability of the gradient. At the same time, Add learnable relative position encoding The concatenation and fusion expression of Multi-head self-attention features is as follows:
[0055]
[0056] In order to achieve information transfer between non-overlapping windows, the SW-MSA method can be used to recalculate the self-attention after the window offset, so that the model can learn information across windows. The cyclic shift method is used in SW-MSA, that is, by moving the top M / 2 rows of pixels in the feature map to the bottom, and then moving the leftmost M / 2 columns of pixels to the right, and then using the W-MSA window division method to divide the reorganized feature map into non-overlapping windows, where M is the size of each divided window. Then, through the mask mechanism, the weight coefficients between pixels from non-adjacent areas in each window are set to 0, isolating the invalid information exchange between pixels in non-adjacent areas of the original feature map, thereby limiting the self-attention calculation to each sub-window. Finally, the relative position of the feature map is restored through the reverse cyclic shift operation.
[0057] The Ghost module splits the ordinary convolution layer into two parts. First, it uses several 1×1 convolution kernels to perform point-by-point convolution to generate the intrinsic feature map of the input feature, and then uses layer-by-layer convolution to perform a series of linear transformations to efficiently generate redundant feature maps. The redundant feature map and the intrinsic feature map are then concatenated to obtain a feature map with a similar effect to the ordinary convolution result. Compared with ordinary convolution operations, the Ghost module can effectively reduce model parameters and computational complexity without changing the output feature size and dimension.
[0058] The attention mechanism ECA (efficient channel attention) converts the global feature vector into an attention weight vector by applying a one-dimensional convolution layer, and applies it to the feature map, thereby increasing the weight of important feature channels. The attention mechanism ECA abandons dimensionality reduction and directly converts the input feature map into a 1×1×C tensor through global pooling, and then uses a 1×1 convolution to learn the channel score of the input tensor, where k=3 or 5 adaptively selects the size of the convolution kernel. Then, the weight parameters for each channel are obtained through the Sigmoid activation function, and the obtained weight values are multiplied by the corresponding elements of the original input feature map to obtain a feature map with channel weight values. Compared with other attention mechanisms, the attention mechanism ECA has the advantages of fast calculation speed and small number of parameters, and does not need to explicitly calculate the correlation between features. At the same time, considering the problems of model depth and gradient disappearance as well as better learning of target features, residual connections are introduced to convolve the input and output to obtain the final result, such as Figure 3 shown.
[0059] Step S2, using the helmet recognition model to locate the head of the tunnel image to be detected, and generating a target detection frame corresponding to each head area in the tunnel image to be detected; using the Backbone layer with the Swin Transformer module added, feature extraction is performed on the head area calibrated by each target detection frame to obtain multiple detection features; using the Neck layer with the Ghost module and the attention mechanism ECA added, feature fusion is performed on the multiple detection features to obtain the fusion feature corresponding to each head area; based on the fusion feature of each head area, it is judged whether the tunnel image to be detected indicates that there are construction workers who are not wearing helmets.
[0060] Specifically, the tunnel image to be detected can be input into the helmet recognition model, the head of the tunnel image to be detected can be located, and one or more target detection frames can be added to the tunnel image to be detected. Each target detection frame is used to mark all head areas in the tunnel image to be detected, and each target detection frame has a unique corresponding head area.
[0061] The Backbone layer with the Swin Transformer module added is used to extract features of the head area calibrated by each target detection frame to obtain multiple detection features; the Neck layer with the Ghost module and the attention mechanism ECA added is used to fuse multiple detection features to obtain the fused features corresponding to each head area; the fully connected layer of the safety helmet recognition model is used to judge whether the tunnel image to be detected indicates that there are construction workers who are not wearing safety helmets based on the fused features of each head area.
[0062] It can be seen from the above technical solutions that the helmet wearing detection method provided by the present application can obtain a tunnel image to be detected containing construction workers, and use the helmet recognition model to locate the head of the tunnel image to be detected, and generate a target detection frame corresponding to each head area in the tunnel image to be detected; use the Backbone layer with a Swin Transformer module to extract features of the head area calibrated by each target detection frame to obtain multiple detection features; use the Neck layer with a Ghost module and an attention mechanism ECA to fuse multiple detection features to obtain fused features corresponding to each head area; based on the fused features of each head area, it is judged whether the tunnel image to be detected indicates that there are construction workers who are not wearing helmets. Based on this, the helmet recognition model can be used to first locate the head area of the construction workers in the tunnel image to be detected, and then evaluate whether the head area is wearing a helmet. It can ensure that all identified helmets are worn on the heads of construction workers, and confirm that the helmets are worn on the heads of construction workers. In addition, this application uses a trained YOLOv8 model with a Swin Transformer module added to the Backbone layer and a Ghost module and an attention mechanism ECA added to the Neck layer for image detection.
[0063] Ghost convolution can reduce network complexity, Swin Transformer module can strengthen feature fusion, and attention mechanism ECA can reduce background interference. Based on this, this application combines Swin Transformer module, Ghost module and attention mechanism ECA, which can combine self-attention mechanism, adaptive adjustment of channel weights and cross-scale feature fusion, so as to improve the key feature capture ability of the model and the detection ability of targets of different sizes, and further improve the detection reliability and accuracy of this application. It can be seen that this application can accurately determine whether each construction worker in the tunnel wears a helmet on his head, ensuring the safety of the construction work.
[0064] In some embodiments of the present application, the process of obtaining the helmet recognition model in step S1 is described in detail, and the steps are as follows:
[0065] S10. Build the YOLOv8 model.
[0066] Specifically, an open source YOLOv8 model can be built.
[0067] S11. Add a Swin Transformer module to the Backbone layer of the YOLOv8 model, and add a Ghost module and an attention mechanism ECA to the Neck layer to form a target YOLOv8 model.
[0068] Specifically, the YOLOv8 model can be improved by adding multiple SwinTransformer modules in the Backbone layer, and adding multiple Ghost modules and multiple attention mechanisms ECA in the Neck layer to form a target YOLOv8 model.
[0069] S12. Obtain two types of training images, one type of training images is images of tunnels that do not contain construction workers, and the other type of training images contains one or more bounding boxes for marking head regions, and each head region has a label indicating whether the corresponding head region is wearing a safety helmet.
[0070] Specifically, images that do not contain construction workers can be obtained as one type of training images, and tunnel images that contain one or more bounding boxes for marking head regions and each head region has an annotated label indicating whether the corresponding head region is wearing a helmet can be obtained as another type of training images.
[0071] S13. Use each training image in turn to train the target YOLOv8 model, and use the target YOLOv8 model finally trained as a helmet recognition model.
[0072] Specifically, each training image can be input into the target YOLOv8 model in turn, and the target YOLOv8 model can be trained until the target YOLOv8 model meets the preset stop condition, and the target YOLOv8 model finally trained is used as the helmet recognition model.
[0073] It can be seen from the above technical solution that this embodiment provides an optional way to obtain a helmet recognition model. Through the above method, the helmet recognition model can be better constructed and the recognition reliability of the helmet recognition model can be improved.
[0074] In some embodiments of the present application, the process of adding a Swin Transformer module in the Backbone layer of the YOLOv8 model in step S11 is described in detail, and the steps are as follows:
[0075] S110, adding a SwinTransformer module after the multiple conv structures at the Backbone level of the YOLOv8 model.
[0076] Specifically, two Swin Transformer modules are added to the first, second, fourth, and fifth stages of the Backbone hierarchy, and six Swin Transformer modules are added to the third stage of the Backbone hierarchy. Each Swin Transformer module is added after the conv structure, such as Figure 2 shown.
[0077] The feature maps output by the second, third, fourth and fifth stages can be fused to obtain output feature maps of four different grid sizes.
[0078] It can be seen from the above technical solution that this embodiment provides an optional way to add a Swin transformer module. Through the above method, the feature fusion performance of the Swin transformer module can be further utilized to further enhance the feature fusion capability of the helmet recognition model.
[0079] In some embodiments of the present application, the process of adding the Ghost module and the attention mechanism ECA in the Neck level in step S11 is described in detail, and the steps are as follows:
[0080] S111. Use the Ghost module to replace the convolution block of the C2f structure in the Neck layer.
[0081] Specifically, the Ghost module is used to replace the ordinary convolutional block in the Bottlenecks structure in each C2f. Among them, C2f contains two Bottlenecks structures.
[0082] The first layer of Ghost modules in the replaced C2f is used to increase the number of channels, thereby increasing the feature dimension. The second layer of Ghost modules is used to reduce the feature dimension to adapt it to the residual connection and add the input and output. Batch normalization (BN) is introduced to ensure that the input of each layer of the network has the same distribution as much as possible. The introduction of the sparse ReLu activation function can avoid the gradient vanishing phenomenon of back propagation. The ReLU activation function is not used after the second layer of Ghost modules because the hard saturation setting of the negative half axis of ReLU will make its output data distribution not zero mean, resulting in neuron inactivation, thereby reducing the performance of the network.
[0083] S112. Add the attention mechanism ECA as the neighborhood connection structure of the Concat structure in the Neck layer to the Neck layer.
[0084] Specifically, the attention mechanism ECA is added between the C2f obtained after replacement in the Neck layer and the Concat structure.
[0085] The attention mechanism ECA is a neighborhood connection structure of the C2f and Concat structures obtained after replacement, that is, the attention mechanism ECA is not only connected to the C2f and Concat structures obtained after replacement, but also near the C2f and Concat structures obtained after replacement, such as Figure 2 shown.
[0086] In order to further improve the detection accuracy and generalization ability of the model, the attention mechanism ECA is introduced before the 1×1 convolution of the Head module predicts the large target output.
[0087] It can be seen from the above technical solution that this embodiment provides an optional way to add a Ghost module and an attention mechanism ECA. Through the above method, Ghost convolution can be used to reduce network complexity, and more valuable redundant feature maps can be generated through low-cost operations, effectively improving network performance. The attention mechanism ECA is used to reduce background interference and improve the reliability of feature extraction.
[0088] In some embodiments of the present application, the process of obtaining two types of training images in step S12 is described in detail, and the steps are as follows:
[0089] S120. Filter multiple tunnel images from various websites and image data sets using web crawler technology.
[0090] Specifically, various types of tunnel images can be selected through web crawler technology.
[0091] S121. For each tunnel image, determine whether there are construction workers in the tunnel image. If yes, add a bounding box for marking the head area in the tunnel image; evaluate whether each head area is wearing a safety helmet. If yes, add a safety helmet label to the corresponding head area; if no, add a no-safety helmet label to the corresponding head area.
[0092] Specifically, each tunnel image may be processed to construct a training image.
[0093] Among them, it can be determined in turn whether there are construction workers in each tunnel image.
[0094] If there are no construction workers, the tunnel image can be used as a training image.
[0095] If there are construction workers, one or more bounding boxes for marking the head region may be added to the tunnel image, and it may be evaluated whether each head region is wearing a safety helmet.
[0096] If worn, a helmet label may be added to the corresponding head area.
[0097] If not worn, a no helmet label may be added to the corresponding head area.
[0098] It can be seen from the above technical solution that this embodiment provides an optional method for obtaining training images. Through the above method, multiple types of training images can be obtained to complete model training, further improving the recognition reliability of the helmet recognition model.
[0099] In some embodiments of the present application, step S13, the process of training the target YOLOv8 model using each training image in turn, is described in detail, and the steps are as follows:
[0100] S130, input each training image into the target YOLOv8 model in turn, use the target YOLOv8 model to predict the head area in each training image, and predict whether a helmet is worn in each head area, and generate a prediction result corresponding to each training image.
[0101] Specifically, the target YOLOv8 model can be used to extract features from each training image, the head area in each training image can be marked with a detection box, and the Backbone layer with an added Swin Transformer module can be used to extract features from each head area. The Neck layer with an added Ghost module and an attention mechanism ECA can be used to fuse multiple detection features to generate a prediction result indicating whether there are construction workers without helmets in the corresponding training image.
[0102] S131. Based on each training image and its corresponding prediction result, a loss value is calculated, and the loss value is used to adjust the parameters of the Backbone layer with the Swin Transformer module added and the Neck layer with the Ghost module and the attention mechanism ECA added.
[0103] Specifically, the IoU loss function can be used to calculate the loss value based on each training image and its corresponding prediction result.
[0104] Based on the loss value, the gradient descent method is used to adjust the parameters of the Backbone layer with the Swin Transformer module and the Neck layer with the Ghost module and the attention mechanism ECA until the loss value is less than the preset loss threshold. The final trained target YOLOv8 model is used as the helmet recognition model.
[0105] In some embodiments of the present application, in order to timely remind construction workers who are not wearing safety helmets, an early warning process can be added. Next, the early warning process will be described in detail. The steps are as follows:
[0106] S1. When the image of the tunnel to be detected shows that there are construction workers who are not wearing safety helmets, a warning is issued.
[0107] Specifically, when it is confirmed that the image of the tunnel to be detected shows that there are construction workers who are not wearing safety helmets, an alarm may be sounded, or an early warning message may be sent to a terminal of a safety manager.
[0108] It can be seen from the above technical solution that, compared with the previous embodiment, this embodiment adds an early warning process, through which construction workers who are not wearing safety helmets can be reminded in time to ensure work safety.
[0109] Next, we will combine Figure 4 The safety helmet wearing detection device provided in the present application is introduced in detail. The safety helmet wearing detection device provided below can be compared with the safety helmet wearing detection method provided above.
[0110] See also Figure 4 It can be found that the helmet wearing detection device may include:
[0111] An acquisition module 10 is used to acquire a tunnel image to be detected including construction workers and a helmet recognition model, wherein the helmet recognition model is a trained YOLOv8 model with a Swin Transformer module added to the Backbone layer and a Ghost module and an attention mechanism ECA added to the Neck layer;
[0112] The judgment module 20 is used to use the helmet recognition model to locate the head of the tunnel image to be detected, and generate a target detection frame corresponding to each head area in the tunnel image to be detected; use the Backbone layer with the SwinTransformer module added to perform feature extraction on the head area calibrated by each target detection frame to obtain multiple detection features; use the Neck layer with the Ghost module and the attention mechanism ECA added to perform feature fusion on the multiple detection features to obtain the fusion feature corresponding to each head area; based on the fusion feature of each head area, it is judged whether the tunnel image to be detected indicates that there are construction workers who are not wearing helmets.
[0113] Furthermore, the acquisition module may include:
[0114] Model building unit, used to build the YOLOv8 model;
[0115] A module adding unit, used for adding a Swin Transformer module in the Backbone layer of the YOLOv8 model, and adding a Ghost module and an attention mechanism ECA in the Neck layer to form a target YOLOv8 model;
[0116] A training image acquisition unit is used to acquire two types of training images, one type of training images is an image of a tunnel without construction workers, and the other type of training images contains one or more bounding boxes for marking head regions, and each head region has a label indicating whether the corresponding head region is wearing a helmet;
[0117] The model training unit is used to train the target YOLOv8 model using each training image in turn, and use the target YOLOv8 model finally trained as a helmet recognition model.
[0118] Furthermore, the module adding unit may include:
[0119] The Swin Transformer module adds a component for adding a Swin Transformer module after the multiple conv structures at the Backbone level of the YOLOv8 model.
[0120] Furthermore, the module adding unit may also include:
[0121] The convolutional block replacement component is used to replace the convolutional blocks of the C2f structure in the Neck layer with the Ghost module;
[0122] An attention mechanism component is added to add the attention mechanism ECA to the Neck layer as a neighborhood connection structure of the Concat structure in the Neck layer.
[0123] Further, the training image acquisition unit may include:
[0124] The tunnel image acquisition component is used to obtain multiple tunnel images from various websites and image data sets through web crawler technology;
[0125] The image processing component is used to determine, for each tunnel image, whether there are construction workers in the tunnel image. If so, a bounding box for marking the head area is added to the tunnel image; and to evaluate whether each head area is wearing a safety helmet. If so, a safety helmet label is added to the corresponding head area; if not, a no-safety-helmet label is added to the corresponding head area.
[0126] Furthermore, the model training unit may include:
[0127] A prediction result generating component is used to input each training image into the target YOLOv8 model in turn, use the target YOLOv8 model to predict the head area in each training image, and predict whether a helmet is worn in each head area, and generate a prediction result corresponding to each training image;
[0128] The parameter adjustment component is used to calculate the loss value based on each training image and its corresponding prediction result, and use the loss value to adjust the parameters of the Backbone layer with the Swin Transformer module added and the Neck layer with the Ghost module and the attention mechanism ECA added.
[0129] Furthermore, the helmet wearing detection device may also include:
[0130] The warning issuing module is used to issue a warning when the tunnel image to be detected shows that there are construction workers who are not wearing safety helmets.
[0131] The helmet wearing detection device provided in the embodiment of the present application can be applied to helmet wearing detection equipment, such as PC terminals, cloud platforms, servers and server clusters. Figure 5 The hardware structure diagram of the helmet wearing detection device is shown in FIG. Figure 5 ,The hardware structure of the helmet wearing detection device may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;
[0132] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;
[0133] The processor 1 may be a central processing unit CPU, or an application-specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention, etc.;
[0134] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), etc., such as at least one disk memory;
[0135] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to:
[0136] Obtain a tunnel image to be detected containing construction workers and a helmet recognition model, wherein the helmet recognition model is a trained YOLOv8 model with a Swin Transformer module added to the Backbone layer and a Ghost module and an attention mechanism ECA added to the Neck layer;
[0137] The helmet recognition model is used to locate the head of the tunnel image to be detected, and a target detection frame corresponding to each head area is generated in the tunnel image to be detected; the Backbone layer with a Swin Transformer module is used to extract features of the head area calibrated by each target detection frame to obtain multiple detection features; the Neck layer with a Ghost module and an attention mechanism ECA is used to fuse multiple detection features to obtain fused features corresponding to each head area; based on the fused features of each head area, it is judged whether the tunnel image to be detected indicates that there are construction workers who are not wearing helmets.
[0138] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0139] The embodiment of the present application further provides a readable storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:
[0140] Obtain a tunnel image to be detected containing construction workers and a helmet recognition model, wherein the helmet recognition model is a trained YOLOv8 model with a Swin Transformer module added to the Backbone layer and a Ghost module and an attention mechanism ECA added to the Neck layer;
[0141] The helmet recognition model is used to locate the head of the tunnel image to be detected, and a target detection frame corresponding to each head area is generated in the tunnel image to be detected; the Backbone layer with a Swin Transformer module is used to extract features of the head area calibrated by each target detection frame to obtain multiple detection features; the Neck layer with a Ghost module and an attention mechanism ECA is used to fuse multiple detection features to obtain fused features corresponding to each head area; based on the fused features of each head area, it is judged whether the tunnel image to be detected indicates that there are construction workers who are not wearing helmets.
[0142] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0143] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0144] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0145] The above description of the disclosed embodiments enables professionals and technicians in the field to implement or use the present application. Various modifications to these embodiments will be apparent to professionals and technicians in the field, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. The various embodiments of the present application can be combined with each other. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for detecting helmet wearing. It is characterized in that include: Obtain a tunnel image to be detected containing construction workers and a helmet recognition model, wherein the helmet recognition model is a trained YOLOv8 model with a Swin Transformer module added to the Backbone layer and a Ghost module and an attention mechanism ECA added to the Neck layer; The helmet recognition model is used to locate the head of the tunnel image to be detected, and a target detection frame corresponding to each head area is generated in the tunnel image to be detected; the Backbone layer with the Swin Transformer module is used to extract features of the head area marked by each target detection frame to obtain multiple detection features; the Neck layer with the Ghost module and the attention mechanism ECA is used to fuse multiple detection features to obtain fused features corresponding to each head area; Based on the fusion features of each head region, it is determined whether the tunnel image to be detected indicates that there are construction workers who are not wearing safety helmets.
2. The helmet wearing detection method according to claim 1, It is characterized in that Get the helmet recognition model, including: Build the YOLOv8 model; Adding a Swin Transformer module to the Backbone layer of the YOLOv8 model, and adding a Ghost module and an attention mechanism ECA to the Neck layer to form a target YOLOv8 model; Two types of training images are obtained, one type of training images is an image of a tunnel without construction workers, and the other type of training images contains one or more bounding boxes for marking the head area, and each head area has a label indicating whether the corresponding head area is wearing a helmet; The target YOLOv8 model is trained using each training image in turn, and the target YOLOv8 model finally trained is used as a helmet recognition model.
3. The helmet wearing detection method according to claim 2, It is characterized in that Add the Swin Transformer module to the Backbone layer of the YOLOv8 model, including: A Swin Transformer module is added after the multiple conv structures at the Backbone level of the YOLOv8 model.
4. The helmet wearing detection method according to claim 2, It is characterized in that The Ghost module and the attention mechanism ECA are added to the Neck level, including: Use the Ghost module to replace the convolutional block of the C2f structure in the Neck layer; The attention mechanism ECA is added to the Neck layer as the neighborhood connection structure of the Concat structure in the Neck layer.
5. The helmet wearing detection method according to claim 2, It is characterized in that The obtaining of two types of training images comprises: Using web crawler technology, multiple tunnel images were screened from various websites and image datasets; For each tunnel image, determine whether there are construction workers in the tunnel image. If so, add a bounding box to mark the head area in the tunnel image. Evaluate whether each head area is wearing a safety helmet. If so, add a safety helmet label to the corresponding head area. If not, add a no-safety helmet label to the corresponding head area.
6. The helmet wearing detection method according to claim 2, It is characterized in that The method of training the target YOLOv8 model by using each training image in turn includes: Input each training image into the target YOLOv8 model in turn, use the target YOLOv8 model to predict the head area in each training image, and predict whether a helmet is worn in each head area, and generate a prediction result corresponding to each training image; Based on each training image and its corresponding prediction result, the loss value is calculated, and the loss value is used to adjust the parameters of the Backbone layer with the SwinTransformer module added and the Neck layer with the Ghost module and the attention mechanism ECA added.
7. The helmet wearing detection method according to any one of claims 1 to 6, It is characterized in that Also includes: When the image of the tunnel to be detected shows that there are construction workers who are not wearing safety helmets, a warning is issued.
8. A helmet wearing detection device, It is characterized in that include: An acquisition module is used to acquire a tunnel image to be detected containing construction workers and a helmet recognition model, wherein the helmet recognition model is a trained YOLOv8 model with a Swin Transformer module added to the Backbone layer and a Ghost module and an attention mechanism ECA added to the Neck layer; A judgment module is used to use the helmet recognition model to locate the head of the tunnel image to be detected, and generate a target detection frame corresponding to each head area in the tunnel image to be detected; use the Backbone layer with the Swin Transformer module to extract features of the head area marked by each target detection frame to obtain multiple detection features; use the Neck layer with the Ghost module and the attention mechanism ECA to fuse the multiple detection features to obtain the fusion feature corresponding to each head area; Based on the fusion features of each head region, it is determined whether the tunnel image to be detected indicates that there are construction workers who are not wearing safety helmets.
9. A helmet wearing detection device, It is characterized in that including memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the helmet wearing detection method as described in any one of claims 1-7.
10. A readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, each step of the helmet wearing detection method as described in any one of claims 1 to 7 is implemented.
