Working clothes wearing detection method based on improved YOLO
By introducing efficient multi-scale attention and cross-level partial network modules into the YOLOv8n model, the balance problem of the model between accuracy and lightweight is solved, the computing resource requirements are reduced, and the small object detection capability in complex environments is improved. Suitable for embedded devices, improving the intelligence level of security monitoring.
Patent Information
- Application Number
- CN202411229322.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2025-01-17
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing YOLO-based detection model is difficult to balance between accuracy and lightweight. Some models have large parameters and complex structures, making it difficult to deploy in embedded terminal devices. In addition, small target detection accuracy is insufficient in complex environments, false detection and The missed detection rate is high and the computing resource demand is large.
By introducing efficient multi-scale attention modules and one-time aggregation of cross-level partial network modules, the YOLOv8n network model is improved, and the modules in the backbone network and neck network are replaced, and the lightweight FasterC2f module and EMA attention mechanism are adopted. , reduce the amount of model parameters and calculations, and use VoVGSCSP module in the neck network to improve the ability to detect targets in complex environments.
A detection model that significantly reduces the demand for computing resources is realized, maintains high-precision detection capabilities, is suitable for real-time work clothes wear detection tasks in complex environments, improves the intelligence level of security monitoring and management, and is suitable for efficient operation on terminal devices with limited resources. .
Smart Images

