Safety helmet wearing condition detection method and device, electronic equipment and storage medium
By detection methods based on the helmet wearing of the YOLOV5 algorithm, the improved YOLOV5 network model and multi -target tracking algorithm are used to solve the problem of inaccurate detection caused by the complexity of the work site and the detection of fatigue. Testing in a hard hat.
Patent Information
- Application Number
- CN202411282054.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2025-01-24
AI Technical Summary
Due to the complex situation on the work site and the prone to fatigue of the monitoring personnel, the detection of the hard hat wearing is inaccurate.
The helmet wearing detection method based on the YOLOv5 algorithm is adopted. By obtaining the job site video captured by the camera and the helmet wearing detection training samples, the improved YOLOv5 network model is trained, and the multi-target tracking algorithm is used to optimize the detection model.
The accuracy and speed of the condition of the helmet wear, ensure the safety of operators at the work site, and reduce the occurrence of safety accidents.
Smart Images

Figure CN119360413A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of helmet wearing condition detection, and in particular to a helmet wearing condition detection method, device, electronic equipment and storage medium. Background Art
[0002] Safety helmets are a common head protection tool. Wearing safety helmets plays a vital role in protecting the head safety of workers at high-risk work sites. However, due to the lack of safety awareness of some workers, they do not wear safety helmets as required, which leads to many safety accidents.
[0003] At present, the main helmet detection method still relies on manual monitoring, which is easy to lead to missed detection due to complex on-site conditions and fatigue of monitoring personnel. In recent years, the helmet wearing monitoring method based on artificial intelligence and computer vision has become the main means of management for port enterprises. How to improve the accuracy and speed of helmet wearing detection is a key problem in practical application.
[0004] Therefore, a helmet wearing detection method based on the YOLOv5 algorithm is studied to quickly and accurately detect the helmet wearing status based on the improved YOLOv5 model, which is of great significance for identifying the helmet wearing status of the workers, ensuring the safety of the workers at the work site, and preventing safety accidents of the workers at the work site. Summary of the invention
[0005] The present invention provides a method, device, electronic equipment and storage medium for detecting the wearing condition of a safety helmet, which are used to solve the problem of inaccurate detection of the wearing condition of a safety helmet due to complex conditions at the work site and fatigue of monitoring personnel, thereby laying an important foundation for the safe operation of operators.
[0006] In a first aspect, the present invention provides a method for detecting a helmet wearing condition, comprising:
[0007] Obtaining a work site video captured by a camera, and obtaining a helmet wearing condition detection training sample in a database; the helmet wearing condition detection training sample includes a first historical work site picture and corresponding historical helmet wearing condition information;
[0008] Using the first historical work site picture and the corresponding historical helmet wearing information, an improved YOLOv5 network model is trained to obtain a helmet wearing detection model; the improved YOLOv5 network model is a YOLOv5 network model improved based on a CA attention mechanism, a prediction layer, an improved Neck network and an improved loss function;
[0009] The work site video is input into the safety helmet wearing condition detection model optimized based on the multi-target tracking algorithm to obtain the safety helmet wearing condition detection result of the work site video.
[0010] Optionally, using the first historical work site picture and the corresponding historical helmet wearing information, an improved YOLOv5 network model is trained to obtain a helmet wearing detection model, including:
[0011] Performing a data enhancement operation on the first historical work site picture to obtain a second historical work site picture;
[0012] The improved YOLOv5 network model is trained using the second historical work site picture and the corresponding historical safety helmet wearing condition information to obtain the safety helmet wearing condition detection model.
[0013] Optionally, using the second historical work site picture and the corresponding historical helmet wearing information to train the improved YOLOv5 network model to obtain the helmet wearing detection model, including:
[0014] Constructing the improved YOLOv5 network model corresponding to the second historical work site picture;
[0015] According to the second historical work site picture and the corresponding historical helmet wearing information, training the improved YOLOv5 network model to obtain a trained YOLOv5 network model;
[0016] Based on the second historical work site picture and the corresponding historical safety helmet wearing condition information, the trained improved YOLOv5 network model is verified to obtain the safety helmet wearing condition detection model.
[0017] Optionally, constructing the improved YOLOv5 network model corresponding to the second historical work site picture includes:
[0018] Constructing a YOLOv5 network model corresponding to the second historical operation site picture;
[0019] The YOLOv5 network model is improved to obtain the improved YOLOv5 network model.
[0020] Optionally, training the improved YOLOv5 network model according to the second historical work site picture and the corresponding historical helmet wearing information to obtain the trained YOLOv5 network model includes:
[0021] Inputting the second historical work site picture into the improved YOLOv5 network model to obtain a corresponding helmet wearing condition detection output;
[0022] determining a training error based on the second historical work site picture and the corresponding historical helmet wearing condition information and the corresponding historical helmet wearing condition information;
[0023] Based on the training error, the parameters of the improved YOLOv5 network model are adjusted to obtain optimal parameters, and the improved YOLOv5 network model is optimized using the optimal parameters to obtain the trained YOLOv5 network model.
[0024] Optionally, the work site video is input into the helmet wearing condition detection model optimized based on the multi-target tracking algorithm to obtain the helmet wearing condition detection result of the work site video, including:
[0025] Utilizing a multi-target tracking algorithm, the helmet wearing condition detection model is optimized to obtain an optimal tracking detection model;
[0026] The work site video is input into the optimal tracking detection model to obtain a safety helmet wearing condition detection result of the work site video.
[0027] In a second aspect, the present invention provides a device for detecting the wearing condition of a helmet, comprising:
[0028] The acquisition module is used to acquire the work site video captured by the camera and to acquire the helmet wearing condition detection training samples in the database; the helmet wearing condition detection training samples include the first historical work site picture and the corresponding historical helmet wearing condition information
[0029] A training module, used to train an improved YOLOv5 network model using the first historical work site picture and the corresponding historical helmet wearing information to obtain a helmet wearing detection model;
[0030] An input module is used to input the work site video into the safety helmet wearing condition detection model optimized based on the multi-target tracking algorithm to obtain the safety helmet wearing condition detection result of the work site video, including.
[0031] In a third aspect, the present invention provides an electronic device, comprising a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the method provided in the first aspect are performed.
[0032] In a fourth aspect, the present invention provides a storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, runs the steps of the method provided in the first aspect.
[0033] In a fifth aspect, the present invention provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the steps in the method provided in the first aspect are performed.
[0034] It can be seen from the above technical solutions that the present invention has the following advantages:
[0035] The present invention provides a method, device, electronic device and storage medium for detecting the wearing condition of a helmet. The method comprises: obtaining a video of a work site shot by a camera, and obtaining a training sample for detecting the wearing condition of a helmet in a database, wherein the training sample comprises a first historical work site picture and corresponding historical information on wearing condition of a helmet, and using the first historical work site picture and corresponding historical information on wearing condition of a helmet to train an improved YOLOv5 network model to obtain a model for detecting the wearing condition of a helmet, wherein the improved YOLOv5 network model is a YOLOv5 network model improved based on a CA attention mechanism, a prediction layer, an improved Neck network and an improved loss function, and the work site video is input into the model for detecting the wearing condition of a helmet optimized based on a multi-target tracking algorithm to obtain a detection result of the wearing condition of a helmet from the work site. A method for detecting the wearing condition of a helmet from the work site using an optimal tracking detection model is formed, so as to solve the problem of inaccurate detection of the wearing condition of a helmet due to the complex work site conditions and the fatigue of monitoring personnel, and to lay an important foundation for the safe operation of the operators. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present invention 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 some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0037] Figure 1 A flowchart of a first embodiment of a method for detecting the wearing condition of a helmet according to the present invention;
[0038] Figure 2 This is a flowchart of a second embodiment of a method for detecting the wearing condition of a helmet according to the present invention;
[0039] Figure 3 It is a structural schematic diagram of the improved YOLOv5 model of the present invention;
[0040] Figure 4 It is a schematic diagram of the detection result of the wearing condition of the safety helmet of the present invention;
[0041] Figure 5 The present invention is a structural block diagram of an embodiment of a device for detecting the wearing condition of a helmet. DETAILED DESCRIPTION
[0042] The embodiments of the present invention provide a method, device, electronic device and storage medium for detecting the wearing condition of a safety helmet, which are used to solve the problem of difficulty in detecting the wearing condition of a safety helmet in an abnormally high-pressure layer section, and lay an important foundation for the safe operation of operators.
[0043] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] Embodiment 1
[0045] See also Figure 1 , Figure 1 The present invention is a flowchart of a first embodiment of a method for detecting the wearing condition of a helmet, the method comprising:
[0046] Step S101, obtaining a video of the work site taken by a camera, and obtaining a safety helmet wearing condition detection training sample in a database; the safety helmet wearing condition detection training sample includes a first historical work site picture and corresponding historical safety helmet wearing condition information;
[0047] The camera of the embodiment of the present invention takes a work site video, which is a work site scenario where the safety helmet wearing condition needs to be detected. A safety helmet wearing condition detection training sample in a database is obtained. The safety helmet wearing condition detection training sample includes a first historical work site picture and corresponding historical safety helmet wearing condition information. The first historical work site picture is a historical picture of the work site, and the safety helmet wearing condition information is the safety helmet wearing condition of the historical picture.
[0048] Step S102, using the first historical work site picture and the corresponding historical helmet wearing information, training an improved YOLOv5 network model to obtain a helmet wearing detection model; the improved YOLOv5 network model is a YOLOv5 network model improved based on CA attention mechanism, prediction layer, improved Neck network and improved loss function;
[0049] In an optional embodiment, the first historical work site picture and the corresponding historical helmet wearing information are used to train an improved YOLOv5 network model to obtain a helmet wearing detection model, including:
[0050] Performing a data enhancement operation on the first historical work site picture to obtain a second historical work site picture;
[0051] The improved YOLOv5 network model is trained using the second historical work site picture and the corresponding historical safety helmet wearing condition information to obtain the safety helmet wearing condition detection model.
[0052] The embodiment of the present invention constructs an improved YOLOv5 network model corresponding to the second historical work site picture, trains the improved YOLOv5 network model according to the second historical work site picture and the corresponding historical helmet wearing information, obtains the trained YOLOv5 network model, verifies the trained improved YOLOv5 network model based on the second historical work site picture and the corresponding historical helmet wearing information, and obtains a helmet wearing detection model. The improved YOLOv5 network model is a YOLOv5 network model improved based on the CA attention mechanism, the prediction layer, the improved Neck network and the improved loss function.
[0053] Step S103, inputting the work site video into the helmet wearing condition detection model optimized based on the multi-target tracking algorithm to obtain the helmet wearing condition detection result of the work site video;
[0054] In an optional embodiment, the work site video is input into the helmet wearing condition detection model optimized based on the multi-target tracking algorithm to obtain the helmet wearing condition detection result of the work site video, including:
[0055] Utilizing a multi-target tracking algorithm, the helmet wearing condition detection model is optimized to obtain an optimal tracking detection model;
[0056] Inputting the work site video into the optimal tracking detection model to obtain a safety helmet wearing condition detection result of the work site video;
[0057] The embodiment of the present invention optimizes the safety helmet wearing detection model through a multi-target tracking algorithm, so that the safety helmet wearing detection model has the ability to track video targets, and obtains the optimal tracking detection model. The work site video is input into the optimal tracking detection model. The optimal tracking detection model captures each frame of the picture from the work site video and automatically identifies the position of the worker's safety helmet and the worker's safety helmet wearing status, and outputs the safety helmet wearing detection result of the work site video.
[0058] A method for detecting the wearing condition of a helmet provided in an embodiment of the present invention comprises: obtaining a video of a work site taken by a camera, and obtaining a training sample for detecting the wearing condition of a helmet in a database, wherein the training sample comprises a first historical work site picture and corresponding historical helmet wearing condition information, and using the first historical work site picture and corresponding historical helmet wearing condition information to train an improved YOLOv5 network model to obtain a helmet wearing condition detection model, wherein the improved YOLOv5 network model is a YOLOv5 network model improved based on a CA attention mechanism, a prediction layer, an improved Neck network, and an improved loss function, and the work site video is input into the helmet wearing condition detection model optimized based on a multi-target tracking algorithm to obtain a helmet wearing condition detection result of the work site view. A method for detecting the helmet wearing condition detection result of the work site view using an optimal tracking detection model is formed, so as to solve the problem of inaccurate helmet wearing condition detection due to complex work site conditions and fatigue of monitoring personnel, and lay an important foundation for the safe operation of operators.
[0059] Embodiment 2
[0060] See also Figure 2 , Figure 2 This is a flowchart of a second embodiment of a method for detecting the wearing condition of a helmet according to the present invention, and the steps include:
[0061] S201, obtaining a video of the work site taken by a camera, and obtaining a safety helmet wearing condition detection training sample in a database; the safety helmet wearing condition detection training sample includes a first historical work site picture and corresponding historical safety helmet wearing condition information;
[0062] The embodiment of the present invention is a work site video captured by a camera, and the work site video is a work site scenario where the helmet wearing condition needs to be detected. A helmet wearing condition detection training sample in a database is obtained. The helmet wearing condition detection training sample includes a first historical work site picture and corresponding historical helmet wearing condition information. The first historical work site picture is a historical picture of the work site, and the helmet wearing condition information is the helmet wearing condition of the historical picture. Any work site picture is extracted from the historical pictures in the database as the first historical work site picture, and the helmet wearing condition corresponding to the work site picture is extracted as the historical helmet wearing condition information, thereby extracting a large amount of data in the database to form a helmet wearing condition detection training sample, and the above-obtained data is set as a test set and a validation set for training the model, so that the trained model can identify the helmet wearing condition of the operator.
[0063] Among them, the helmet wearing status in the historical helmet wearing status information can be determined through manual labeling and other methods.
[0064] S202, performing a data enhancement operation on the first historical work site picture to obtain a second historical work site picture;
[0065] The embodiment of the present invention uses the K-means clustering algorithm to generate the initial anchor frame parameters that best match the characteristics of the data set, and uses the Mosaic-9 data enhancement method to perform data enhancement operations on the first historical work site picture, such as using basic methods such as random increase or decrease of brightness, contrast, saturation, hue, and random scaling, cropping, flipping, and erasing to process the first historical work site picture to obtain the second historical work site picture. The data enhancement method is not limited to the above method, and can be replaced by existing technologies according to actual needs.
[0066] For example, nine pictures (pictures of the first historical operation site) are randomly cropped, randomly arranged, and randomly scaled, and then combined into one picture to increase the amount of sample data. At the same time, some random noise is reasonably introduced to enhance the network model's ability to distinguish small target samples in the image and improve the generalization ability of the model. This can increase the number of small targets in the data set, thereby improving the model's ability to detect small target objects.
[0067] S203, using the second historical work site picture and the corresponding historical helmet wearing information, training the improved YOLOv5 network model to obtain a helmet wearing detection model; the improved YOLOv5 network model is a YOLOv5 network model improved based on CA attention mechanism, prediction layer, improved Neck network and improved loss function;.
[0068] In an optional embodiment, the improved YOLOv5 network model is trained using the second historical work site picture and the corresponding historical helmet wearing information to obtain the helmet wearing detection model, including:
[0069] Constructing the improved YOLOv5 network model corresponding to the second historical work site picture;
[0070] According to the second historical work site picture and the corresponding historical helmet wearing information, training the improved YOLOv5 network model to obtain a trained YOLOv5 network model;
[0071] Based on the second historical work site picture and the corresponding historical safety helmet wearing information, the trained improved YOLOv5 network model is verified to obtain the safety helmet wearing detection model.
[0072] The embodiment of the present invention constructs a corresponding YOLOv5 network model according to the second historical work site picture, and improves the YOLOv5 network model by introducing an attention mechanism, adding a prediction layer, and improving a loss function, thereby obtaining an improved YOLOv5 network model.
[0073] The improved YOLOv5 network model is as follows Figure 3 As shown, the improved YOLOv5 network model is based on the improved method of the YOLOv5 network model as follows:
[0074] 1) Introducing the attention mechanism;
[0075] The principle of the attention mechanism can be understood as that when the model processes the input data, in order to achieve a specific task, it needs to pay attention to some important information from the input data and ignore some unimportant information. Therefore, the attention mechanism can adjust the model's attention to each input data by weighting different input data, thereby improving the performance of the model. The CA attention mechanism can adaptively select and adjust the feature weights of different channels to better express the input data. It can help the model discover and utilize important channel information in the input data, and improve the discriminative ability and distinguishability of the features. In addition, adding the CA attention mechanism can significantly improve the performance of the model on multi-channel input data. It can help the model better capture the correlation and dependency between channels, thereby improving the model's ability to understand the input data. The present invention adds the CA attention mechanism to the YOLOv5 network architecture. This attention mechanism hardly increases the amount of calculation, can obtain more feature information, and help the model locate and identify more accurately. The role of adding the attention mechanism to the backbone basic network is to let the training network know which part to focus on, so as to achieve the prominent performance of important features and suppress less obvious features.
[0076] In the YOLOv5 network architecture, the added CA attention mechanism is located between C3 and CONV of the backbone basic network. Different from other improved methods, this method adds a single-layer CA attention mechanism. The CA attention mechanism adopts the group convolution method. Group convolution is used to improve the CNN architecture. After several layers of convolution, each position of the feature map contains information about a local area of the original image. The maximum and average values of multiple channels at each position are taken as weighting coefficients. The high-dimensional (low-dimensional) channel includes long (short) convolutions under the condition of a fixed number of groups. Practice has proved that this method can ensure speed and improve performance. It makes full use of the captured position information so that the area of interest is accurately captured, and also effectively captures the relationship between channels.
[0077] 2) Add prediction layer;
[0078] The YOLOv5s model has only three prediction layers. When an image of size 640×640 is input into the network, the Neck network performs 8x, 16x, and 32x downsampling respectively. The corresponding prediction layer feature map sizes are 80×80, 40×40, and 20×20, which are used to detect small targets, medium targets, and large targets. In the actual high-risk operation scenario, the distance between the operator and the camera is different, and the size of the image is different. When the distance is far, there are very small targets. In order to improve the recognition accuracy of small targets at a long distance, a prediction layer is added to the original YOLOv5s network, and one upsampling is added to the Neck network. After the third upsampling, it is fused with the second layer of the backbone network to obtain a newly added 160×160 prediction layer for detecting small targets. The improved model uses four prediction layers of prediction scales, making full use of the high resolution of the underlying features and the high semantic information of the deep features, without significantly increasing the network complexity.
[0079] 3) Use AFPN to replace the original PANet;
[0080] Adding AFPN (Adaptive Feature Pyramid Network) to YOLOv5 can improve the accuracy of target detection. AFPN is a function enhancement module for target detection tasks, which can adaptively fuse feature maps from different levels to provide better target positioning and scale adaptation capabilities. It has a relatively good detection effect on the wearing of hard hats during high-risk operations.
[0081] The neck network layer of YOLOv5 currently uses PANet, which has only a unidirectional information flow from top to bottom. Here, an asymptotic feature pyramid network (AFPN) is used to support direct interaction of non-adjacent layers. AFPN is started by fusing two adjacent Low-Level features and gradually incorporates High-Level features into the fusion process. In this way, large semantic gaps between non-adjacent levels can be avoided. Considering that multi-target information conflicts may occur during the feature fusion process at each spatial position, adaptive spatial fusion operations are further used to alleviate these inconsistencies. The specific operation steps are: first, the feature extraction part of YOLOv5 is adjusted to enable it to generate feature maps of multiple scales, which can provide more rich information for the AFPN module. Then the output of the AFPN module is connected to the detection head of YOLOv5 to perform object detection at different scales. Finally, a learnable parameter is defined while adding the AFPN network, and normalization is performed to control the weight value to enhance the effect of feature fusion. After adding AFPN and a small target detection layer, although it will increase the amount of computation slightly, the improved network can achieve good results on datasets with dense targets and simple features such as helmet wearing.
[0082] 4) Improve the loss function;
[0083] The loss function can be simply understood as each sample will get a predicted value after passing through the algorithm model, and then the difference between the predicted value and the true value becomes the loss function. The loss function is used to evaluate the degree of difference between the predicted value and the true value of the algorithm model. It is a non-negative real-valued function. The smaller the loss function, the better the performance of the algorithm model.
[0084] YOLOv5 uses the CIOU loss function, which is improved to EIOU to accelerate convergence and improve regression accuracy. The EIOU loss function solves the fuzzy definition of aspect ratio on the basis of CIOU, and adds Focal Loss to solve the sample imbalance problem in BBox regression. The CIOU loss function used by YOLOv5 takes into account three geometric parameters: overlapping area, center point distance, and aspect ratio.
[0085] The CIOU formula is as follows:
[0086]
[0087] Loss c =1-CIOU;
[0088] Among them, CIOU is the CIOU loss function; IOU is the intersection-over-union ratio, that is, the ratio of the intersection area of the predicted box and the true box to their union area; v is the aspect ratio, that is, the aspect ratio consistency measure, which is used to measure the aspect ratio difference between the predicted box and the true box; b is the predicted box; b gt is the real box; ρ is the Euclidean distance; α is the adjustment coefficient, which is used to control the weight of the center point distance and the aspect ratio; c is the diagonal length of the minimum bounding box of the predicted box and the real box; w is the width of the predicted box, h is the height of the predicted box, and w gt is the height of the real frame, h gt is the width of the real box, Loss c is the loss function.
[0089] The v in the formula reflects the aspect ratio, and its definition is still vague. There is still some gap between the actual difference between width and height and their confidence, which will cause problems that hinder the model from effectively optimizing similarity. To solve this problem, it is proposed to split the aspect ratio on the basis of CIOU, that is, to improve the penalty term. On the basis of the penalty term of CIOU, the influencing factor of the aspect ratio is split to calculate the length and width of the target box and the anchor box respectively, and then become EIOU. This loss function contains three parts: overlap loss, center distance loss and width and height loss. Compared with CIOU, this loss function converges faster, and Focal Loss is added on the basis of EIOU to solve the sample imbalance problem in BBox regression.
[0090] The EIOU formula is as follows:
[0091]
[0092] Among them, L EIOU is the EIOU loss function, L IOU is the overlap loss, L dis is the center distance loss, L asp is the width-height loss, C h is the minimum enclosing rectangle height, C w The minimum width of the bounding rectangle.
[0093] The benefits of changing CIOU to EIOU are as follows: the aspect ratio loss term is split into the difference between the predicted width and height and the minimum bounding box width and height, which accelerates convergence and improves regression accuracy; Focal Loss is introduced to optimize the sample imbalance problem in the bounding box regression task, that is, to reduce the optimization contribution of a large number of anchor boxes that have less overlap with the target box to the BBox regression, so that the regression process focuses on high-quality anchor boxes.
[0094] In summary, the YOLOv5 network model is improved to obtain an improved YOLOv5 network model.
[0095] The second historical work site picture is input into the improved YOLOv5 network model to obtain the corresponding helmet wearing detection output. The second historical work site picture and the corresponding historical helmet wearing information in the database are compared with the helmet wearing detection output obtained by inputting the second historical work site picture into the improved YOLOv5 network model to obtain training errors, such as the size deviation and position deviation of the helmet position (i.e., the head position of the operator) in the historical helmet wearing information and the helmet wearing detection output. The training errors are used to adjust the parameters of the improved YOLOv5 network model. If the training error is the position deviation of the helmet position in the historical helmet wearing information and the helmet wearing detection output, the corresponding model parameters are modified to make the helmet wearing position of the helmet wearing detection output more accurate, and the optimal parameters are obtained. The improved YOLOv5 network model is optimized through the optimal parameters to obtain the trained YOLOv5 network model.
[0096] Before inputting data to train the model, the parameters of the improved YOLOv5 network model must be initialized to ensure that the model is in normal use.
[0097] The second historical work site picture in the database that is not used for training is input into the trained YOLOv5 network model to obtain the corresponding helmet wearing detection output, and the helmet wearing detection output is used as verification data. The verification data is compared with the historical helmet wearing information corresponding to the second historical work site picture that is not used for training to determine whether the error of the trained YOLOv5 network model is within an acceptable range (the acceptable error range is generally 0 to 3%, which can be modified according to actual needs), verify the accuracy of the trained YOLOv5 network model, and obtain a helmet wearing detection model.
[0098] S204, optimizing the helmet wearing detection model using a multi-target tracking algorithm to obtain an optimal tracking detection model;
[0099] The embodiment of the present invention utilizes a multi-target tracking algorithm to effectively improve the feature extraction capability of the safety helmet wearing detection model, so as to optimize the safety helmet wearing detection model, and enable the safety helmet wearing detection model to have the ability to track targets in video, and to be able to extract each frame of the image from the video and automatically identify the workers and the workers' safety helmet wearing conditions, so as to obtain the final optimal tracking detection model, thereby improving the accuracy of safety helmet wearing detection for workers in high-risk working scenarios.
[0100] S205, inputting the work site video into the optimal tracking detection model to obtain a helmet wearing condition detection result of the work site video;
[0101] The optimal tracking detection model of the embodiment of the present invention automatically recognizes the video of the work site, captures each frame of the video from the work site, and automatically recognizes the position of the worker's helmet and the worker's helmet wearing condition, and outputs the helmet wearing condition detection result of the work site video, such as Figure 4 As shown, Figure 4 The position marked in the square box is the position of the helmet, and helmet means wearing a helmet.
[0102] A method for detecting the wearing condition of a helmet disclosed in an embodiment of the present invention comprises: obtaining a video of a work site taken by a camera, and obtaining a training sample for detecting the wearing condition of a helmet in a database, wherein the training sample for detecting the wearing condition of a helmet comprises a first historical work site picture and corresponding historical information on wearing condition of a helmet, and using the first historical work site picture and corresponding historical information on wearing condition of a helmet to train an improved YOLOv5 network model to obtain a model for detecting the wearing condition of a helmet, wherein the improved YOLOv5 network model is a YOLOv5 network model improved based on a CA attention mechanism, a prediction layer, an improved Neck network and an improved loss function, and the work site video is input into the model for detecting the wearing condition of a helmet optimized based on a multi-target tracking algorithm to obtain a detection result of the wearing condition of a helmet in the work site. The method solves the problem of inaccurate detection of the wearing condition of a helmet due to complex work site conditions and fatigue of monitoring personnel, and lays an important foundation for the safe operation of operators. At the same time, the method is highly operable, and the process of detecting the wearing condition of a helmet in actual use is intuitive and clear, and can be easily promoted and applied to the detection process of the wearing condition of a helmet of an operator.
[0103] To facilitate the understanding of the present invention by those skilled in the art, the method of the present invention is illustrated below by taking the acquisition of a helmet wearing detection data set of 10,000 images to determine the helmet wearing situation as an example.
[0104] Example: Get a helmet wearing detection dataset containing 10,000 images, and manually annotate them. The annotation tool uses labels to divide them into two categories, helmet and nohelmet, where helmet means wearing a helmet and nohelmet means not wearing a helmet. The annotated helmet dataset is divided into training set, validation set and test set in a ratio of 8:1:1. The training set is used to train the improved YOLOv5 model, the validation set is used to verify the training results and adjust the parameters to obtain the helmet wearing detection model, and then the multi-target tracking algorithm is used to optimize the helmet wearing detection model to obtain the optimal tracking detection model, and the test set is mainly used for the final evaluation of the trained optimal tracking detection model.
[0105] It should be noted that the model evaluation indicators when evaluating the model mainly include precision P (precision), recall R (recall) and mean average precision (mAP). Precision is the accuracy rate, which indicates the ratio of the number of samples predicted as positive in the prediction results to the true positive samples. Recall rate indicates the ratio of the number of positive examples in the original samples that are predicted correctly. mAP is the sum of the average precision of all categories divided by the average precision of all categories in the data set. In this experiment, TP, FP and FN represent the number of correctly detected boxes, falsely detected boxes and missed boxes respectively:
[0106]
[0107] Among them, mAP is the mean average precision, Recall is the recall rate, Precision is the accuracy, TP is the number of correctly detected boxes, FP is the number of falsely detected boxes, and FN is the number of missed boxes.
[0108] While ensuring the same parameters, the initial learning rate is 0.01, the batch size is 16, and after 500 rounds of training, the weight file best.pt is obtained. The images in the test set are input into the YOLOv5 target detection model generated by the improved training to obtain the detection results of the model in the test set.
[0109] After experiments, the following parameters were obtained. The performance comparison of the YOLOv5 model is shown in the following table:
[0110] category Precision Recall R Mean average precision mAP YOLOv5 algorithm model 0.912 0.908 0.916 Improved YOLOv5 algorithm model 0.934 0.927 0.561
[0111] It can be seen from the above table that the improved YOLOv5 algorithm has better effect on helmet wearing detection than the original YOLOv5 algorithm.
[0112] In summary, the optimal tracking detection model of the embodiment of the present invention can improve the accuracy of workers' helmet wearing detection in high-risk operation scenarios.
[0113] Embodiment 3
[0114] See also Figure 5 , Figure 5 This is a structural block diagram of an embodiment of a helmet wearing condition detection device of the present invention, the device comprises:
[0115] The acquisition module 301 is used to acquire the work site video captured by the camera and acquire the helmet wearing condition detection training samples in the database; the helmet wearing condition detection training samples include the first historical work site picture and the corresponding historical helmet wearing condition information;
[0116] The training module 302 is used to train the improved YOLOv5 network model using the first historical work site picture and the corresponding historical helmet wearing information to obtain a helmet wearing detection model; the improved YOLOv5 network model is a YOLOv5 network model improved based on the CA attention mechanism, the prediction layer, the improved Neck network and the improved loss function;
[0117] The input module 303 is used to input the work site video into the optimal tracking detection model based on the multi-target tracking algorithm to obtain the helmet wearing condition detection result of the work site video.
[0118] In an optional embodiment, the training module 302 includes:
[0119] An operation submodule, configured to perform a data enhancement operation on the first historical operation site picture to obtain a second historical operation site picture;
[0120] The training submodule is used to train the improved YOLOv5 network model using the second historical work site picture and the corresponding historical safety helmet wearing information to obtain the safety helmet wearing detection model.
[0121] In an optional embodiment, the training submodule includes:
[0122] A construction unit, configured to construct the improved YOLOv5 network model corresponding to the second historical operation site picture;
[0123] A training unit, configured to train the improved YOLOv5 network model according to the second historical work site picture and the corresponding historical helmet wearing information to obtain a trained YOLOv5 network model;
[0124] A verification unit is used to verify the trained improved YOLOv5 network model based on the second historical work site picture and the corresponding historical helmet wearing information to obtain the helmet wearing detection model.
[0125] In an optional embodiment, the building block comprises:
[0126] A construction subunit, configured to construct a YOLOv5 network model corresponding to the second historical operation site picture;
[0127] The improvement subunit is used to improve the YOLOv5 network model to obtain the improved YOLOv5 network model.
[0128] In an optional embodiment, the training unit includes:
[0129] An input subunit, used for inputting the second historical work site picture into the improved YOLOv5 network model to obtain a corresponding helmet wearing detection output;
[0130] a determination subunit, configured to determine a training error based on the second historical work site picture and the corresponding historical helmet wearing condition information and the corresponding historical helmet wearing condition information;
[0131] The optimization subunit is used to adjust the parameters of the improved YOLOv5 network model based on the training error to obtain the optimal parameters, and optimize the improved YOLOv5 network model using the optimal parameters to obtain the trained YOLOv5 network model.
[0132] In an optional embodiment, the input module 303 includes:
[0133] An optimization submodule, used to optimize the helmet wearing condition detection model by using a multi-target tracking algorithm to obtain an optimal tracking detection model;
[0134] The input submodule is used to input the work site video into the optimal tracking detection model to obtain the helmet wearing condition detection result of the work site video.
[0135] Embodiment 4
[0136] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of a method for detecting the wearing condition of a helmet in any embodiment.
[0137] Embodiment 5
[0138] An embodiment of the present invention further provides a computer storage medium on which a computer program is stored. When the computer program is executed by the processor, the steps of a method for detecting the wearing condition of a helmet in any embodiment are implemented.
[0139] Embodiment 6
[0140] An embodiment of the present invention further provides a computer program product on which a computer program is stored. When the computer program is executed by the processor, the steps of a method for detecting the wearing condition of a helmet in any embodiment are implemented.
[0141] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0142] In the several embodiments provided in the present application, it should be understood that the methods, devices, electronic devices and storage media disclosed in the present invention can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0143] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0144] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0145] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a readable storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned readable storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0146] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for detecting the wearing condition of a helmet, characterized in that: include: Obtaining a work site video captured by a camera, and obtaining a helmet wearing condition detection training sample in a database; the helmet wearing condition detection training sample includes a first historical work site picture and corresponding historical helmet wearing condition information; Using the first historical work site picture and the corresponding historical helmet wearing information, an improved YOLOv5 network model is trained to obtain a helmet wearing detection model; the improved YOLOv5 network model is a YOLOv5 network model improved based on a CA attention mechanism, a prediction layer, an improved Neck network and an improved loss function; The work site video is input into the safety helmet wearing condition detection model optimized based on the multi-target tracking algorithm to obtain the safety helmet wearing condition detection result of the work site video.
2. The method for detecting the wearing condition of a helmet according to claim 1, characterized in that: Using the first historical work site picture and the corresponding historical helmet wearing information, the improved YOLOv5 network model is trained to obtain a helmet wearing detection model, including: Performing a data enhancement operation on the first historical work site picture to obtain a second historical work site picture; The improved YOLOv5 network model is trained using the second historical work site picture and the corresponding historical safety helmet wearing condition information to obtain the safety helmet wearing condition detection model.
3. The method for detecting the wearing condition of a helmet according to claim 2, characterized in that: Using the second historical work site picture and the corresponding historical helmet wearing information, the improved YOLOv5 network model is trained to obtain the helmet wearing detection model, including: Constructing the improved YOLOv5 network model corresponding to the second historical work site picture; According to the second historical work site picture and the corresponding historical helmet wearing information, training the improved YOLOv5 network model to obtain a trained YOLOv5 network model; Based on the second historical work site picture and the corresponding historical safety helmet wearing condition information, the trained improved YOLOv5 network model is verified to obtain the safety helmet wearing condition detection model.
4. The method for detecting the wearing condition of a helmet according to claim 3, characterized in that: Constructing the improved YOLOv5 network model corresponding to the second historical operation site picture, including: Constructing a YOLOv5 network model corresponding to the second historical operation site picture; The YOLOv5 network model is improved to obtain the improved YOLOv5 network model.
5. The method for detecting the wearing condition of a helmet according to claim 3, characterized in that: According to the second historical work site picture and the corresponding historical helmet wearing information, the improved YOLOv5 network model is trained to obtain the trained YOLOv5 network model, including: Inputting the second historical work site picture into the improved YOLOv5 network model to obtain a corresponding helmet wearing condition detection output; determining a training error based on the second historical work site picture and the corresponding historical helmet wearing condition information and the corresponding historical helmet wearing condition information; Based on the training error, the parameters of the improved YOLOv5 network model are adjusted to obtain optimal parameters, and the improved YOLOv5 network model is optimized using the optimal parameters to obtain the trained YOLOv5 network model.
6. The method for detecting the wearing condition of a helmet according to claim 5, characterized in that: The work site video is input into the helmet wearing condition detection model optimized based on the multi-target tracking algorithm to obtain the helmet wearing condition detection result of the work site video, including: Utilizing a multi-target tracking algorithm, the helmet wearing condition detection model is optimized to obtain an optimal tracking detection model; The work site video is input into the optimal tracking detection model to obtain a safety helmet wearing condition detection result of the work site video.
7. A helmet wearing condition detection device, characterized in that: include: The acquisition module is used to acquire the work site video captured by the camera and to acquire the helmet wearing condition detection training samples in the database; the helmet wearing condition detection training samples include the first historical work site picture and the corresponding historical helmet wearing condition information A training module, used to train an improved YOLOv5 network model using the first historical work site picture and the corresponding historical helmet wearing information to obtain a helmet wearing detection model; An optimization module, used to optimize the helmet wearing condition detection model by using a multi-target tracking algorithm to obtain an optimal tracking detection model; An input module is used to input the work site video into the optimal tracking detection model to obtain a safety helmet wearing condition detection result of the work site video.
8. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the method according to any one of claims 1 to 6 is executed.
9. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is executed.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Cited By
Helmet wearing detection method and device for two-wheeled vehicle, electronic equipment and medium
CN120655951A