Safety helmet standard wearing detection method based on improved YOLOv8
By improving the YOLOv8 network structure, adopting deformable convolution V2 and MPCA mechanisms, combined with the "collect-distribution" information fusion mechanism, the problems of low detection accuracy and difficult to detect small targets in safety helmet standard wear detection are solved, and a safety helmet standard wear detection with higher accuracy and robustness are achieved.
Patent Information
- Application Number
- CN202411383325.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-03-07
AI Technical Summary
The prior art has problems in the standardized wear detection of safety helmets with low detection accuracy and difficult to accurately detect small targets, especially in complex environments, it is difficult to effectively identify the standardized wear status of the safety helmets.
Using the improved YOLOv8 network structure, the size of the convolution kernel is dynamically adjusted and feature extraction and fusion capabilities are enhanced by introducing deformable convolution V2 and MPCA mechanisms. Combined with the "collect-distribution" information fusion mechanism, the multi-scale feature fusion module is improved to enhance the model's ability to identify the standardized wear behavior of the safety helmet.
It improves the accuracy and robustness of standardized wear detection of safety helmets, can more accurately identify whether workers wear safety helmets, reduces missed inspections, and improves the accuracy of small target detection in complex background environments.
Smart Images

Figure CN119580177A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer vision target detection, and in particular to a method for detecting standard wearing of a helmet based on an improved YOLOv8. Background Art
[0002] Safety helmets are essential protective equipment for production workers in various industries, which can protect the head from falling objects. Traditionally, the identification of safety helmet wearing is carried out through manual supervision through monitoring, but manual supervision takes a long time, is inefficient, and there are subjective differences among people, making it difficult to achieve real-time supervision and detection, which cannot meet the needs of production safety in modern society. Therefore, in production safety management, it is particularly important to detect whether workers are wearing safety helmets in a standardized manner. However, there are currently few studies on the standardized wearing of safety helmets, especially in complex environmental scenarios. Problems such as low accuracy of safety helmet standardized wearing detection and difficulty in accurately detecting small targets are still difficult to solve.
[0003] In recent years, the development of deep learning has produced many target detection algorithms. The current mainstream target detection algorithms are divided into two categories: one is a single-stage algorithm based on regression. The other is a two-stage algorithm based on candidate regions. The two-stage algorithm has high accuracy but cumbersome training; the one-stage algorithm has higher real-time performance but slightly lower accuracy. YOLO is a one-stage algorithm. The paper "YOLOv8: A Novel Object Detection Algorithm with Enhanced Performance and Robustness" introduces the YOLOv8 algorithm in detail, which improves the accuracy and robustness of target detection through improved network architecture and loss function. It can be seen that YOLOv8 is an excellent version in the YOLO series. Compared with other versions, it can be applied to a wider range of fields and is more flexible.
[0004] In the article "Analysis of Helmet Wearing Target Detection Technology Based on Jetson Nano and Improved YOLOv7 Algorithm", the author implemented the detection of helmets based on the YOLOv7 network, but the solution can only determine whether the helmet is worn, but cannot detect whether the helmet is worn in a standardized manner. Further reference to domestic and foreign literature found that the research on the standardized wearing of helmets is still in the exploratory stage, and there is no high-precision detection solution. Summary of the invention
[0005] In view of the technical problems that there are few new methods for detecting the details of helmet buckle wearing in the current safety helmet standard wearing detection, the detection accuracy is low, and small targets are easily missed and misdetected, the purpose of the present invention is to provide a safety helmet standard wearing detection method based on improved YOLOv8, by improving the YOLOv8 network structure, adding offsets during the training process to extract more comprehensive features, fusing non-adjacent hierarchical features to enhance the model's multi-scale feature fusion capability, and accurately identifying whether the safety helmet is worn in a standardized manner. This method not only helps managers to effectively supervise the wearing of safety helmets at the work site, but also provides new ideas and examples for deep learning-based target detection technology in the field of safety helmet detection.
[0006] In order to achieve the above-mentioned invention object, the technical solution adopted by the present invention is specifically: a helmet standard wearing detection method based on improved YOLOv8, comprising the following steps:
[0007] S1. Sample data collection
[0008] (1) Data on the wearing of hard hats by construction workers on site are collected by downloading public datasets, using web crawler tools, and extracting key frames from surveillance videos. A dataset of standard hard hat wearing is created for training the model.
[0009] (2) Use the LabelImg annotation tool to classify and annotate the images in the dataset. The annotated categories include two categories: wearing a helmet properly (true) and not wearing a helmet properly (false). When annotating, ensure that the helmet mark covers the person's head and the helmet itself. After the annotation is completed, a label file in XML format is generated, forming a dataset in VOC format (XML file).
[0010] (3) Convert the label file in xml format into the txt file format required to improve the YOLOv8 helmet standard wearing detection model, and divide the data into training set and validation set in a ratio of 9:1 for model training.
[0011] S2, using deformable convolution Deformable ConvolutionV2 to replace traditional convolution
[0012] Traditional convolution generally uses a rectangular structure of fixed size and proportion to extract features at a specific position in the feature map. Therefore, traditional convolution has good performance when processing some static or relatively regular low-complexity targets. However, helmet standard wearing detection is often a dynamic task, and the detection is easily affected by environmental factors. In general, the targets to be tested at various positions on the feature layer are of different scales and shapes, so conventional convolution cannot adapt well to the deformation between the targets, which reduces the effective information extracted by the model and easily misses the key feature information of the target.
[0013] In order to make the convolutional neural network have a better ability to recognize geometric transformations, deformable convolution is introduced instead of conventional convolution. Deformable convolution can automatically adapt and adjust the size of the convolution kernel according to the shape and proportion of the object to be measured, so that the network model can better simulate the deformation of the object.
[0014] Deformable convolution adds an offset to each sampling point based on traditional convolution. Assuming the size of the convolution kernel is 3×3, there are 9 sampling points for this convolution kernel. These 9 sampling points are all assigned an offset, so that the position and size of the convolution kernel can be dynamically adjusted according to the target object, which can better fit the size and shape of the object during feature extraction, and optimize the model's detection performance for irregular and deformed targets.
[0015] In deformable convolution, the formula for the output eigenvalue of a certain sampling point p0 is:
[0016]
[0017] In the formula, R = {(-1,-1), (-1,0), ..., (0,1), (1,1)}, w (pn) is the weight of the sampling point, x is the input feature map, pn represents the position element in R, and x (pn + p0 + Δpn) represents the sampling position of the feature map to be detected. Δpn is the offset added to the conventional convolution sampling point. Δpn can adjust the sampling position of the position element, thereby enhancing the model's adaptability to the recognition of helmet standard wearing behavior.
[0018] First, the input image is feature extracted using a conventional convolution kernel. The output feature map is then passed through an additional offset field layer to obtain the offset field of the convolution kernel sampling point, which has 2N channels, including the offsets in the x and y directions on the 2D plane. The obtained offset field size and input feature Figure 1 The offset matrix of the convolution kernel sampling point can be obtained from it, and the offset Δpn can be obtained from it. The sampling point offset is updated and optimized using the interpolation algorithm and the back propagation algorithm.
[0019] The sampling point position pixel x(p0+pn+Δpn) after the offset is introduced is calculated using the bilinear interpolation method, and the formula is:
[0020]
[0021] Among them, p = p0 + pn + Δpn represents any position in the region, q represents all spatial positions in the input feature map, that is, the four integer points around p. x(q) represents the value of all integer positions in the feature map, G(q,p) is a bilinear interpolation kernel function of a two-dimensional kernel, which can be decomposed into two one-dimensional kernels, and the formula is:
[0022] G(q,p)=g(q x ,p x )·g(q y ,p y )
[0023] In the above formula: g(a,b)=max{0,1-|ab|}
[0024] Introducing deformable convolution into the network model not only improves the fitting ability for irregularly shaped objects, but also reduces omissions during feature extraction, making the target information of the detected object more complete. In practical applications, researchers found that deformable convolution has a good fitting effect on small targets, but when fitting large detection targets, irrelevant background information may be included, introducing irrelevant areas and causing interference. Therefore, DCNv2 is proposed based on DCNv1.
[0025] In order to further improve the fitting ability of irregularly shaped objects, DCNv2 adds weight values to each sampling point on the basis of DCNv1, and the calculation formula of the output eigenvalue y(p0) is:
[0026]
[0027] Introducing weight coefficient Δm n , suppress irrelevant background information, so that the model can reduce the interference of irrelevant content when learning features
[0028] S3. DCNV2 improvement based on MPCA
[0029] Existing models have limitations in identifying the wearing details of helmets under different posture changes, especially in complex environments, and lack robust feature extraction and fusion capabilities, which easily causes information loss. At the same time, since the original DCNv2 only uses a single layer of convolution to generate offset_mask, the generation capability is weak. In addition, there are limitations to obtaining sampling weights only through convolution operations. This single calculation mode limits the ability of DCNV2 to dynamically allocate sampling weights for each sampling point, thereby reducing the model's adaptability to the details of helmet wearing specifications. In response to these challenges, the present invention uses MPCA to strengthen DCNV2 to enhance the model's feature extraction and fusion capabilities.
[0030] The MPCA mechanism improves on the original CA attention mechanism. The CA mechanism captures spatial feature dependencies through one-dimensional global average pooling (GAP) in the horizontal and vertical directions, respectively, and then generates attention maps in two directions. However, in order to enhance its ability to generate offset_mask, the present invention makes some improvements.
[0031] Based on the CA attention mechanism, this paper adds a GAP channel branch to process the input feature F∈R in a different way from CA. C×H×W , thereby preserving the global feature information F when performing average pooling in the X and Y directions gap We stimulate the fusion and exchange of feature information in the X and Y directions through concatenation and convolution operations, thus generating F hw Then, by splitting F h Get feature F w and F hw . hw Further convolution and sigmoid operations are performed to obtain F hw weight , split it to get the feature weight F in the X direction h weight and the feature weight F in the Y direction w weight Multiply these weights by F h and F w Get F x and F y , revealing more detailed features in the above directions.
[0032] The present invention adopts the YOLOv8 detection model, whose backbone network integrates the C2f module, aiming to extract the features of the mirrored cross-stage partial network. The neck network adopts the path aggregation network (PAN) and the feature pyramid network (FPN) for effective feature fusion. After convolution, the output is forwarded to the detection head for the final solution of classification and regression problems. For the helmet standard wearing detection task, the traditional convolution operation in C2f is used to extract image features. Due to the fixed nature of the convolution kernel, it cannot solve the challenge of non-rigid deformation. In order to solve this problem, we fuse the DCNV2 strengthened by MPCA into C2f. While maintaining the basic structure of the C2f module, all traditional convolutions in the bottleneck are replaced by DCNV2 strengthened by MPCA, which enhances the feature extraction ability of the model. This operation helps to achieve more fine-grained feature interaction and fusion. Through multiple convolution and segmentation operations, not only the depth of the feature map is increased, but also the information about the x and y coordinates in the feature map becomes more refined and rich, enhancing the feature extraction and fusion capabilities of YOLOv8.
[0033] S4. Improved multi-scale feature fusion module
[0034] Information loss is a problem that exists in many detection algorithms. In the algorithm, different branches are responsible for detecting objects of different sizes. At the beginning, there is a lot of high-level semantic information in their feature maps, but during the propagation or fusion process, this semantic information will be dissipated, which means that the spatial information of the feature map obtained by the detection head is incomplete, which ultimately affects the performance of the algorithm.
[0035] YOLOv8 uses the traditional FPN-PAN network structure to fuse feature maps at different levels to improve detection accuracy. The traditional FPN-PAN structure contains multiple branches for multi-scale feature fusion, but they can only completely fuse the information of adjacent layers, and for the information of non-adjacent layers, they can only obtain it indirectly and recursively. This information fusion method will lead to huge information loss.
[0036] In order to avoid the loss caused by the traditional FPN-PAN network structure, we built a "Gather-and-Distribute" information fusion mechanism, using a unified module to collect and distribute information at all levels. In the C2f multi-scale feature fusion network, we used the FAM feature alignment module, the IFM information fusion module, and the Inject information injection module.
[0037] The C2f multi-scale feature fusion network can indeed retain semantic information, solve the problem of information loss to a certain extent, and improve the performance of the algorithm. The C2f multi-scale feature fusion network has two branches, namely the low-level convergence branch and the high-level convergence branch. These two branches fuse the feature maps from the high-level and low-level layers respectively, and then inject them into the feature maps of different layers through the Inject module. The LowFAM module uses the feature map size of B4 as the baseline size, B2 and B3 use the AvgPool layer to downsample the feature map to the B4 size, and the feature map of B5 is expanded to the B4 size using bilinear interpolation and spliced together in the channel. The design of the LowIFM module includes convolution, structural reparameterization RepConv Block, and splitting operations. The RepConv Block takes the output Falign after the low FAM module as input and divides the output into two outputs in the channel to facilitate the fusion of information at different levels. The formula is as follows:
[0038] F align =LowFAM([B2, B3, B4, B5])
[0039] F fuse =RepConv(F align )
[0040] P4, P3 = Split (F fuse )
[0041] In the above formula, the LowIFM module is a convolution, including convolution, structure reparameterization RepConv Block and splitting operation; RepConv Block takes the output Falign after the low FAM module as input, and divides the output into two outputs in the channel for the fusion of information at different levels.
[0042] The network structure of the Inject module. X Global is the global information generated by the IFM module, and X Local is the local information at different levels. Through low LAF and high LAF, the receiving range of the Injecet module is further expanded, thereby enhancing the characteristics of the module. By performing convolution, sampling, and interpolation operations on local and global information, different information is spliced in the channel. After calculation by the C2f module, the final output of the information injection module is obtained.
[0043] The C2f multi-scale feature fusion network works because it does not have to obtain information from other layers indirectly or recursively like the FPN-PAN network. It replaces the downward fusion and upward fusion operations in the FPN-PAN network through the LowGD module and the HighGD module, which means that all information in the C2f multi-scale feature fusion network is directly obtained, with less loss and higher efficiency, thereby improving the accuracy of the detector.
[0044] S5. Use the helmet standard wearing data set to train the improved YOLOv8 network model to obtain the trained model. Then input the images and videos to be detected into the trained model for inference and prediction to obtain the result of whether the worker wears the helmet in a standard manner.
[0045] Compared with the prior art, the present invention has the following beneficial effects:
[0046] 1. The present invention improves the YOLOv8 network and introduces deformable convolution V2 in the backbone part. The convolution kernel size is dynamically adjusted by generating an offset, which can accurately capture the shape changes of the helmet in the helmet wearing state. In addition, by learning the weight of each sampling point, the interference of environmental factors such as complex background on the helmet standard wearing detection task can be further reduced.
[0047] 2. The present invention proposes an MPCA mechanism based on the CA attention mechanism, adds a channel branch, connects multiple layers together for convolution and segmentation to achieve better information exchange, learns the weight of each sampling point to reduce the influence of interference factors such as the environment, and enhances the ability of variable convolution to generate offsets.
[0048] 3. The present invention improves the feature fusion module with the help of the "aggregation and distribution" mechanism in GOLD YOLO, strengthens the multi-scale feature fusion capability to solve the information loss problem, and thus can more accurately identify helmets of different sizes and locate tiny helmet buckles in images.
[0049] 4. The present invention can accurately detect the standard wearing of safety helmets by production workers in various industries, improve the detection accuracy of small targets in complex background environments, reduce missed detections and false detections, and effectively reduce the frequency of safety accidents on construction sites. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0051] Figure 1 This is a flow chart of the helmet standard wearing detection method based on the improved YOLOv8 network structure of the present invention.
[0052] Figure 2 This is a typical data set case diagram in the present invention.
[0053] Figure 3 Schematic diagram of the GD mechanism of the present invention.
[0054] Figure 4 This is a schematic diagram of the improved effect of the present invention. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. Of course, the specific embodiments described here are only used to explain the present invention and are not used to limit the present invention.
[0056] Example 1
[0057] See also Figure 1 and Figure 4 The technical solution provided in this embodiment is a method for detecting the standard wearing of a helmet based on an improved YOLOv8, comprising the following steps:
[0058] S1. Sample data collection
[0059] First, we download the public dataset and remove a large number of duplicate and low-quality samples from the public dataset, retain high-quality images, and add video frames of valid samples captured from surveillance videos for some categories to create a dataset, so that the data is rich in categories as a whole, and the dataset contains rich angles, postures, and environmental changes such as helmets. Finally, we use the LabelImg tool for labeling, including standard wearing of helmets (true) and non-standard wearing of helmets (false). The helmet annotation area includes the head above the neck and the helmet. The file is placed in the Annotations folder in xml format. Since the label format of YOLO is txt, it is converted to YOLO format through python code, and the training set and validation set are divided according to a certain ratio.
[0060] S2, Improvement of the backbone network based on Deformable Conv V2
[0061] Traditional convolution generally uses a rectangular structure of fixed size and proportion to extract features at a specific position in the feature map. Therefore, traditional convolution has good performance when processing some static or relatively regular low-complexity targets. However, helmet standard wearing detection is often a dynamic task, and the detection is easily affected by environmental factors. In general, the targets to be tested at various positions on the feature layer are of different scales and shapes, so conventional convolution cannot adapt well to the deformation between the targets, which reduces the effective information extracted by the model and easily misses the key feature information of the target.
[0062] In order to make the convolutional neural network have a better ability to recognize geometric transformations, deformable convolution is introduced instead of conventional convolution. Deformable convolution can automatically adapt and adjust the size of the convolution kernel according to the shape and proportion of the object to be measured, so that the network model can better simulate the deformation of the object.
[0063] Deformable convolution adds an offset to each sampling point based on traditional convolution. Assuming the size of the convolution kernel is 3×3, there are 9 sampling points for this convolution kernel. These 9 sampling points are all assigned an offset, so that the position and size of the convolution kernel can be dynamically adjusted according to the target object, which can better fit the size and shape of the object during feature extraction, and optimize the model's detection performance for irregular and deformed targets.
[0064] In deformable convolution, the formula for the output eigenvalue of a certain sampling point p0 is:
[0065]
[0066] In the formula, R = {(-1,-1), (-1,0), ..., (0,1), (1,1)}, w (pn) is the weight of the sampling point, x is the input feature map, pn represents the position element in R, and x (pn + p0 + Δpn) represents the sampling position of the feature map to be detected. Δpn is the offset added to the conventional convolution sampling point. Δpn can adjust the sampling position of the position element, thereby enhancing the model's adaptability to the recognition of helmet standard wearing behavior.
[0067] First, the input image is feature extracted using a conventional convolution kernel. The output feature map is then passed through an additional offset field layer to obtain the offset field of the convolution kernel sampling point, which has 2N channels, including the offsets in the x and y directions on the 2D plane. The obtained offset field size and input feature Figure 1 The offset matrix of the convolution kernel sampling point can be obtained from it, and the offset Δpn can be obtained from it. The sampling point offset is updated and optimized using the interpolation algorithm and the back propagation algorithm.
[0068] The sampling point position pixel x(p0+pn+Δpn) after the offset is introduced is calculated using the bilinear interpolation method, and the formula is:
[0069]
[0070] Among them, p = p0 + pn + Δpn represents any position in the region, q represents all spatial positions in the input feature map, that is, the four integer points around p. x(q) represents the value of all integer positions in the feature map, G(q,p) is a bilinear interpolation kernel function of a two-dimensional kernel, which can be decomposed into two one-dimensional kernels, and the formula is:
[0071] G(q,p)=g(q x ,p x )·g(q y ,p y )
[0072] Where: g(a,b)=max{0,1-|ab|}
[0073] Introducing deformable convolution into the network model not only improves the fitting ability for irregularly shaped objects, but also reduces omissions during feature extraction, making the target information of the detected object more complete. In practical applications, researchers found that deformable convolution has a good fitting effect on small targets, but when fitting large detection targets, irrelevant background information may be included, introducing irrelevant areas and causing interference. Therefore, DCNv2 is proposed based on DCNv1.
[0074] In order to further improve the fitting ability of irregularly shaped objects, DCNv2 adds weight values to each sampling point on the basis of DCNv1, and the calculation formula of the output eigenvalue y(p0) is:
[0075]
[0076] Introducing weight coefficient Δm n , irrelevant background information is suppressed, so that the model can reduce the interference of irrelevant content during feature learning.
[0077] S3. DCNV2 improvement based on MPCA
[0078] Existing models have limitations in identifying the details of helmet wearing under different posture changes, especially in complex environments, and lack robust feature extraction and fusion capabilities, which easily causes information loss. At the same time, since the original DCNv2 only uses a single layer of convolution to generate offset_mask, the generation capability is weak. In addition, there are limitations to obtaining sampling weights only through convolution operations. This single calculation mode limits the ability of DCNV2 to dynamically allocate sampling weights for each sampling point, thereby reducing the model's adaptability to the details of helmet wearing specifications. In response to these challenges, this embodiment uses MPCA to strengthen DCNV2 to enhance the model's feature extraction and fusion capabilities.
[0079] The MPCA mechanism improves upon the original CA attention mechanism. The CA mechanism captures spatial feature dependencies through one-dimensional global average pooling (GAP) in both horizontal and vertical directions, and then generates attention maps in both directions. However, in order to enhance its ability to generate offset_mask, this embodiment makes some improvements.
[0080] This embodiment adds a GAP channel branch based on the CA attention mechanism to process the input feature F∈R in a different way from CA C×H×W , thereby preserving the global feature information F when performing average pooling in the X and Y directions gap We stimulate the fusion and exchange of feature information in the X and Y directions through concatenation and convolution operations, thus generating F hw Then, by splitting F h Get feature F w and F hw . hw Further convolution and sigmoid operations are performed to obtain F hw weight , split it to get the feature weight F in the X direction h weight and the feature weight F in the Y direction w weight Multiply these weights by F h and F w Get F x and F y , revealing more detailed features in the above directions.
[0081] This embodiment uses the YOLOv8 detection model, whose backbone network integrates the C2f module to extract the features of the mirrored cross-stage partial network. The neck network uses a path aggregation network (PAN) and a feature pyramid network (FPN) for effective feature fusion. After convolution, the output is forwarded to the detection head for the final solution of classification and regression problems. For the helmet standard wearing detection task, the traditional convolution operation in C2f is used to extract image features. Due to the fixed nature of the convolution kernel, it cannot solve the challenge of non-rigid deformation. To solve this problem, we fuse the DCNV2 enhanced by MPCA into C2f. While maintaining the basic structure of the C2f module, all traditional convolutions in the bottleneck are replaced by DCNV2 enhanced by MPCA, which enhances the feature extraction capability of the model. This operation helps to achieve more fine-grained feature interaction and fusion. Through multiple convolution and segmentation operations, not only the depth of the feature map is increased, but also the information about the x and y coordinates in the feature map becomes more refined and rich, enhancing the feature extraction and fusion capabilities of YOLOv8.
[0082] S4. Improved multi-scale feature fusion module
[0083] Information loss is a problem that exists in many detection algorithms. In the algorithm, different branches are responsible for detecting objects of different sizes. At the beginning, there is a lot of high-level semantic information in their feature maps, but during the propagation or fusion process, this semantic information will be dissipated, which means that the spatial information of the feature map obtained by the detection head is incomplete, which ultimately affects the performance of the algorithm.
[0084] YOLOv8 uses the traditional FPN-PAN network structure to fuse feature maps at different levels to improve detection accuracy. The traditional FPN-PAN structure contains multiple branches for multi-scale feature fusion, but they can only completely fuse the information of adjacent layers, and for the information of non-adjacent layers, they can only obtain it indirectly and recursively. This information fusion method will lead to huge information loss.
[0085] In order to avoid the loss caused by the traditional FPN-PAN network structure, we built a "Gather-and-Distribute" information fusion mechanism, using a unified module to collect and distribute information at all levels. In the C2f multi-scale feature fusion network, we used the FAM feature alignment module, the IFM information fusion module, and the Inject information injection module.
[0086] The C2f multi-scale feature fusion network can indeed retain semantic information, solve the problem of information loss to a certain extent, and improve the performance of the algorithm. The C2f multi-scale feature fusion network has two branches, namely the low-level convergence branch and the high-level convergence branch. These two branches fuse the feature maps from the high-level and low-level layers respectively, and then inject them into the feature maps of different layers through the Inject module. The LowFAM module uses the feature map size of B4 as the baseline size, B2 and B3 use the AvgPool layer to downsample the feature map to the B4 size, and the feature map of B5 is expanded to the B4 size using bilinear interpolation and spliced together in the channel. The design of the LowIFM module includes convolution, structural reparameterization RepConv Block, and splitting operations. The RepConv Block takes the output Falign after the low FAM module as input and divides the output into two outputs in the channel to facilitate the fusion of information at different levels. The formula is as follows:
[0087] F align =LowFAM([B2, B3, B4, B5])
[0088] F fuse =RepConv(F align )
[0089] P4, P3 = Split (F fuse )
[0090] The HighFAM module uses the feature map size of P5 as the baseline size. P3 and P4 use the AvgPool layer to downsample the feature map to the P5 size and concatenate it into channels. The HighIFM design includes multiple self-attention, MLP, and split operations. The specific formula is as follows:
[0091] F align =HighFAM([P3, P4, P5])
[0092] F fuse = Transformer(F align )
[0093] N4, N5 = Split (Conv 1*1 (F fuse ))
[0094] The network structure of the Inject module. X_Global is the global information generated by the IFM module, and X_Local is the local information at different levels. Through low LAF and high LAF, the receiving range of the Injecet module is further expanded, thereby enhancing the characteristics of the module. By performing convolution, sampling, and interpolation operations on local and global information, different information is spliced in the channel. After calculation by the C2f module, the final output of the information injection module is obtained.
[0095] The C2f multi-scale feature fusion network works because it does not have to obtain information from other layers indirectly or recursively like the FPN-PAN network. It replaces the downward fusion and upward fusion operations in the FPN-PAN network through the LowGD module and the HighGD module, which means that all information in the C2f multi-scale feature fusion network is directly obtained, with less loss and higher efficiency, thereby improving the accuracy of the detector.
[0096] S5. Use the safety helmet standard wearing data set ss to train the improved YOLOv8 network model to obtain the trained model.
[0097] Set the parameters of the YOLOv8 network structure to be improved, select YOLOv8 as the model, select the yolov8.pt file as the weight file, set the learning rate to 0.01, set the epoch to 200 rounds, and set the batch-size to 8. Use the prepared data set for training, and continuously optimize the network structure parameters according to the training situation until the improved model with the best training effect is obtained.
[0098] Finally, the images and videos to be tested are input into the trained model for inference and prediction, and the results of whether the workers are wearing safety helmets properly are obtained and output.
[0099] Example 2
[0100] This solution is compared with the traditional solution. The traditional solution is mainly divided into manual detection, which is not only inefficient and costly, but also lacks good timeliness.
[0101] In order to verify the effectiveness of the model and improved module used in this embodiment, ablation experiments were conducted on the original YOLOv5 network, the original YOLOv8 network, the YOLOv8 network with improved MPCA-DCVNV2, and the YOLOv8 network with improved MPCA-CDCNV2 and GD mechanism, and the effectiveness of the improved module was verified by comparing the average precision value mAP. Among them, mAP (%) 0.5 means that when IoU is set to 0.5, the AP of all images of each category is calculated, and then all categories are averaged, that is, mAP. After the experiment, the results in Table 1 are obtained:
[0102]
[0103] Through experiments, it can be seen that each module improvement in this embodiment improves the accuracy of the model, and each improvement is meaningful.
[0104] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A helmet standard wearing detection method based on improved YOLOv8, characterized in that: The following steps are involved: S1. Sample data collection; S2, use deformable convolutionV2 to replace traditional convolution; S3, DCNV2 improvement based on MPCA; S4, improved multi-scale feature fusion module; S5. Use the safety helmet standard wearing data set to train the improved YOLOv8 network model to obtain the trained model, and then input the images and videos to be detected into the trained model for inference and prediction to obtain the results of whether the workers are wearing safety helmets in a standardized manner.
2. The helmet standard wearing detection method based on improved YOLOv8 according to claim 1 is characterized in that: The step S1 comprises the following steps: (1) Collect data on the wearing of hard hats by construction workers on site by downloading public datasets, using web crawler tools, and extracting key frames from surveillance videos, and create a dataset of hard hat standard wearing for training models; (2) Use the LabelImg annotation tool to classify and annotate the images in the dataset. The annotated categories include two types: wearing a helmet properly and not wearing a helmet properly. When annotating, the helmet mark covers the person's head and the helmet itself. After the annotation is completed, a label file in XML format is formed, which constitutes a dataset in VOC format or XML file. (3) Convert the label file in xml format into the txt file format required to improve the YOLOv8 helmet standard wearing detection model, and divide the data into training set and validation set in a ratio of 9:1 for model training.
3. The helmet standard wearing detection method based on improved YOLOv8 according to claim 1 is characterized in that: The step S2 specifically includes the following steps: S21. Introduce deformable convolution instead of conventional convolution. Deformable convolution automatically adapts and adjusts the size of the convolution kernel according to the shape and proportion of the object to be measured, so that the network model simulates the deformation of the object; Deformable convolution adds an offset to each sampling point based on traditional convolution. Assuming the size of the convolution kernel is 3×3, there are 9 sampling points for this convolution kernel. These 9 sampling points are all assigned an offset, so that the position and size of the convolution kernel are dynamically adjusted according to the target object, fitting the size and shape of the object during feature extraction, and optimizing the model's detection performance for irregular and deformed targets. In deformable convolution, the formula for the output eigenvalue of a certain sampling point p0 is: Where R = {(-1,-1), (-1,0), …, (0,1), (1,1)}, w(pn) is the weight of the sampling point, x is the input feature map, pn represents the position element in R, x(pn+p0+Δpn) represents the sampling position of the feature map to be detected; Δpn is the offset added to the conventional convolution sampling point, Δpn adjusts the sampling position of the position element, thereby enhancing the model's adaptability to the recognition of helmet standard wearing behavior; S22, using a conventional convolution kernel to extract features from the input image, and then passing the obtained output feature map through an additional offset field layer to obtain the offset field of the convolution kernel sampling point, whose number of channels is 2N, including the offsets in the x and y directions on the 2D plane. The size of the obtained offset field is consistent with the input feature map, from which the offset matrix of the convolution kernel sampling point is obtained, and the offset Δpn is obtained. The sampling point offset is updated and optimized using the interpolation algorithm and the back propagation algorithm; The sampling point position pixel x(p0+pn+Δpn) after the offset is introduced is calculated using the bilinear interpolation method, and the formula is: Among them, p = p0 + pn + Δpn represents any position in the region, q represents all spatial positions in the input feature map, that is, the four integer points around p, x(q) represents the value of all points at integer positions in the feature map, G(q,p) is a bilinear interpolation kernel function of a two-dimensional kernel, decomposed into two one-dimensional kernels, the formula is: G(q,p)=g(q x ,p x )·g(q y ,p y ) In the above formula: g(a,b)=max{0,1-|ab|}, which is a one-dimensional kernel; S23, introduces deformable convolution into the network model to make the target information of the object under test complete; DCNv2 adds weight values to each sampling point on the basis of DCNv1 in order to further improve the fitting ability of irregular shaped objects, and the calculation formula of the output eigenvalue y(p0) is: In the above formula, Δm n It is the weight coefficient introduced to suppress irrelevant background information, so that the model can reduce the interference of irrelevant content during feature learning.
4. The helmet standard wearing detection method based on improved YOLOv8 according to claim 1 is characterized in that: The step S3 comprises the following steps: S31. The MPCA mechanism improves on the original CA attention mechanism. The CA mechanism captures spatial feature dependencies through one-dimensional global average pooling GAP in the horizontal and vertical directions, and then generates attention maps in two directions. On the basis of the CA attention mechanism, a GAP channel branch is added to process the input feature F∈R in a different way from CA. C ×H×W , thereby preserving the global feature information F when performing average pooling in the X and Y directions gap , through the connection and convolution operations, the fusion and exchange of feature information in the X and Y directions are stimulated, thus generating F hw , then, by splitting F h Get feature F w and F hw , for F hw Further convolution and sigmoid operations are performed to obtain F hwweight , split it to get the feature weight F in the X direction hweight and the feature weight F in the Y direction wweight , multiply these weights by F h and F w Get F x and; S32 uses the YOLOv8 detection model, whose backbone network integrates the C2f module, which is designed to extract the features of the mirrored cross-stage partial network. The neck network uses the path aggregation network PAN and the feature pyramid network FPN for effective feature fusion. After convolution, the output is forwarded to the detection head to finally solve the classification and regression problems. For the safety helmet standard wearing detection task, the traditional convolution operation in C2f is used to extract image features, and the DCNV2 enhanced by MPCA is fused into C2f. While maintaining the basic structure of the C2f module, all traditional convolutions in the bottleneck are replaced by DCNV2 enhanced by MPCA, which enhances the feature extraction capability of the model. This operation helps to achieve finer-grained feature interaction and fusion. Through multiple convolution and segmentation operations, not only the depth of the feature map is increased, but also the information about the x and y coordinates in the feature map becomes more refined and rich, enhancing the feature extraction and fusion capabilities of YOLOv8.
5. The helmet standard wearing detection method based on improved YOLOv8 according to claim 1 is characterized in that: The step S4 comprises the following steps: S41. Construct a Gather-and-Distribute information fusion mechanism, using a unified module to collect and distribute information at all levels. In the C2f multi-scale feature fusion network, the FAM feature alignment module, the IFM information fusion module, and the Inject information injection module are used. The S42 and C2f multi-scale feature fusion networks have two branches, namely the low-density branch and the high-density branch. These two branches fuse feature maps from high and low layers respectively, and then inject them into feature maps of different layers through the Inject module. The LowFAM module uses the feature map size of B4 as the baseline size. B2 and B3 use the AvgPool layer to downsample the feature map to the B4 size. The feature map of B5 is expanded to the B4 size using bilinear interpolation and spliced together in the channel. The formula is as follows: <h2 style=";text-align:left;direction:ltr">F<h2 style=";text-align:left;direction:ltr"> align <h2 style=";text-align:left;direction:ltr"> LowFAM([B2, B3, B4, B5]) F fuse =RepConv(F align ) P4,P3=Split(F fuse ) In the above formula, the LowIFM module is a convolution, including convolution, structure reparameterization RepConv Block and split operation; RepConv Block takes the output Falign after the low FAM module as input, and splits the output into two outputs in the channel for the fusion of different levels of information; S43 and X_Global are global information generated by the IFM module, and X_Local is local information at different levels. Through low LAF and high LAF, different information is spliced in the channel by convolution, sampling and interpolation operations on local information and global information. After calculation by the C2f module, the final output of the information injection module is obtained; The S44 and C2f multi-scale feature fusion network works because it does not have to obtain information from other layers indirectly or recursively like the FPN-PAN network. It replaces the downward fusion and upward fusion operations in the FPN-PAN network through the LowGD module and the HighGD module.
Citation Information
Cited By
PCB surface defect detection system and method based on improved YOLOv10
CN120125585A
Method and device for detecting position of judge in standard court, method and device for detecting whether judge wears gown or not, and medium
CN120339684A
A specification court judge position detection method and judge wearing a robe detection method, device and medium
CN120339684B
Target cooperative control method and system based on deep learning
CN120370719A
A method for identifying standard behavior of long-distance complex scene port operation
CN122637485A