Figure CN119323712A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image recognition, and in particular to a work clothes wearing detection method based on improved YOLO. Background Art
[0002] In recent years, image processing technology has developed rapidly, and intelligent technologies based on video surveillance have been widely used. These technologies use computer vision to detect, track and identify targets in the scene, and actively alarm and record when abnormal events occur, effectively assisting staff in monitoring. However, traditional industrial site monitoring systems usually only have basic acquisition and display functions, lack intelligent analysis capabilities, and rely on manual monitoring, which is not only inefficient, but also prone to safety hazards not being discovered in time due to fatigue of monitoring personnel.
[0003] To solve the above problems, Chinese patent specification CN117496129A discloses a factory safety wear target detection method based on improved YOLOv7. The method includes the following steps: data collection through enterprise on-site video collection and network crawling to build a safety wear data set; improvement based on the YOLOv7 model, including introducing deep separable convolution and adding CA attention mechanism, and using SiLU activation function to improve the generalization ability of the model; analyzing and judging the data after model training, and evaluating, adjusting and optimizing the model, retaining the optimal weight model after training; using the optimal detection model for real-time monitoring image detection, and generating early warning information based on the detection results.
[0004] In addition, Chinese patent specification CN116597282A discloses a safety wear detection method based on YOLOv7 and Deepsort. This method combines the YOLOv7 network and the Deepsort tracking algorithm, and enhances the detection of small targets through the LSAM attention mechanism. The specific steps include: first, the worker's wear is detected through the pre-trained YOLOv7 model, and then the Deepsort algorithm is used for continuous character tracking to ensure the continuity and accuracy of the detection.
[0005] Existing YOLO-based detection models have difficulty balancing accuracy and lightness. Some models have large parameters and complex structures, making them difficult to deploy in embedded terminal devices; and models that pursue extreme lightness perform poorly in intensive task detection and occlusion tasks. In complex environments, there are still problems of false detection and missed detection, and the amount of calculation is large, making it difficult to run efficiently on resource-constrained terminal devices. Existing technologies still have room for improvement in improving detection accuracy and real-time performance, especially when dealing with complex backgrounds and small target detection, where performance is still insufficient.
[0006] The Chinese invention patent with publication number CN117496129A has a high number of parameters and computational complexity. Although it introduces depthwise separable convolution and SiLU activation function, it still has the problem of large computing resource requirements. The accuracy of small target detection still has room for improvement. Although a small target detection layer has been added, the robustness of detection under complex backgrounds still needs to be further optimized.
[0007] Although the Chinese invention patent with publication number CN116597282A has improved the YOLOv7 network structure and combined it with Deepsort for tracking, in practical applications, the false detection and missed detection rates still need to be further reduced; the detection accuracy of small targets is still insufficient in some complex environments, and the robustness needs to be enhanced. Summary of the invention
[0008] The purpose of the present invention is to overcome the above-mentioned shortcomings and provide a work clothes wearing detection method based on improved YOLO, which can significantly reduce the demand for computing resources while maintaining high-precision detection capabilities, so as to be suitable for real-time work clothes wearing detection tasks in complex environments, and effectively improve the intelligence level of safety monitoring and management.
[0009] In order to solve the above technical problems, the technical solution adopted by the present invention is: a work clothes wearing detection method based on improved YOLO, which comprises the following steps:
[0010] Step 1: Collect data through historical images of the hydropower plant site and web crawling, and use them as the real sample library. The sample library is randomly divided into training set, validation set and test set according to the ratio of 7:2:1.
[0011] Step 2: Label the safety clothing and helmet objects in the samples obtained in step 1 to construct a hydropower plant field data set;
[0012] Step 3: Introduce an efficient multi-scale attention module and a one-time aggregated cross-level partial network module to improve the backbone network and neck network of the YOLOv8n network model;
[0013] Step 4: Input the data set in step 2 into the network described in step 3 for training, and adjust and optimize the network weights based on forward and backward propagation of the loss function to obtain the optimal detection model.
[0014] Furthermore, the step 1 includes the following process:
[0015] Step 1.1, collect on-site historical images and network images of the hydropower plant, select scene types including complex background, dense targets, and object occlusion, and use the data set expanded by network images as the real image sample library;
[0016] Step 1.2: Preprocess the collected data, including image enhancement, image filtering and size adjustment, to improve the robustness and generalization ability of the model.
[0017] Furthermore, the step 2 includes the following process:
[0018] Step 2.1. Start the LabelImg software, click the "Open Directory" button, and select the folder containing the images to be labeled; select the "Create RectBox" tool to draw the bounding box of the target;
[0019] Step 2.2: Draw the bounding boxes of the safety clothing and helmet on the image, set the two types of labels to "clothing" and "helmet", and then click OK; repeat this step until all the objects are labeled;
[0020] Step 2.3. After the annotation is completed, click the "Save" button to save the annotation information as an XML file; ensure that all annotation files correspond to the corresponding sample images one by one, and use the image and the XML file with annotation information as the data set.
[0021] Furthermore, step 3 includes the following process:
[0022] Step 3.1: In the backbone network, introduce the FasterBlock module to replace the BottleNeck module in the C2f module, build a lightweight FasterC2f module, and reduce the number of model parameters and GFLOPS;
[0023] Step 3.2: For the FasterC2f module in step 3.1, an efficient multi-scale attention mechanism is introduced to enhance the representation of the object of attention through the FasterC2fEMA structure, thereby improving the detection capability of dense targets.
[0024] Step 3.3: In the neck network, replace the C2f module with a one-time aggregated cross-level partial network module, and use residual connections to merge shallow feature map information with deep feature map information to improve the model's ability to detect distant small targets.
[0025] Furthermore, the step 3.1 includes the following process:
[0026] Step 3.1.1, the input feature map is processed by a CBS module; the CBS module includes a convolution layer, a batch normalization layer and a SiLU activation function, and the processed feature map is split into multiple sub-feature maps;
[0027] Step 3.1.2, each split sub-feature map is processed by multiple FasterBlock modules respectively; each FasterBlock module consists of a PConv module and two convolution layers with 1x1 convolution kernels; the PConv module expands the number of channels in the middle layer, and then restores the original number of channels after the batch normalization layer and SiLU activation function;
[0028] Step 3.1.3, all sub-feature maps processed by the FasterBlock module are recombined into a complete feature map through splicing operation;
[0029] Step 3.1.4, the concatenated complete feature map is processed again by a CBS module to generate the final output feature map;
[0030] For an input Input∈R c×h×w The feature map of PConv is shown in Figure 1, where c is the number of input channels, h is the height of the input feature map, and w is the width of the input feature map. Partial convolution PConv uses c n filters, while the standard convolution Conv uses c filters; the memory usage of a Conv convolution in the original BottleNeck module is as follows:
[0031] Conv mem =h×w×2c+k 2 ×c 2 ≈h×w×2c
[0032] Where k is the size of the convolution kernel, assuming a k×k square convolution kernel, and h×w×2c represents the storage requirement of the intermediate results;
[0033] FLOPs are:
[0034] F conv =h×w×k 2 ×c 2
[0035] The memory usage of a PConv is as follows:
[0036]
[0037] Among them, s n is the number of filters used by PConv, c n <c,h×w×2c n Indicates the storage requirements of the intermediate results of PConv;
[0038] FLOPs are:
[0039]
[0040] From the above formula, we can get:
[0041]
[0042]
[0043] PConv only performs convolution operations on some input channels, and the remaining channels remain unchanged, and performs feature extraction through subsequent standard convolution, thereby reducing memory usage and floating-point operations, achieving lightweight models, while retaining the original feature map information and achieving effective feature extraction.
[0044] Furthermore, the step 3.2 includes the following process:
[0045] Step 3.2.1, the input feature map is divided into multiple sub-feature groups according to the channel dimension, and each sub-feature group will be processed separately; next, these sub-feature groups are pooled in different directions to generate feature maps in the vertical and horizontal directions; the vertical pooling uses the pooling kernel of (1, W) to perform global average pooling on each channel to generate a feature map in the vertical direction; the horizontal pooling uses the pooling kernel of (H, 1) to perform global average pooling on each channel to generate a feature map in the horizontal direction;
[0046] The specific calculation formulas for vertical and horizontal pooling are:
[0047]
[0048]
[0049] They represent the output values of channel c at width w and height h, respectively. H and W represent the height and width of the input feature map, respectively. c (j,w) represent the values of the input feature map at channel c, height position j, and width position w, respectively. c (h,i) represents the value of the input feature map at channel c, height position h, and width position i respectively;
[0050] Step 3.2.2, concatenate the feature maps in the vertical and horizontal directions, and perform cross-channel information fusion through convolution with a convolution kernel size of 1*1; the fused feature map is decomposed into two independent tensors according to the channel dimension, representing the feature encoding in the vertical and horizontal directions respectively; then use the sigmoid activation function to calculate the intermediate weights to obtain the weight tensors in the two directions;
[0051] Step 3.2.3, in the parallel branch, a convolution operation with a convolution kernel size of 3*3 is performed to extract multi-scale spatial structure information; then, two-dimensional global average pooling is performed on the processed horizontal and vertical feature maps, and spatial attention maps are generated through the Softmax nonlinear activation function; these spatial attention maps integrate spatial information and position information of different scales;
[0052] Step 3.2.4: Multiply the generated spatial attention map by the input feature map element by element to complete the reweighting of the feature map and generate the output feature map; finally, process the reweighted feature map through the Sigmoid nonlinear activation function to obtain the output of the EMA module;
[0053] Step 3.2.5, add the EMA attention mechanism to the end of the FasterC2f module to construct the FasterC2fEMA module; generate spatial attention weight values through cross-space learning, and integrate multi-scale spatial information and position information; the EMA attention mechanism can capture the pixel-level pairwise relationship of the feature map and highlight the global contextual information of the pixel; replace the C2f module of Backbone in YOLOv8n with the FasterC2fEMA module, reduce the number of parameters of the backbone network, and achieve lightweight model.
[0054] Furthermore, the step 3.3 includes the following process:
[0055] Step 3.3.1, build the GSConv basic module; the GSConv module consists of standard convolution, depthwise separable convolution and feature map shuffling; the module processes the feature map according to the following steps: the input feature map first passes through the standard convolution layer for preliminary feature extraction; further extracts features through depthwise separable convolution, which reduces the computational complexity; the feature map enhances the connectivity and feature expression ability between channels through the shuffling operation, and finally outputs the feature map;
[0056] Step 3.3.2, based on the GSConv basic module, construct the GSBottleneck module; the input feature map is firstly extracted through a GSConv module, and then further extracted through another GSConv module; in order to enhance the representation ability of the features and the stability of the network, the residual connection is introduced to directly connect the input feature map to the output of the second layer of GSConv;
[0057] Step 3.3.3, based on the GSBottleneck module, build the VoVGSCSP module; the VoVGSCSP module consists of two branches; the first branch contains multiple GSBottleneck modules for deep feature extraction; the input feature map is processed in sequence by multiple GSBottleneck modules to extract feature information layer by layer; the second branch is a simple standard convolution layer for aggregating feature map information; the output feature maps of the two branches are merged into one feature map through feature concatenation operation, and the merged feature map is further extracted through a standard convolution layer, and finally the enhanced feature map is output;
[0058] Step 3.3.4, replace the C2f module in the neck module of YOLOV8n with the VoVGSCSP module to fully integrate the feature map information extracted by the backbone network and improve the detection capabilities of small targets in the distance and in complex scenes.
[0059] Furthermore, the step 4 includes the following process:
[0060] Step 4.1: Use the training set in step 2 to train the constructed detection network, and then use the verification set in step 2 to verify the training results, and continuously adjust the parameters of the improved network training through back propagation to select the optimal weight file. When the overall loss value reaches the minimum and converges, the network model reaches the optimal value.
[0061] Step 4.2: Input the test set in step 2 into the trained improved network model, and use four evaluation indicators: precision, recall, average precision, and average precision mean to evaluate and test the model;
[0062] The calculation formulas of the evaluation indicators are as follows:
[0063]
[0064]
[0065] Among them, TP represents the number of samples correctly judged as positive, FP represents the number of samples incorrectly judged as positive, and FN represents the number of samples correctly judged as negative;
[0066]
[0067] Among them, P stands for Precision, R stands for Recall, r stands for different thresholds of Recall, and AP is the area under the Precision-Recall curve of a certain category;
[0068]
[0069] mAP is the mean of AP values under all categories, where n is the total number of categories and AP i Represents the AP value of the i-th category.
[0070] Beneficial effects of the present invention:
[0071] 1. The present invention proposes a lightweight wear detection model, which significantly reduces the demand for computing resources while maintaining high-precision detection capabilities; the present invention has the advantages of high detection accuracy, high computing efficiency, small model size, and easy deployment. It is particularly suitable for real-time work clothes wearing detection tasks in complex environments, and can effectively improve the intelligence level of safety monitoring and management.
[0072] 2. The present invention significantly reduces the number of parameters and calculations by introducing the lightweight FasterC2f module and EMA attention mechanism, and using the VoVGSCSP module in the neck network, thereby improving detection accuracy and real-time performance, and enhancing the recognition of occluded targets and small targets in complex environments. The lightweight model is suitable for efficient operation on terminal devices with limited resources, is easy to deploy, has strong adaptability, and can significantly improve the level of intelligence of security monitoring and management, effectively prevent and reduce the occurrence of safety accidents, and ensure the safety of staff. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] Figure 1 is a flow chart of the method proposed by the present invention;
[0074] Figure 2 It is a network diagram of the improved YOLOv8 of the present invention;
[0075] Figure 3 This is a schematic diagram of the EMA mechanism in the FasterC2fEMA module;
[0076] Figure 4 This is a schematic diagram of the VoVGSCSP module. DETAILED DESCRIPTION
[0077] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments.
[0078] Example 1: Figure 1-4 As shown, a work clothes wearing detection method based on improved YOLO includes the following steps:
[0079] Step 1: Collect data through historical images of the hydropower plant site and web crawling, and use them as the real sample library. The sample library is randomly divided into training set, validation set and test set according to the ratio of 7:2:1.
[0080] Step 2: Label the objects such as safety clothing and helmets in the samples obtained in step 1 to construct a hydropower plant field data set;
[0081] Step 3: Introduce the efficient multi-scale attention (EMA) module and the one-shot aggregated cross-level partial network module (VoVGSCSP) module to improve the backbone network and neck network of the YOLOv8n network model;
[0082] Step 4: Input the data set in step 2 into the network described in step 3 for training, and adjust and optimize the network weights based on forward and backward propagation of the loss function to obtain the optimal detection model.
[0083] Preferably, step 1 is implemented according to the following specific steps:
[0084] Step 1.1, collect on-site historical images and network images of the hydropower plant, select scene types including common complex backgrounds, dense targets, object occlusion, etc., and use the data set expanded by network images as the real image sample library;
[0085] Step 1.2: Preprocess the collected data, including image enhancement, image filtering, and size adjustment, etc., to improve the robustness and generalization ability of the model;
[0086] Preferably, step 2 is implemented according to the following specific steps:
[0087] Step 2.1. Start the LabelImg software, click the "Open Directory" button, and select the folder containing the images to be labeled. Select the "Create RectBox" tool to draw the bounding box of the target;
[0088] Step 2.2, draw the bounding box of the safety clothing and helmet on the image, set the two types of labels to "clothing" and "helmet", and then click OK. Repeat this step until all the objects are labeled;
[0089] Step 2.3. After the annotation is completed, click the "Save" button to save the annotation information as an XML file. Make sure that all annotation files correspond to the corresponding sample images one by one, and use the image and the XML file with annotation information as the data set;
[0090] Preferably, step 3 is implemented according to the following specific steps:
[0091] Step 3.1: In the backbone network, introduce the FasterBlock module to replace the BottleNeck module in the C2f module, and build a lightweight FasterC2f module to effectively reduce the number of model parameters and GFLOPS.
[0092] Step 3.2: For the FasterC2f module in step 3.1, introduce the Efficient Multi-Scale Attention (EMA) attention mechanism and design a FasterC2fEMA structure to enhance the representation of the object of attention and improve the detection capability of dense targets.
[0093] Step 3.3: In the neck network, the C2f module is replaced by a one-time aggregated cross-level partial network module (VoVGSCSP), and the residual connection is used to merge the shallow feature map information with the deep feature map information to improve the model's ability to detect distant small targets.
[0094] Step 3.1 is implemented as follows:
[0095] Step 3.1.1: The input feature map is processed by a CBS module. The CBS module includes a convolutional layer (Conv), a batch normalization layer (BN), and a SiLU activation function. The processed feature map is split into multiple sub-feature maps.
[0096] Step 3.1.2, each split sub-feature map is processed by multiple FasterBlock modules. Each FasterBlock module consists of a PConv module and two convolutional layers (Conv) with 1x1 convolution kernels. The PConv module expands the number of channels in the middle layer, and then restores the original number of channels after the batch normalization layer (BatchNorm) and SiLU activation function;
[0097] Step 3.1.3: All sub-feature maps processed by the FasterBlock module are reassembled into a complete feature map through concatenation operation (Concat);
[0098] Step 3.1.4: The concatenated complete feature map is processed again by a CBS module to generate the final output feature map; the FasterBlock module significantly reduces the number of network parameters by reducing the number of convolution operations, thereby speeding up the inference speed;
[0099] For an input Input∈R c×h×w The feature map of PConv is shown in Figure 1, where c is the number of input channels, h is the height of the input feature map, and w is the width of the input feature map. Partial convolution PConv uses c n filters, while the standard convolution Conv uses c filters; the memory usage of a Conv convolution in the original BottleNeck module is as follows:
[0100] Conv mem =h×w×2c+k 2 ×c2 ≈h×w×2c
[0101] Where k is the size of the convolution kernel, assuming a k×k square convolution kernel, and h×w×2c represents the storage requirement of the intermediate results;
[0102] FLOPs are:
[0103] F conv =h×w×k 2 ×c 2
[0104] The memory usage of a PConv is as follows:
[0105]
[0106] Among them, c n is the number of filters used by PConv, c n <c,h×w×2c n Indicates the storage requirements of the intermediate results of PConv;
[0107] FLOPs are:
[0108]
[0109] From the above formula, we can get:
[0110]
[0111]
[0112] PConv only performs convolution operations on some input channels, and the remaining channels remain unchanged, and performs feature extraction through subsequent standard convolution, thereby reducing memory usage and floating-point operations, achieving lightweight models, while retaining the original feature map information and achieving effective feature extraction.
[0113] Step 3.2 is implemented as follows:
[0114] Step 3.2.1. The input feature map is divided into multiple sub-feature groups according to the channel dimension, and each sub-feature group will be processed separately. Next, these sub-feature groups are pooled in different directions to generate feature maps in the vertical and horizontal directions. Specifically, vertical pooling uses a pooling kernel of (1, W) to perform global average pooling on each channel to generate a feature map in the vertical direction; horizontal pooling uses a pooling kernel of (H, 1) to perform global average pooling on each channel to generate a feature map in the horizontal direction;
[0115] The specific calculation formulas for vertical and horizontal pooling are:
[0116]
[0117]
[0118] They represent the output values of channel c at width w and height h, respectively. H and W represent the height and width of the input feature map, respectively. c (j,w) represent the values of the input feature map at channel c, height position j, and width position w, respectively. c (h,i) the same;
[0119] Step 3.2.2, concatenate the feature maps in the vertical and horizontal directions, and fuse the cross-channel information through convolution with a convolution kernel size of 1*1. The fused feature map is decomposed into two independent tensors according to the channel dimension, representing the feature encoding in the vertical and horizontal directions respectively. Then use the sigmoid activation function to calculate the intermediate weights to obtain the weight tensors in the two directions;
[0120] Step 3.2.3: In the parallel branch, a convolution operation with a kernel size of 3*3 is performed to extract multi-scale spatial structure information. Then, two-dimensional global average pooling is performed on the processed horizontal and vertical feature maps, and spatial attention maps are generated through the Softmax nonlinear activation function. These spatial attention maps integrate spatial information and position information of different scales;
[0121] Step 3.2.4: Multiply the generated spatial attention map by the input feature map element by element to complete the reweighting of the feature map and generate the output feature map. Finally, the reweighted feature map is processed by the Sigmoid nonlinear activation function to obtain the output of the EMA module.
[0122] Step 3.2.5, add the EMA attention mechanism to the end of the FasterC2f module to construct the FasterC2fEMA module. Generate spatial attention weight values through cross-space learning, and integrate multi-scale spatial information and location information. The EMA attention mechanism can capture the pixel-level pairwise relationship of the feature map and highlight the global contextual information of the pixel. Replace the C2f module of Backbone in YOLOv8n with the FasterC2fEMA module, reduce the number of parameters of the backbone network, and achieve lightweight model;
[0123] Step 3.3 is implemented as follows:
[0124] Step 3.3.1, build the GSConv basic module. The GSConv module consists of standard convolution (Conv), depthwise separable convolution (DWConv) and feature map shuffle (Shuffle). The module processes the feature map according to the following steps: the input feature map first passes through the standard convolution layer for preliminary feature extraction; the features are further extracted through the depthwise separable convolution, which reduces the computational complexity; the feature map enhances the connectivity and feature expression ability between channels through the shuffle operation, and finally outputs the feature map. Through the GSConv basic module, features can be extracted efficiently while maintaining effective use of computing resources;
[0125] Step 3.3.2. Based on the GSConv basic module, build the GSBottleneck module. The input feature map first passes through a GSConv module for preliminary feature extraction, and then passes through another GSConv module to further extract features. In order to enhance the representation ability of features and the stability of the network, residual connections are introduced to directly connect the input feature map to the output of the second layer of GSConv. This design retains the original feature map information while enhancing the expression ability of the network. Through residual connections, the GSBottleneck module can effectively improve the deep feature extraction capability of the network and enhance the stability of the model;
[0126] Step 3.3.3. Based on the GSBottleneck module, build the VoVGSCSP module. The VoVGSCSP module consists of two branches. The first branch contains multiple GSBottleneck modules for deep feature extraction. The input feature map is processed in sequence by multiple GSBottleneck modules to extract feature information layer by layer. The second branch is a simple standard convolution layer for aggregating feature map information. The output feature maps of the two branches are merged into one feature map through a feature splicing operation. The merged feature map is further extracted through a standard convolution layer, and the enhanced feature map is finally output;
[0127] Step 3.3.4, replace the C2f module in the neck module of YOLOV8n with the VoVGSCSP module to achieve full integration of feature map information extracted by the backbone network and improve the detection capability of small distant targets and targets in complex scenes;
[0128] Preferably, step 4 is implemented according to the following specific steps:
[0129] Step 4.1: Use the training set in step 2 to train the constructed detection network, and then use the verification set in step 2 to verify the training results, and continuously adjust the parameters of the improved network training through back propagation to select the optimal weight file. When the overall loss value reaches the minimum and converges, the network model reaches the optimal value.
[0130] Step 4.2: Input the test set in step 2 into the trained improved network model, and use four evaluation indicators: precision, recall, average precision (AP), and mean average precision (mAP) to evaluate and test the model;
[0131] The calculation formulas of the evaluation indicators are as follows:
[0132]
[0133]
[0134] Among them, TP represents the number of samples correctly judged as positive, FP represents the number of samples incorrectly judged as positive, and FN represents the number of samples correctly judged as negative;
[0135]
[0136] Among them, P stands for Precision, R stands for Recall, r stands for different thresholds of Recall, and AP is the area under the Precision-Recall curve of a certain category;
[0137]
[0138] mAP is the mean of AP values under all categories, where n is the total number of categories and AP i represents the AP value of the jth category.
[0139] Example 2: This example verifies the application effect of the lightweight convolution block of the improved YOLOv8n model in the present invention in work clothes wearing detection through comparative experiments. The specific implementation steps are as follows:
[0140] Step 1: Use the public safety helmet wearing and human head detection dataset: SHWD, and preprocess the dataset. The dataset samples are divided into: "hat" means wearing a safety helmet, "person" means not wearing a safety helmet, and the dataset is randomly divided into training set, validation set and test set according to 7:2:1;
[0141] Step 2: This example selects three models for comparative testing:
[0142] YOLOv5-Q: An improved YOLOv5 helmet wearing detection algorithm;
[0143] YOLOv8n: uses the standard YOLOv8n network structure and does not contain any lightweight improvement modules;
[0144] The improved YOLOv8n model of the present invention: based on YOLOv8n, the FasterC2f module is used to replace the original C2f module, and an efficient multi-scale attention mechanism (EMA) and a one-time aggregated cross-level partial network module (VoVGSCSP) are introduced;
[0145] The three models are trained on the SHWD dataset;
[0146] Step 3: Evaluate the performance of the three models using the test set. The main indicators include mean average precision (mAP), model parameters, computational complexity (GFLOPS), and memory usage. The test results are shown in Table 1:
[0147] Model Type Parameter quantity (M) mAP(%) Memory usage (MB) YOLOv5-Q 12.69 93.7 26.47 YOLOv8n 3.1 92.3 6.1 Improving YOLOv8n 2.39 92.5 4.8
[0148] As can be seen from Table 1, the improved YOLOv8n model has fewer parameters and has improved mAP compared to the standard YOLOv8n. In addition, the memory usage of the improved model is also better than the other two models, making it suitable for deployment on resource-constrained embedded devices;
[0149] This embodiment improves the YOLOv8n model by introducing a lightweight convolution module and a multi-scale attention mechanism. While maintaining high-precision detection capabilities, it reduces the demand for computing resources, enhances the practicality and deployment flexibility of the model, and is particularly suitable for real-time work clothes wearing detection tasks in complex environments.
[0150] The above embodiments are only preferred technical solutions of the present invention and should not be regarded as limiting the present invention. The protection scope of the present invention shall be the technical solutions recorded in the claims, including equivalent replacement solutions of the technical features in the technical solutions recorded in the claims. That is, equivalent replacement improvements within this scope are also within the protection scope of the present invention.
Claims
1. A work clothes wearing detection method based on improved YOLO, characterized by: It includes the following steps: Step 1: Collect data through historical images of the hydropower plant site and web crawling, and use them as the real sample library. The sample library is randomly divided into training set, validation set and test set according to the ratio of 7:2:
1. Step 2: Label the safety clothing and helmet objects in the samples obtained in step 1 to construct a hydropower plant field data set; Step 3: Introduce an efficient multi-scale attention module and a one-time aggregated cross-level partial network module to improve the backbone network and neck network of the YOLOv8n network model; Step 4: Input the data set in step 2 into the network described in step 3 for training, and adjust and optimize the network weights based on forward and backward propagation of the loss function to obtain the optimal detection model.
2. According to claim 1, a work clothes wearing detection method based on improved YOLO is characterized in that: The step 1 includes the following process: Step 1.1, collect on-site historical images and network images of the hydropower plant, select scene types including complex background, dense targets, and object occlusion, and use the data set expanded by network images as the real image sample library; Step 1.2: Preprocess the collected data, including image enhancement, image filtering and size adjustment, to improve the robustness and generalization ability of the model.
3. The work clothes wearing detection method based on improved YOLO according to claim 1 is characterized in that: The step 2 includes the following process: Step 2.
1. Start the LabelImg software, click the "Open Directory" button, and select the folder containing the images to be labeled; select the "Create RectBox" tool to draw the bounding box of the target; Step 2.2, draw the bounding boxes of the safety clothing and helmet on the image, set the two types of labels to "clothing" and "helmet", and then click OK; repeat this step until all the targets are labeled; Step 2.
3. After the annotation is completed, click the "Save" button to save the annotation information as an XML file; ensure that all annotation files correspond to the corresponding sample images one by one, and use the images and XML files with annotation information as the data set.
4. The work clothes wearing detection method based on improved YOLO according to claim 1 is characterized in that: The step 3 includes the following process: Step 3.1: In the backbone network, introduce the FasterBlock module to replace the BottleNeck module in the C2f module, build a lightweight FasterC2f module, and reduce the number of model parameters and GFLOPS; Step 3.2: For the FasterC2f module in step 3.1, an efficient multi-scale attention mechanism is introduced to enhance the representation of the object of attention through the FasterC2fEMA structure, thereby improving the detection capability of dense targets. Step 3.3: In the neck network, replace the C2f module with a one-time aggregated cross-level partial network module, and use residual connections to merge shallow feature map information with deep feature map information to improve the model's ability to detect distant small targets.
5. The work clothes wearing detection method based on improved YOLO according to claim 4 is characterized in that: The step 3.1 includes the following process: Step 3.1.1, the input feature map is processed by a CBS module; the CBS module includes a convolution layer, a batch normalization layer and a SiLU activation function, and the processed feature map is split into multiple sub-feature maps; Step 3.1.2, each split sub-feature map is processed by multiple FasterBlock modules respectively; each FasterBlock module consists of a PConv module and two convolution layers with 1x1 convolution kernels; the PConv module expands the number of channels in the middle layer, and then restores the original number of channels after the batch normalization layer and SiLU activation function; Step 3.1.3, all sub-feature maps processed by the FasterBlock module are recombined into a complete feature map through splicing operation; Step 3.1.4, the concatenated complete feature map is processed again by a CBS module to generate the final output feature map; For an input Input∈R c×h×w The feature map of PConv is shown in Figure 1, where c is the number of input channels, h is the height of the input feature map, and w is the width of the input feature map. Partial convolution PConv uses c n filters, while the standard convolution Conv uses c filters; the memory usage of a Conv convolution in the original BottleNeck module is as follows: Conv mem =g×w×2c+k 2 ×c 2 ≈h×w×2c Where k is the size of the convolution kernel, assuming a k×k square convolution kernel, and h×w×2c represents the storage requirement of the intermediate results; FLOPs are: F conv =h×w×k 2 ×c 2 The memory usage of a PConv is as follows: Among them, c n is the number of filters used by PConv, c n <c,h×w×2c n Indicates the storage requirements of the intermediate results of PConv; FLOPs are: From the above formula, we can get: PConv only performs convolution operations on some input channels, and the remaining channels remain unchanged, and performs feature extraction through subsequent standard convolution, thereby reducing memory usage and floating-point operations, achieving lightweight models, while retaining the original feature map information and achieving effective feature extraction.
6. The work clothes wearing detection method based on improved YOLO according to claim 4 is characterized in that: The step 3.2 includes the following process: Step 3.2.1, the input feature map is divided into multiple sub-feature groups according to the channel dimension, and each sub-feature group will be processed separately; next, these sub-feature groups are pooled in different directions to generate feature maps in the vertical and horizontal directions; the vertical pooling uses the pooling kernel of (1, W) to perform global average pooling on each channel to generate a feature map in the vertical direction; the horizontal pooling uses the pooling kernel of (H, 1) to perform global average pooling on each channel to generate a feature map in the horizontal direction; The specific calculation formulas for vertical and horizontal pooling are: They represent the output values of channel c at width w and height h, respectively. H and W represent the height and width of the input feature map, respectively. c (j,w) represent the values of the input feature map at channel c, height position j, and width position w, respectively. c (h,i) represents the value of the input feature map at channel c, height position h, and width position i respectively; Step 3.2.2, concatenate the feature maps in the vertical and horizontal directions, and perform cross-channel information fusion through convolution with a convolution kernel size of 1*1; the fused feature map is decomposed into two independent tensors according to the channel dimension, representing the feature encoding in the vertical and horizontal directions respectively; then use the sigmoid activation function to calculate the intermediate weights to obtain the weight tensors in the two directions; Step 3.2.3, in the parallel branch, a convolution operation with a convolution kernel size of 3*3 is performed to extract multi-scale spatial structure information; then, two-dimensional global average pooling is performed on the processed horizontal and vertical feature maps, and spatial attention maps are generated through the Softmax nonlinear activation function; these spatial attention maps integrate spatial information and position information of different scales; Step 3.2.4: Multiply the generated spatial attention map by the input feature map element by element to complete the reweighting of the feature map and generate the output feature map; finally, process the reweighted feature map through the Sigmoid nonlinear activation function to obtain the output of the EMA module; Step 3.2.5, add the EMA attention mechanism to the end of the FasterC2f module to construct the FasterC2fEMA module; generate spatial attention weight values through cross-space learning, and integrate multi-scale spatial information and position information; the EMA attention mechanism can capture the pixel-level pairwise relationship of the feature map and highlight the global contextual information of the pixel; replace the C2f module of Backbone in YOLOv8n with the FasterC2fEMA module, reduce the number of parameters of the backbone network, and achieve lightweight model.
7. The work clothes wearing detection method based on improved YOLO according to claim 4 is characterized in that: The step 3.3 includes the following process: Step 3.3.1, build the GSConv basic module; the GSConv module consists of standard convolution, depthwise separable convolution and feature map shuffling; the module processes the feature map according to the following steps: the input feature map first passes through the standard convolution layer for preliminary feature extraction; further extracts features through depthwise separable convolution, which reduces the computational complexity; the feature map enhances the connectivity and feature expression ability between channels through the shuffling operation, and finally outputs the feature map; Step 3.3.2, based on the GSConv basic module, construct the GSBottleneck module; the input feature map is firstly extracted through a GSConv module, and then further extracted through another GSConv module; in order to enhance the representation ability of the features and the stability of the network, the residual connection is introduced to directly connect the input feature map to the output of the second layer of GSConv; Step 3.3.3, based on the GSBottleneck module, build the VoVGSCSP module; the VoVGSCSP module consists of two branches; the first branch contains multiple GSBottleneck modules for deep feature extraction; the input feature map is processed in sequence by multiple GSBottleneck modules to extract feature information layer by layer; the second branch is a simple standard convolution layer for aggregating feature map information; the output feature maps of the two branches are merged into one feature map through feature concatenation operation, and the merged feature map is further extracted through a standard convolution layer, and finally the enhanced feature map is output; Step 3.3.4, replace the C2f module in the neck module of YOLOV8n with the VoVGSCSP module to fully integrate the feature map information extracted by the backbone network and improve the detection capabilities of small targets in the distance and in complex scenes.
8. The work clothes wearing detection method based on improved YOLO according to claim 1 is characterized in that: The step 4 includes the following process: Step 4.1: Use the training set in step 2 to train the constructed detection network, and then use the verification set in step 2 to verify the training results, and continuously adjust the parameters of the improved network training through back propagation to select the optimal weight file. When the overall loss value reaches the minimum and converges, the network model reaches the optimal value. Step 4.2: Input the test set in step 2 into the trained improved network model, and use four evaluation indicators: precision, recall, average precision, and average precision mean to evaluate and test the model; The calculation formulas of the evaluation indicators are as follows: Among them, TP represents the number of samples correctly judged as positive, FP represents the number of samples incorrectly judged as positive, and FN represents the number of samples correctly judged as negative; Among them, P stands for Precision, R stands for Recall, r stands for different thresholds of Recall, and AP is the area under the Precision-Recall curve of a certain category; mAP is the mean of AP values under all categories, where n is the total number of categories and AP i Represents the AP value of the i-th category.
Citation Information
Patent Citations
Safe wearing detection method based on Yolov7 and Deepsort
CN116597282A
Factory safety wearing target detection method based on YOLOv7 improvement
CN117496129A