A safety helmet wearing detection method based on improved YOLOv5
By improving the YOLOv5 network structure and introducing hybrid connectivity and compressed activation gating units, the problem of low accuracy in helmet wearing detection was solved, achieving efficient intelligent helmet wearing detection and reducing the workload of management personnel.
Patent Information
- Application Number
- CN202310785410.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-29
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2043-06-29
AI Technical Summary
The existing YOLOv5 algorithm is not very accurate in detecting helmet wearing, making helmet wearing supervision and inspection time-consuming, labor-intensive, and prone to omissions and misjudgments.
By improving the YOLOv5 network structure, a short-circuit connection structure of local residual connections and macroscopic dense connections is introduced. Group convolution and depthwise separable convolution are used in the compressed activation gating unit, combined with the Softmax and Sigmoid functions, to achieve effective fusion of feature information and decay of reused features.
It improves the accuracy of safety helmet wearing detection, reduces the workload of safety management personnel, and realizes intelligent and automated detection in any construction work environment, which has broad application value.
Smart Images

Figure CN117036846B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence target detection, and in particular to a method for detecting helmet wearing based on a hybrid connection-based improved YOLOv5 algorithm. Background Technology
[0002] Safety helmets provide excellent cushioning, shock absorption, and stress dispersion in various fields such as oilfield drilling and mining. Properly wearing a safety helmet is an effective protective measure for the head. Supervising and inspecting helmet use is of great significance for protecting the safety of workers and is a mandatory duty and obligation of production and operation units. Legitimate production units are equipped with safety management personnel to inspect and supervise helmet use.
[0003] With the development of computer vision technology, computer-aided supervision and inspection has become one of the commonly used methods in modern times. The continuous advancement of intelligent algorithms and equipment brings many promising development possibilities, research value, and significance to computer vision technology.
[0004] Currently, safety helmet supervision and inspection can be categorized based on the form of inspection materials into on-site supervision, photo inspection, video playback inspection, and real-time video inspection. Each method requires manual judgment by safety management personnel, which is not only time-consuming and labor-intensive but also susceptible to omissions and misjudgments due to subjective factors such as fatigue. Safety helmet wearing detection methods can be viewed as target detection methods specifically addressing helmet wearing status. YOLOv5, as a relatively new first-stage target detection algorithm, stands out for its high accuracy and speed, but its target precision is not high. Summary of the Invention
[0005] The purpose of this invention is to overcome the problem of low accuracy when using YOLOv5 as a target detection algorithm in the prior art, and to provide a helmet wearing detection method based on hybrid connection improved YOLOv5.
[0006] To achieve the above-mentioned objectives, the present invention provides the following technical solution:
[0007] A helmet-wearing detection method based on hybrid connectivity improved YOLOv5, characterized by the following steps:
[0008] S1. Collect images of the on-site operations;
[0009] S2. Label the collected images, convert the labeled file format, and establish a safety helmet wearing detection dataset;
[0010] S3. Build a YOLOv5 v6.0 network, improve the network structure, and construct a helmet wearing detection network model based on hybrid connection improved YOLOv5;
[0011] S4. Input the dataset established in S2 into the improved YOLOv5 network model constructed in S3 for training, obtain the training parameters, and save the obtained weight file.
[0012] S5. Complete model deployment and system interface design, and conduct functional testing using test samples, including: images, videos, and camera video streams;
[0013] S6. If an alarm is detected that a person in the sample is not wearing a safety helmet, an alarm will be issued; otherwise, return to step S4.
[0014] The method of this invention improves the structure of the YOLOv5 algorithm by implementing short-circuit connection structures with local residual connections and macroscopic dense connections, constructing compressed activation gates using group convolution and depthwise separable convolution, using Softmax in the update gate to effectively fuse newly extracted feature information, and using the Sigmoid function in the forget gate to decay reused features, thereby further improving the accuracy of model detection.
[0015] Preferably, in step S1, images of construction operations related to safety helmets are obtained based on the MS COCO dataset and combined with web crawling tools, and video recordings of the work site are obtained in a targeted manner according to the usage environment, including work sites such as chemical plants and construction sites, and video frames are extracted to complete the image data collection.
[0016] Web crawling tools were used to obtain images of construction operations related to safety helmets. The collected image data was large and comprehensive, making the dataset richer.
[0017] Preferably, step S2 includes the following steps:
[0018] S21. Use the QT development interface Labelme in Python to annotate the images collected in step S1. Mark the content of wearing a safety helmet as 1 and the content of not wearing a safety helmet as 0. Output the annotation results and save them as an XML file.
[0019] S22. Convert the annotation file into a YOLO dataset label file in txt format;
[0020] S23. Divide the dataset into training, validation, and test sets according to the number of images in the dataset in an 8:1:1 ratio.
[0021] Using this method, a targeted, comprehensive, and accurate helmet-wearing detection dataset can be established.
[0022] Preferably, step S3 includes the following steps:
[0023] S31. Construct the YOLOv5 v6.0 network, including P1 to P5, 8 C3 structures, one SPPF structure, and two Upsample structures. The first 4 C3 structures use the BottleNeck1×n structure for feature extraction, and the last 4 C3 structures use the BottleNeck2×n structure for feature extraction.
[0024] S32. Replace the BottleNeck1×n module with a hybrid connection module 1 that introduces an attention mechanism. A dense connection structure is added between the input and output of the hybrid connection module 1, and a 1×1 convolutional layer is added before the final output. This not only enhances the model's ability to transmit and protect feature information, but also ensures that the original number of channels remains unchanged.
[0025] S33. Replace the BottleNeck2×n module with a hybrid connection module 2. Add a dense connection structure between the input and output of the hybrid connection module 1. The hybrid connection module 2 continues the original BottleNeck2×n structural features. On the basis of the hybrid connection module 1, remove the jump connection structure between every two unit structures.
[0026] S34. In both the hybrid connection module 1 and the hybrid connection module 2, a compressed activation gating structure is used instead of the original ConvBNSiLU structure.
[0027] In the S35 compressed activation gating structure, 1×1 convolutions and 3×3 groups of convolutions are used to form compression units; parallel 3×3 and 5×5 depthwise separable convolutions are used to form information activation units. After the two depthwise separable convolutional layers with different kernels, a gating structure update gate with an attention mechanism is connected to fuse the activation information of the two outputs of the parallel structure. A forget gate is connected in parallel outside the activation unit to filter repeatedly extracted feature information. A residual connection structure is embedded between the output of the compression unit and the forget gate to realize the hybrid connection within all C3 structures.
[0028] 3×3 and 5×5 convolutions produce similar lengths. Using parallel 3×3 and 5×5 depthwise separable convolutions is the lightest combination, with fast speed performance and small model size.
[0029] This method of replacing the original BottleNeck structure with a hybrid connection structure can accelerate the transmission of feature information, retain more feature information, and achieve effective utilization of feature information, while ensuring that the complexity of the model is not increased, thus effectively improving the accuracy of the helmet wearing detection algorithm.
[0030] Preferably, step S35, the compression activation gating unit, includes the following steps:
[0031] S351. The feature image is input to the compression activation gate unit and then passed through a 1×1 convolutional layer and a 3×3 group of convolutional layers. The two layers can use the width multiplier or the stride to achieve the downsampling operation of the model, so as to obtain the feature image with reduced feature dimension and reduce the complexity of the model.
[0032] S352. Using a parallel structure of 3×3 and 5×5 depth-separable convolutions for feature activation and data padding, this design can obtain more activated feature information while keeping the two parallel output dimensions the same, thus enabling the model to learn information more effectively.
[0033] S353. An update gate is connected after two depthwise separable convolutional structures to effectively fuse feature information from different branches. After 3×3 and 5×5 depthwise separable convolutions, feature images are obtained and enter the update gate.
[0034] S354. After the two compressed structures in S351, between the output of the update gate and the output of the forget gate, a weighted aggregation structure consisting of a forget gate and a residual connection in parallel is embedded and added to the output of the update gate. This allows the use of channel attention and the sigmoid function to filter and attenuate features that are being exploited in a complex manner. The forget gate and the update gate share the same Softmax gating structure before the global attention pooling layer, and then pass through the first fully connected layer, the batch normalization and activation function layer, the second fully connected layer, and the sigmoid function layer to obtain the output of the forget gate.
[0035] The Sigmoid function can control the channel weights between (0, 1), effectively attenuating the reuse of features.
[0036] S355. Add the corresponding positions of the final output feature maps of the update gate and the forget gate to obtain the final output of the compressed activation gate unit.
[0037] The above steps enable the efficient dissemination of feature information.
[0038] Preferably, in step S353, for a 3×3 branch, the input feature image is reduced to 1 channel dimension through a 1×1 convolution and a Softmax function to normalize the attention feature map and obtain the final attention feature descriptor, where each element is represented as:
[0039]
[0040] In the formula, This represents the final attention feature map obtained after normalization using the Softmax function, where H, W, and C represent the length, width, and number of channels of the feature map, respectively. Represents the input feature map or Attention feature map obtained after passing through a 1×1 convolution kernel;
[0041] Secondly, the image is shrunk by a global attention pooling layer to generate a global context feature map. Each element of the global context feature map can be represented as:
[0042]
[0043] In the formula, This represents the global context feature map obtained by weighting the final attention feature map through global attention pooling. Represents the global context feature map element of the c-th channel;
[0044] For a 5×5 branch, the global context feature map can be obtained through the same parallel structure.
[0045] Next, the global context feature maps obtained from the two parallel branches are concatenated along the channel and passed through a fully connected layer with a reduction factor to transform them into a hidden process feature map:
[0046] h = W(z) 3×3 ||z 5×5 )+b
[0047] In the formula, μ represents the reduction factor; and These represent the weights and biases of the fully connected layer, respectively.
[0048] Afterwards, the hidden feature map is batch normalized and activated by a non-linear activation function to obtain the hidden feature map, which can be represented as:
[0049] h′=Tanh{BN[W(z 3×3 ||z 5×5 )+b]}
[0050] In the formula, BN stands for BatchNorm, and Tanh stands for Tanh() activation function;
[0051] This process can improve the efficiency of information fusion and dissemination by setting a reduction factor.
[0052] Then, two parallel fully connected layers are applied to the fused hidden feature map to generate the channel attention feature map. A softmax function is then used to normalize the channel features, generating the final channel attention feature map, which can be represented as:
[0053]
[0054] In the formula, the channel attention feature map, These represent the weights and biases of the two fully connected layers, respectively.
[0055] The final channel attention feature map can be represented as:
[0056]
[0057] Among them, u 3×3 ,
[0058] Finally, the final channel attention feature maps are weighted and aggregated with the global context feature maps of the corresponding branches to obtain the final output of the update gate:
[0059]
[0060] Preferably, in step S354, the output of the forget gate is represented as:
[0061]
[0062] In the formula, This indicates that the input feature map The global context feature map is obtained by using the same global attention pooling and other structures as the update gate; These represent the weights and biases of the first fully connected layer, respectively. These represent the weights and biases of the second fully connected layer, respectively; r f Indicates the bottleneck coefficient. The final channel attention feature map representing the output of the forget gate;
[0063] Preferably, step S4 includes the following steps:
[0064] S41. Train the helmet-wearing detection network based on hybrid connection-based improved YOLOv5 in step S3 based on the helmet-wearing detection dataset established in step S2. The Adam or SGD optimizer can be used, with a training epoch of 300 and different batch sizes of 4, 8, 16, 32, and 64 for training.
[0065] S42. Test the training results using weight files and test set data obtained from training with different batch sizes;
[0066] S43. Fine-tune the network's hyperparameters on the validation set;
[0067] S44. Save the optimal training parameters and their weight files, plot the confusion matrix, F1 curve, P curve, R curve, and PR curve, calculate the training set bounding box position loss train / box_loss, target loss train / obj_loss, and confidence loss train / cls_loss, and the validation set bounding box position loss val / box_loss, target loss val / obj_loss, and confidence loss val / cls_loss, as well as the precision, recall, and mean accuracy mAP@0.5 and mAP@0.5:0.95, and plot the function graphs.
[0068] Preferably, step S5 includes the following steps:
[0069] S51. Add the main interface, set the window main class, image and video reading process and thread, as well as model and interface initialization parameters;
[0070] S52. Set up separate interfaces for reading real-time data streams from images, videos, and cameras;
[0071] S53. Set the start, stop, and reset of events for images, videos, etc.
[0072] Preferably, in step S6, the alarm prompt is implemented using the Playsound database built into Python. When the model detects that a person is not wearing a safety helmet, it issues a real-time alarm prompt to remind the person that they are not wearing a safety helmet, thereby reducing the workload of safety management personnel.
[0073] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0074] 1. The method of the present invention adds a hybrid connection structure to the YOLOv5 network. Through the short-circuit connection structure of local residual connection and macro-dense connection, it accelerates the transmission speed and utilization efficiency of feature information, while protecting the model from excessive redundancy.
[0075] 2. In the YOLOv5 network, the method of the present invention embeds the compressed activation gate unit into the hybrid connection module. The compressed activation gate unit uses structures such as group convolution and depthwise separable convolution, which saves the number of model parameters and computation while ensuring performance and maintaining the lightweight effect of the model.
[0076] 3. In the improved YOLOv5 network, the update gate uses Softmax to effectively fuse newly extracted feature information, and the forget gate uses the Sigmoid function to decay reused features. Both introduce a lightweight channel attention mechanism, which can enable the model to learn more feature information and improve the model's detection accuracy, while ensuring that the model's complexity is not too high, the model's memory usage is not too large, and the detection speed is not reduced.
[0077] 4. The method of this invention is an automated intelligent safety helmet wearing detection method that can be used in any construction operation environment. It helps to improve the detection efficiency of safety helmet wearing status, reduce the workload of safety management personnel, and has broad promotion significance and development research value. It provides a new perspective for the realization and implementation of smart construction sites. Attached Figure Description
[0078] Figure 1 This is a flowchart of the helmet wearing detection method based on hybrid connection improved YOLOv5 in this embodiment 1;
[0079] Figure 2 This is a structural diagram of the hybrid connection module 1 used to replace BottleNeck1×n in this embodiment 1;
[0080] Figure 3 This is a structural diagram of the hybrid connection module 2 used to replace BottleNeck2×n in this embodiment 1;
[0081] Figure 4 This is a structural diagram of the compressed activation gate (SEG) structure in Embodiment 1;
[0082] Figure 5 This is a structural diagram of the update gate in Embodiment 1;
[0083] Figure 6 This is a structural diagram of the forgetting gate in Embodiment 1;
[0084] Figure 7 This is a diagram showing the helmet wearing test effect of Example 1;
[0085] Figure 8 This is a comparison chart of experimental results between the method of the present invention in this embodiment 1 and other existing methods. Detailed Implementation
[0086] The present invention will be further described in detail below with reference to experimental examples and specific embodiments. However, this should not be construed as limiting the scope of the above-mentioned subject matter of the present invention to the following embodiments; all technologies implemented based on the content of the present invention fall within the scope of the present invention.
[0087] Example 1
[0088] This invention provides and discloses an improved helmet-wearing detection method based on hybrid connectivity in YOLOv5, such as... Figure 1 As shown, the present invention includes the following steps:
[0089] S1: Collect targeted images of on-site operations;
[0090] S2: Label the collected images, convert the labeled file format, and establish a targeted safety helmet wearing detection dataset;
[0091] S3: Build a YOLOv5 v6.0 network, improve the network structure, and construct a helmet-wearing detection network model based on hybrid connection-based improved YOLOv5;
[0092] S4: Input the dataset established in step 2 into the improved YOLOv5 network model constructed in step S3 for training, obtain the training parameters, and save the obtained weight file.
[0093] S5: Complete model deployment and system interface design, and perform functional testing using test sample head video streams. Test samples include images, videos, and camera video streams.
[0094] S6: If an alarm is detected that a person in the sample is not wearing a safety helmet, an alarm will be issued; otherwise, return to step S4.
[0095] In step S1, based on the MS COCO dataset, images of construction operations related to safety helmets are obtained using web crawling tools, and video recordings of operations are obtained from specific chemical plants, construction sites, and other work sites according to the usage environment. Valid video frames are extracted to complete the image data collection.
[0096] The implementation process of constructing the helmet wearing detection dataset in step S2 specifically includes the following steps:
[0097] S21: Use the QT development interface Labelme in Python to annotate the images collected in step S1. Mark the content of wearing a safety helmet as 1 and the content of not wearing a safety helmet as 0. Output the annotation results and save them as an XML file.
[0098] S22: Convert the annotation file into a YOLO dataset label file (txt format);
[0099] S23: Divide the dataset into training, validation, and test sets according to the number of images in the dataset in an 8:1:1 ratio, and finally establish a targeted safety helmet wearing detection dataset.
[0100] Step S3, constructing a helmet-wearing detection network model based on hybrid connectivity-improved YOLOv5, includes the following steps:
[0101] Step S31: Construct the YOLOv5 v6.0 network, which mainly includes P1 to P5, 8 C3 structures, one SPPF structure, and two Upsample structures. The first 4 C3 structures use the BottleNeck1×n structure for feature extraction, and the last 4 C3 structures use the BottleNeck2×n structure for feature extraction.
[0102] Step S32: As Figure 2 As shown, the BottleNeck1×n module in the network is replaced with a hybrid connection module 1 that introduces an attention mechanism. A dense connection structure is added between the input and output of the hybrid module 1, and a 1×1 convolutional layer is added before the final output. This not only enhances the model's ability to transmit and preserve feature information, but also ensures that the original number of channels remains unchanged.
[0103] Step S33: As Figure 3 As shown, the BottleNeck2×n module is replaced by the hybrid connection module 2. The structure of the hybrid connection module 2 is similar to that of the hybrid connection module 1, both of which have added dense connection structures. The difference is that the hybrid module 2 continues the original BottleNeck2×n structural features, but removes the jump connection structure between every two unit structures on the basis of the hybrid module 1.
[0104] Step S34: Both hybrid connection module 1 and hybrid connection module 2 use the following... Figure 4 The Compressed Activation Gated (SEG) structure shown replaces the original ConvBNSiLU structure;
[0105] Step S35: In the compressed activation gating structure, 1×1 convolutions and 3×3 groups of convolutions are used to form compression units; parallel 3×3 and 5×5 depthwise separable convolutions are used to form information activation units. A gating unit is connected after two depthwise separable convolutional layers with different kernels. Figure 5 The gating structure update gate with an attention mechanism shown is used to fuse the activation information of the two outputs of the parallel structure; a gate such as... is connected in parallel outside the activation unit. Figure 6 The forget gate shown is used to filter repeatedly extracted feature information. A residual connection structure is embedded between the output of the forget gate and the compression unit to realize the hybrid connection within all C3 structures.
[0106] The network training in step S4 specifically includes the following steps:
[0107] Step S41: Train the helmet wearing detection network based on hybrid connection improved YOLOv5 in step S3 based on the helmet wearing detection dataset established in step S2. Use Adam or SGD optimizer, with a training epoch of 300, and set different batch sizes of 4, 8, 16, 32 and 64 for training respectively.
[0108] Step S42: Test the training results using the weight files and test set data obtained from training with different batch sizes;
[0109] Step S43: Fine-tune the network's hyperparameters on the validation set.
[0110] Step S44: Save the optimal training parameters and their weight files, plot the confusion matrix, F1 curve, P curve, R curve, and PR curve, calculate the training set bounding box position loss train / box_loss, target loss train / obj_loss, and confidence loss train / cls_loss, and the validation set bounding box position loss val / box_loss, target loss val / obj_loss, and confidence loss val / cls_loss, as well as the precision, recall, and mean average accuracy mAP@0.5 and mAP@0.5:0.95, and plot the function graphs.
[0111] Step S5 specifically includes the following steps:
[0112] Step S51: Add the main interface, set the window main class, image and video reading process and thread, as well as model and interface initialization parameters;
[0113] Step S52: Set up the interfaces for reading real-time data streams from images, videos, and cameras respectively;
[0114] Step S53: Set the event to be enabled, disabled, and reset for events such as images and videos.
[0115] The practical application effects of the embodiments of the present invention are as follows: Figure 7 As shown.
[0116] The alarm notification operation in step S6 is implemented using the Playsound database built into Python. When the model detects that a person is not wearing a safety helmet, it issues a real-time alarm notification.
[0117] The implementation mechanism for adding a hybrid connection structure in a YOLOv5 network is as follows:
[0118] First, hybrid connection modules 1 and 2, which combine local residual connections and external dense connections, are constructed as follows: Figure 2 and Figure 3 As shown, replace the BottleNeck1×n and BottleNeck2×n structures in YOLOv5 with the two structures respectively; secondly, as shown... Figure 4 The compressed activation gating unit shown is embedded in the hybrid connection module. Within the compressed activation gating unit, standard convolution and group convolution are used to compress the feature image, and depthwise separable convolutions of different scales are employed for information activation. Information fusion is achieved through a gating structure incorporating an attention mechanism. Finally, a structure as shown is constructed... Figure 5 The update gate, which facilitates the transfer of feature information, and the forget gate, which decays duplicate feature information, are shown below. Figure 7 As shown, this method of replacing the original BottleNeck structure with a hybrid connection structure can accelerate the transmission of feature information, retain more feature information, and achieve effective utilization of feature information, while ensuring that the complexity of the model is not increased, thus effectively improving the accuracy of the helmet wearing detection algorithm.
[0119] Furthermore, in the compressed activation gating unit, methods such as group convolution, depthwise separable convolution, attention combined with gating mechanism, and residual connection are used to achieve efficient propagation of feature information. Specifically, the process includes the following steps:
[0120] S351, the feature map input compression activation gate unit, passes through a 1×1 convolutional layer and a 3×3 group of convolutional layers in sequence. Both can use width multipliers or strides to achieve downsampling of the model, so as to obtain a feature image with reduced feature dimensions and reduce model complexity.
[0121] S352. Using a parallel structure of 3×3 and 5×5 depth-separable convolutions for feature activation and data padding, this design can obtain more activated feature information while keeping the two parallel output dimensions the same, thus enabling the model to learn information more effectively.
[0122] S353. An update gate is connected after two depthwise separable convolutional structures to effectively fuse feature information from different branches. Feature images obtained after 3×3 and 5×5 depthwise separable convolutions are then fed into the update gate. This process can be viewed as being achieved through the following five steps:
[0123] ① For a 3×3 branch, the input feature image is reduced to 1 channel dimension by a 1×1 convolution and a softmax function, thus normalizing the attention feature map and obtaining the final attention feature descriptor. Each element in the final attention feature descriptor can be represented by the following formula:
[0124]
[0125] in, This represents the final attention feature map obtained after normalization using the Softmax function, where H, W, and C represent the length, width, and number of channels of the feature map, respectively. Represents the input feature map or The attention feature map obtained after passing through a 1×1 convolution kernel, where i and j represent the number of rows and columns of the feature map, respectively.
[0126] ② The image is shrunk by passing it through a global attention pooling layer to generate a global context feature map. Each element of the global context feature map can be represented as:
[0127]
[0128] in, This represents the global context feature map obtained by weighting the final attention feature map through global attention pooling. This represents a global context feature map element for the c-th channel.
[0129] Similarly, another global context feature map can be obtained through the same parallel structure.
[0130] ③ The global context feature maps obtained from the two parallel branches are concatenated along the channel and passed through a fully connected layer with a reduction factor to transform them into a hidden process feature map:
[0131] h = W(z) 3×3 ||z 5×5 )+b
[0132] in, μ represents the reduction factor; and These represent the weights and biases of the fully connected layer, respectively.
[0133] After the hidden feature map is batch normalized and activated by a non-linear activation function, the hidden feature map can be represented as:
[0134] h′=Tanh{BN[W(z 3×3 ||z 5×5 )+b]}
[0135] in, BN stands for BatchNorm, and Tanh stands for Tanh() activation function;
[0136] This process can improve the efficiency of information fusion and dissemination by setting a reduction factor.
[0137] ④ Two parallel fully connected layers are used to generate channel attention feature maps from the fused hidden feature maps. Then, a Softmax function is used to normalize the channel features to generate the final channel attention feature maps.
[0138] The channel attention feature map can be represented as:
[0139]
[0140] Among them, channel attention feature map These represent the weights and biases of the two fully connected layers, respectively.
[0141] The final channel attention feature map can be represented as:
[0142]
[0143] Among them, u 3×3 ,
[0144] ⑤ By weighted aggregation of the final channel attention feature maps with the global context feature maps of the corresponding branches, the final output of the update gate can be obtained:
[0145]
[0146] in,
[0147] S354. After the two compressed structures in step 1), a weighted aggregation structure consisting of a forget gate and a residual connection in parallel is embedded between the output of the update gate and the output of the update gate. This structure is then added to the output of the update gate. This allows for the use of channel attention and the sigmoid function to filter and attenuate reused features. The forget gate and update gate share the same Softmax gating structure before the global attention pooling layer, and then pass through a first fully connected layer, a batch normalization and activation function layer, a second fully connected layer, and a sigmoid function layer to obtain the output of the forget gate. Similar to the implementation mechanism of the update gate, the output of the forget gate can be represented as follows:
[0148]
[0149] in, This indicates that the input feature map The global context feature map is obtained by using the same global attention pooling and other structures as the update gate; These represent the weights and biases of the first fully connected layer, respectively. These represent the weights and biases of the second fully connected layer, respectively; r f Indicates the bottleneck coefficient. This represents the final channel attention feature map of the forget gate output.
[0150] The Sigmoid function can control the channel weights between (0, 1), effectively attenuating the reuse of features.
[0151] S355. Add the corresponding positions of the final output feature maps of the update gate and the forget gate to obtain the final output of the compressed activation gate unit.
[0152] In this embodiment, the aforementioned key parameters are ultimately set as follows: batch size is 16, training epochs are 300, learning rate is 0.1, the number of 3×3 convolutional groups in the SEG block g = 4, width multiplier α = 4, and the reduction ratio parameter r for the update and forget gates. u =r f =2, step size S=1.
[0153] Finally, the method of this invention and other methods were trained together on the dataset used in this embodiment, and the results were compared. It can be seen that the method of this invention improves the detection accuracy of the model without sacrificing detection performance, which proves the effectiveness of the method of this invention.
[0154] like Figure 8 As shown, based on the experimental results of the dataset in this embodiment, it can be seen that the method of the present invention achieves the highest detection accuracy, the smallest weight file memory usage, and a shorter time to detect the same image. Figure 8 The detection results shown demonstrate that the method of this invention achieves automatic computer detection of helmet wearing, which is beneficial for further research and application in related fields.
[0155] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A hard hat wearing detection method based on mixed connection improved YOLOv5, characterized in that, Comprise the following steps: S1, collect the field operation image; S2, data labeling is carried out to the collected image, complete the annotation file format conversion, establish safety helmet wearing detection data set; S3, build YOLOv5 v6.0 network, improve network structure, build safety helmet wearing detection network model based on mixed connection improved YOLOv5; S4, the data set established in the S2 is input into the improved YOLOv5 network model constructed in the S3 for training, and the training parameters are obtained, and the obtained weight file is saved; S5, complete model deployment and system interface design, use test samples to do function test, including: image, video, camera video stream; S6, if it is detected that there is a person without safety helmet in the sample, an alarm prompt is sent, and if not, it returns to the step S4; Among them, in the step S3, it comprises the following steps: S31, build YOLOv5 v6.0 network, including P1~P5, 8 C3 structures, one SPPF structure, two Upsample structures, wherein the first four C3 structures use BottleNeck1×n structure for feature extraction, and the last four C3 structures use BottleNeck2×n structure for feature extraction; S32, the BottleNeck1×n module is replaced by a mixed connection module 1 with attention mechanism, a dense connection structure is added between the input and output of the mixed connection module 1, and a 1×1 convolution layer is added before the final output; S33, the BottleNeck2×n module is replaced by a mixed connection module 2, a dense connection structure is added between the input and output of the mixed connection module 2, and the mixed connection module 2 continues the original BottleNeck2×n structure feature, removes the skip connection structure between every two unit structures based on the mixed connection module 1; S34, in the mixed connection module 1 and the mixed connection module 2, the original ConvBNSiLU structure is replaced by a compression activation gate structure; S35, in the compression activation gate structure, a 1×1 convolution and a 3×3 group convolution are used to form a compression unit; a 3×3 and a 5×5 depth separable convolution in parallel are used to form an information activation unit, a gate structure update door with attention mechanism is connected after the two different convolution kernel depth separable convolution layers, which is used for information fusion of the activation information of the two outputs of the parallel structure; an oblivion gate is connected in parallel outside the activation unit, which is used for filtering the repeatedly extracted feature information; a residual connection structure is embedded between the compression unit and the output of the oblivion gate.
2. The safety helmet wearing detection method based on hybrid connection improved YOLOv5 according to claim 1, wherein In the step S1, based on the MS COCO data set, the network crawler tool is used to obtain safety helmet related construction operation image, and the operation video recording is obtained according to the use environment, the video frame is intercepted, and the image data collection is completed.
3. The safety helmet wearing detection method based on hybrid connection improved YOLOv5 according to claim 1, characterized in that, In the step S2, it comprises the following steps: S21, using the QT development interface Labelme in Python to mark the images collected in the S1 step, marking the content of wearing a safety helmet as 1 and the content of not wearing a safety helmet as 0, and outputting and saving the marking result as an xml format file; S22, converting the marking file into a YOLO data set label file, which is in a txt format; S23, dividing the training set, the verification set and the test set according to the proportion according to the number of images in the data set, and finally establishing a safety helmet wearing detection data set with pertinence.
4. The safety helmet wearing detection method based on hybrid connection improved YOLOv5 according to claim 1, characterized in that, In the step S35 of compressing and activating the gating unit, efficient propagation of feature information is realized, including the following steps: S351, inputting the feature image into the compression and activation gating unit, sequentially passing through a 1x1 convolution layer and a 3x3 group convolution layer, and obtaining a feature image with reduced feature dimension through a down-sampling operation; S352, using a structure of 3x3 and 5x5 deep separable convolution in parallel to activate and fill data of the feature information; S353, connecting an update gate after the two deep separable convolution structures, for effective fusion of feature information of different branches, and obtaining feature images after 3x3 and 5x5 deep separable convolution respectively into the update gate; S354, embedding a structure of a forgetting gate and a residual connection in parallel after the output of the two compression structures of the S351 and weighting and aggregating the structure, and adding the output of the forgetting gate to the output of the update gate; then respectively passing through a first full connection layer, a batch normalization and an activation function layer, a second full connection layer and a Sigmoid function layer to obtain the output of the forgetting gate; S355, adding the corresponding positions of the final output feature maps of the update gate and the forgetting gate to obtain the final output of the compression and activation gating unit.
5. The safety helmet wearing detection method based on hybrid connection improved YOLOv5 according to claim 4, wherein In the step S353, for the 3x3 branch, the input feature image is reduced to 1 in channel dimension through a 1x1 convolution and a Softmax function, attention feature map normalization is realized, and a final attention feature descriptor is obtained, each element of which is represented as: In the formula, , represents the final attention feature map obtained after normalization of the Softmax function, H, W, and C represent the length, width, and channel number of the feature map respectively; x e [1, H], y e [1, W]; represents the input feature map or the attention feature map obtained through a 1x1 convolution kernel; Secondly, the image is contracted through a global attention pooling layer to generate a global context feature map, each element of the global context feature map can be represented as: In the formula, represents the global context feature obtained by performing global attention pooling weighting on the final attention feature map, represents the global context feature map element of the cth channel. For 5x5 branch, the global context feature maps can be obtained through the same parallel structure Then, the global context feature maps obtained by the two parallel branches are concatenated in the channel, and a fully connected layer with a reduction factor is set to convert them into a hidden process feature map: wherein , r μ denotes a reduction factor; and denote the weight and bias values of the fully connected layer, respectively Then, the hidden process feature map is activated through batch normalization and a nonlinear activation function to obtain a hidden feature map, which can be represented as: wherein , BN denotes Batch Norm, and Tanh denotes a Tanh() activation function. Then, two parallel full connection layers are used to act on the fused hidden feature map to generate a channel attention feature map, and a Softmax function is used to realize channel feature normalization to generate a final channel attention feature map, which can be represented as: , wherein the channel attention feature map , ∈ , , ∈ , , ∈ respectively represent the weight and bias values of two fully connected layers. The final channel attention feature map can be represented as: , wherein , ∈ ; Finally, the final channel attention feature map is weighted and aggregated with the global context feature map of the corresponding branch to obtain the final output of the update gate: , 。 6. The safety cap wearing detection method based on hybrid connection improved YOLOv5 according to claim 1, wherein In the step S354, the output of the forgetting gate is represented as: In the formula, represents the global context feature map obtained by the same global attention pooling structure as the input feature map global context feature map obtained by the same global attention pooling structure as the input feature map , respectively represent the weight and bias values of the first fully connected layer; , respectively represent the weight and bias values of the second fully connected layer; r f represents a bottleneck coefficient, represents the final channel attention feature map output by the forgetting gate.
7. The safety cap wearing detection method based on hybrid connection improved YOLOv5 according to claim 1, wherein, In the step S4, the following steps are included: S41, based on the safety helmet wearing detection data set established in S2, train the safety helmet wearing detection network based on the mixed connection improved YOLOv5 in S3, use the optimizer, the training period (epoch) is 300, set different batch sizes (batch_size) as 4, 8, 16, 32, 64 respectively for training; S42, test the training results based on the weight files and test set data trained with different batch sizes; S43, fine-tune the hyperparameters of the network on the validation set; S44, save the optimal training parameters and their weight files, draw the confusion matrix, F1 curve, P curve, R curve, P R curve, calculate the training set prediction box position loss, target loss, confidence loss, calculate the validation set prediction box position loss, target loss, confidence loss, precision, recall, average correct rate mean mAP@0.5 and mAP@0.5:0.95, and draw the function image.
8. The safety cap wearing detection method based on hybrid connection improved YOLOv5 according to claim 1, wherein In the step S5, the following steps are included: S51, add a main interface, set a window main class, picture and video reading processes and threads, and model and interface initialization parameters; S52, set picture, video and camera real-time data stream reading interfaces respectively; S53, set picture, video event opening, closing and resetting events.
9. The hard hat wearing detection method based on hybrid connection improved YOLOv5 according to claim 1, wherein, In the step S6, the Playsound database provided by Python is used to realize alarm prompt. When the model detects that a person does not wear a safety helmet, real-time alarm prompt is issued.
Citation Information
Patent Citations
Power transmission line target detection and identification method based on feature fusion
CN114445706A
Water meter digital picture processing method and system based on deep learning
CN115082922A