A safety helmet detection method, system, device and medium based on improved YOLOX
By improving the YOLOX safety helmet detection model and introducing the DenseBlock module and densely connected feature fusion layer, the problem of insufficient safety helmet detection accuracy in complex substation environments was solved, achieving high-precision and high-speed small target detection.
Patent Information
- Application Number
- CN202210947150.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-09
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2042-08-09
AI Technical Summary
In the complex environment of substations, existing regression-based YOLO target detection algorithms are easily affected by factors such as occlusion and low light, resulting in a decrease in the accuracy of safety helmet detection, especially in small target scenarios where they are prone to missed detection.
An improved YOLOX helmet detection model was constructed, introducing a DenseBlock module to replace the Focus module in the backbone network. A densely connected feature fusion layer and multiple residual units were used, and the feature fusion layer was connected to the output layer to enhance the extraction of small target feature information and the multi-scale detection capability. Data augmentation was also used to increase the amount of training data.
It improves the accuracy and speed of safety helmet detection in substation environments, reduces missed and false detections, enhances detection performance in small target scenarios, and meets the detection needs in complex scenarios.
Smart Images

Figure CN115690643B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of target detection technology, specifically relating to a safety helmet detection method, system, equipment, and medium based on an improved YOLOX. Background Technology
[0002] With the development of artificial intelligence, the use of machine vision technology to automatically detect whether substation workers are wearing safety helmets can effectively improve the level of safety production management and is of great importance to the safe production of substations.
[0003] Currently, there are three main types of testing methods for helmet wearing, both domestically and internationally:
[0004] The first category is traditional object detection methods based on machine learning. These methods typically detect objects by extracting contour or color features. Originating at the 2005 CVPR conference, French researcher Navneet Dala proposed a method combining Histogram of Oriented Gradient (HOG) feature extraction with a Support Vector Machine (SVM) classifier for pedestrian detection. The HOG feature extraction method extracts feature vectors by dividing the image into cells and sequentially calculating the gradient direction distribution. These features include light intensity gradients and edge direction distributions, which is the principle behind HOG's object recognition capabilities. Its block normalization strategy effectively reduces the impact of local shadows and lighting variations compared to earlier edge detection algorithms. After feature extraction, the SVM classifier, responsible for feature classification, finds a hyperplane to classify the extracted feature vectors. The combination of these two methods fulfills the basic requirements of object detection: locating and recognizing the detected object. Based on this technology, relevant scholars have made a series of improvements to the detection method. However, due to the limitations of feature extraction algorithms, these detection schemes do not have rotation invariance and scale invariance, resulting in poor generalization performance of this type of detection method.
[0005] The second category is the location detection method for safety helmets based on Internet of Things (IoT) technology. Zeng Hao from Harbin Engineering University used RFID (Radio Frequency Identification) technology to achieve non-contact safety helmet wearing identification by embedding electronic tags and pressure sensors in the safety helmet. This RFID method, which is not based on computer vision, consists of three parts: a tag, a reader, a data transmission device, and a processing system. The advantage of this method is high identification accuracy, but its shortcomings are also obvious. Specifically, RFID tags are divided into passive and active tags. Passive RFID tags use a frequency-hopping mode and do not require a power supply, but their identification distance is short, making them unsuitable for identification scenarios involving wearing safety helmets. Active RFID identification requires batteries installed in the tags, and these batteries need to be replaced regularly, increasing the manufacturing and usage costs of the safety helmet. In addition to RFID technology, Hao Zhaoming et al. also combined Zigbee and GPRS networks, using smart safety helmets embedded with cc2530 chips for personnel positioning and gas detection in mines, achieving some results, but still suffering from the drawback of high manufacturing costs for the detection system.
[0006] The third category is deep learning-based object detection methods, which can be divided into regression-based and region-based object detection algorithms. Region-based (classification) object detection algorithms further divide the detection problem into two stages: first, selecting candidate regions; then, classifying and repositioning these regions to output the object detection result. Typical examples of this type of algorithm are the R-CNN series based on region extraction, such as R-CNN, SPP-Net, Fast R-CNN, and Faster R-CNN. Regression-based object detection algorithms, also known as one-stage models, simplify the object detection process into a unified end-to-end regression problem. They only require processing the image once to simultaneously obtain the object's location and category information. Unlike the two-stage region-based models, one-stage models achieve feature sharing through a single training iteration, significantly improving both accuracy and speed. Typical examples of this type of algorithm include the YOLO series and SSD. In terms of detection efficiency, although regression-based YOLO series object detection algorithms spend more time extracting features from the entire image, they only need to complete one forward pass, while traditional machine learning-based object detection methods require scanning the image hundreds of times.
[0007] Therefore, regression-based YOLO methods offer faster target detection speeds and are less demanding on the detection environment and shooting angle. Currently, the mainstream target detection technology is primarily based on regression, represented by the YOLO series (YOLO1-5) models.
[0008] However, in using the prior art, the inventors discovered at least the following problems:
[0009] In substation safety helmet detection, the external environment is complex, and most monitoring scenarios involve wide-area surveillance. Factors such as target obstruction and low light levels can easily lead to dense detection of small targets with low scale, low resolution, and blurred pixels, affecting detection accuracy. In the raw video image frames acquired in real time, the safety helmet target usually occupies a very small proportion of the image size. If conventional regression-based YOLO series target detection algorithms are used, it often results in missed targets, affecting the accuracy of safety helmet detection. Summary of the Invention
[0010] The present invention aims to at least partially solve the above-mentioned technical problems. The present invention provides a safety helmet detection method, system, device and medium based on improved YOLOX.
[0011] To achieve the above objectives, the present invention adopts the following technical solution:
[0012] Firstly, an improved YOLOX-based helmet detection method is provided, including:
[0013] An improved YOLOX helmet detection model is constructed. The improved YOLOX helmet detection model includes an input layer, a backbone network, a feature fusion layer, and an output layer connected in sequence. The backbone network includes a DenseBlock module connected in sequence to the input layer and multiple stacked residual units. The outputs of the multiple residual units are all connected to the output layer through the feature fusion layer.
[0014] Obtain the safety helmet dataset and preprocess the safety helmet dataset to obtain the preprocessed dataset;
[0015] The improved YOLOX helmet detection model is trained based on the preprocessed dataset to obtain the trained helmet detection model.
[0016] Obtain substation operation data;
[0017] The substation operation data is input into the trained safety helmet detection model to obtain the safety helmet wearing status detection results of the substation operation data.
[0018] This invention improves the helmet detection performance of the model in substation environments, exhibits strong generalization ability in small target scenarios, reduces false negatives and missed detections, and enhances the accuracy and speed of helmet detection. It also improves detection performance in small target scenarios, essentially meeting the accuracy requirements for helmet detection in complex substation environments. Specifically, in implementation, this invention introduces a DenseBlock module to replace the slicing operation performed by the Focus module in the existing backbone network, which greatly preserves the complete information of small targets. The feature fusion module is improved using a dense connection approach to achieve feature reuse, thereby enhancing the extraction and detection capabilities of multi-scale features. By connecting the outputs of multiple residual units to the output layer through the feature fusion layer, the improved YOLO helmet detection model in this invention can utilize both low-level and high-level features of the network, increasing the output based on the feature map output of the existing YOLO model, providing more small target feature information, thus enhancing the network's small target detection capability and enabling multi-scale fusion detection.
[0019] In one possible design, a safety helmet dataset is obtained, and the safety helmet dataset is preprocessed to obtain a preprocessed dataset, including:
[0020] Obtain the safety helmet dataset and perform image annotation on the samples in the safety helmet dataset to obtain the annotated dataset;
[0021] The labeled dataset is then augmented to obtain a preprocessed dataset.
[0022] In one possible design, the labeled dataset is subjected to data augmentation to obtain a preprocessed dataset, including:
[0023] The number of samples in the labeled dataset is increased to the specified number.
[0024] The image is cropped according to the smallest rectangular area of the target image in the sample to obtain the cropped image;
[0025] The cropped image is scaled to obtain a scaled image;
[0026] A specified number of scaled images are stitched together to form an enhanced image, and multiple enhanced images constitute a preprocessed dataset.
[0027] In one possible design, each residual unit includes a Conv module and a CspLayer module connected in sequence; there are four residual units, which are divided into a first residual unit, a second residual unit, a third residual unit, and a fourth residual unit connected in sequence to the DenseBlock module. The CspLayer modules in the first residual unit, the second residual unit, the third residual unit, and the fourth residual unit are all connected to the output layer through a feature fusion layer.
[0028] In one possible design, the feature fusion layer includes a first upsampling module, a first feature stitching module, a second upsampling module, a second feature stitching module, a third upsampling module, a third feature stitching module, a fourth upsampling module, a fifth upsampling module, a sixth upsampling module, a downsampling module, and a fourth feature stitching module;
[0029] The output of the fourth residual unit is connected to the input of the first feature stitching module via the first upsampling module; the output of the third residual unit is connected to the input of the first feature stitching module; the output of the first feature stitching module is connected to the input of the second feature stitching module via the second upsampling module; the output of the second residual unit is connected to the input of the second feature stitching module; the output of the fourth residual unit is connected to the input of the second feature stitching module via the fourth upsampling module; the output of the second feature stitching module is connected to the input of the third feature stitching module via the third upsampling module; the output of the first residual unit is connected to the input of the third feature stitching module via the fifth upsampling module; the output of the fourth residual unit is connected to the input of the third feature stitching module via the sixth upsampling module; the output of the third feature stitching module is connected to the input of the fourth feature stitching module via the downsampling module; and the output of the second feature stitching module is connected to the input of the fourth feature stitching module.
[0030] The output layer includes a first output module connected to the output end of the fourth residual unit, a second output module connected to the output end of the first feature splicing module, and a third output module connected to the output end of the fourth feature splicing module.
[0031] In one possible design, multiple residual units are connected through an MCA attention module, and the outputs of multiple residual units are all connected to the feature fusion layer through the MCA attention module.
[0032] In one possible design, the improved YOLOX helmet detection model is trained based on the preprocessed dataset, resulting in a trained helmet detection model that includes a model building unit, a dataset acquisition unit, a model training unit, a data acquisition unit, and a prediction unit; wherein...
[0033] The model building unit is used to build an improved YOLOX helmet detection model.
[0034] The dataset acquisition unit is used to acquire the safety helmet dataset and preprocess the safety helmet dataset to obtain the preprocessed dataset.
[0035] The model training unit is communicatively connected to the dataset acquisition unit and the model building unit, respectively, and is used to train the improved YOLOX helmet detection model based on the preprocessed dataset input to obtain the trained helmet detection model, and then input the trained helmet detection model into the prediction unit.
[0036] The data acquisition unit is used to acquire substation operation data;
[0037] The prediction unit is communicatively connected to the data acquisition unit and is used to input the substation operation data into the trained safety helmet detection model to obtain the safety helmet wearing status detection result of the substation operation data.
[0038] Obtain the model parameters of the preset pre-trained model;
[0039] The model parameters of the improved YOLOX helmet detection model are replaced with the model parameters of the preset pre-trained model. Then, the preprocessed dataset is input into the improved YOLOX helmet detection model for training to obtain the trained helmet detection model.
[0040] Secondly, a helmet detection system based on an improved YOLOX is provided, for implementing the helmet detection method based on the improved YOLOX as described in any of the above claims; the helmet detection system based on the improved YOLOX includes...
[0041] Thirdly, an electronic device is provided, comprising:
[0042] Memory, used to store computer program instructions; and,
[0043] A processor for executing the computer program instructions to perform the operation of the improved YOLOX-based helmet detection method as described in any of the preceding claims.
[0044] Fourthly, a computer-readable storage medium is provided for storing computer-readable computer program instructions configured to perform operations as described in any of the preceding claims regarding the improved YOLOX-based helmet detection method. Attached Figure Description
[0045] Figure 1 This is a flowchart of a helmet detection method based on the improved YOLOX in this invention;
[0046] Figure 2 This is a structural block diagram of the improved YOLOX helmet detection model in this invention;
[0047] Figure 3 This is a schematic diagram of the structure in this invention where the DenseBlock module replaces the existing Focus module in the backbone network;
[0048] Figure 4 This is a schematic diagram of the structure of adding an MCA attention module to the backbone network in this invention;
[0049] Figure 5 This is a schematic diagram of the feature fusion module in this invention.
[0050] Figure 6 This is a schematic diagram of the architecture of the safety helmet detection system of the present invention. Detailed Implementation
[0051] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in conjunction with the accompanying drawings and descriptions of the embodiments or the prior art. Obviously, the following description of the structure of the accompanying drawings is only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. It should be noted that the description of these embodiments is for the purpose of helping to understand the present invention, but does not constitute a limitation of the present invention.
[0052] Example 1: The first aspect of this example provides a helmet detection method based on the improved YOLOX, which can be executed by, but is not limited to, a computer device or virtual machine with certain computing resources, such as a personal computer, smartphone, personal digital assistant or wearable device, or by a virtual machine.
[0053] like Figure 1 As shown, a helmet detection method based on an improved YOLOX may include, but is not limited to, the following steps:
[0054] S1. Construct an improved YOLOX helmet detection model; where, for example... Figure 2As shown, the improved YOLOX helmet detection model includes an Input layer 1, a Backbone network 2, a Feature Fusion layer 3, and an Output layer 4 connected in sequence. The Backbone network 2 uses a CSPDarknet network for feature extraction. The first layer of the CSPDarknet network uses a DenseBlock module 201. That is, the Backbone network 2 includes a DenseBlock module 201 connected in sequence to the Input layer 1 and multiple stacked residual units (resblock_body). The outputs of the multiple residual units are all connected to the Output layer 4 through the Feature Fusion layer 3. Specifically, the DenseBlock module 201 replaces the Focus layer. Figure 3 As shown.
[0055] Specifically, the DenseBlock module 201 is used to perform slicing operations on samples in the preprocessed dataset to obtain sliced data;
[0056] The residual unit is used to perform normalization, function activation, and convolution processing on the sliced data sequentially, and then transmit the convolutional data to subsequent network layers. Unlike the cascading operation of convolutional feature maps, the residual unit in this embodiment directly connects any two layers in the input feature map. All feature maps of previous network layers are used as independent inputs, and the feature map of the current layer is also passed as input to subsequent layers. This alleviates the gradient vanishing problem and can replace the slicing operation of the DenseBlock module 201 to perform dimensionality reduction and feature extraction on the input image.
[0057] The feature fusion layer 3 is used to perform feature fusion on the convolutional data output by multiple residual units and then output the result.
[0058] It should be noted that the first layer of the backbone network in the existing YOLOX model is a Focus module, which connects to the input layer. The Focus module is mainly used to achieve downsampling without information loss. In this embodiment, the Focus module is replaced with a DenseBlock module 201. Utilizing its dense connections and unique feature map information transmission method, more information can be transmitted, reducing gradients between networks, thereby effectively reducing the loss of small target information during input downsampling. Furthermore, since the DenseBlock module 201 is the first layer of the backbone network 2, it will only connect to the Conv modules in the subsequent residual units. This allows it to replace the existing Focus module to perform double downsampling to extract feature information at more scales. On the other hand, because this unique connection method does not require learning a large amount of useless feature map information, it can improve the gradient information of the network and avoid gradient explosion, thus potentially reducing overfitting. Therefore, while increasing the number of parameters and computational cost, the feature extraction capability of the backbone network 2 can be improved, enabling the network to strengthen the training of small target feature information.
[0059] In this embodiment, each residual unit includes a Conv module (Conv2D+BatchNorm+SiLU, Conv2D_BN_SiLU) and a CspLayer module connected in sequence. The overall structure diagram of the improved YOLOX helmet detection model is as follows: Figure 2 As shown, the dimensions and other parameters of each network module are detailed in [reference needed]. Figure 2 The residual unit is provided with 4 units, which are divided into a first residual unit 202, a second residual unit 203, a third residual unit 204 and a fourth residual unit 205, which are connected to the DenseBlock module 201 in sequence. The CspLayer module in the first residual unit 202, the second residual unit 203, the third residual unit 204 and the fourth residual unit 205 are all connected to the output layer 4 through the feature fusion layer 3.
[0060] Specifically, such as Figure 2As shown, the CspLayer modules in the four residual units are divided into CspLayer(160, 160, 128), CspLayer(80, 80, 256), CspLayer(40, 40, 512), and CspLayer(20, 20, 1024) modules. The outputs of the CspLayer(160, 160, 128), CspLayer(80, 80, 256), CspLayer(40, 40, 512), and CspLayer(20, 20, 1024) modules are all connected to the MCA attention modules. The corresponding MCA attention modules are the outputs of the corresponding residual units, meaning that the four MCA attention modules are connected to the input of feature fusion layer 3.
[0061] Since the final output incorporates the features from all previous layers, it can preserve as much feature information as possible about small targets during downsampling, minimizing information loss and enabling subsequent convolutional operations to extract more information about small targets. This strengthens the model's training on small targets and improves its performance in detecting them.
[0062] Specifically, the feature fusion layer 3 includes a first upsampling module 301, a first feature splicing module 302, a second upsampling module 303, a second feature splicing module 304, a third upsampling module 305, a third feature splicing module 306, a fourth upsampling module 307, a fifth upsampling module 308, a sixth upsampling module 309, a downsampling module 310, and a fourth feature splicing module 311;
[0063] The output of the fourth residual unit 205 is connected to the input of the first feature stitching module 302 via the first upsampling module 301, and the output of the third residual unit 204 is connected to the input of the first feature stitching module 302; the output of the first feature stitching module 302 is connected to the input of the second feature stitching module 304 via the second upsampling module 303, and the output of the second residual unit 203 is connected to the input of the second feature stitching module 304; the output of the fourth residual unit 205 is connected to the input of the second feature stitching module 304 via the fourth upsampling module 307; the output of the second feature stitching module 304 is connected to the input of the third upsampling module 205 via the fourth upsampling module 307. The sampling module 305 is connected to the input of the third feature stitching module 306, the output of the first residual unit 202 is connected to the input of the third feature stitching module 306, the output of the first feature stitching module 302 is connected to the input of the third feature stitching module 306 through the fifth upsampling module 308, the output of the fourth residual unit 205 is connected to the input of the third feature stitching module 306 through the sixth upsampling module 309, the output of the third feature stitching module 306 is connected to the input of the fourth feature stitching module 311 through the downsampling module 310, and the output of the second feature stitching module 304 is connected to the input of the fourth feature stitching module 311.
[0064] The output layer 4 includes a first output module 401 connected to the output end of the fourth residual unit 205, a second output module 402 connected to the output end of the first feature splicing module 302, and a third output module 403 connected to the output end of the fourth feature splicing module 311.
[0065] In this embodiment, by improving the feature pyramid network based on feature fusion layer 3, multi-scale detection is achieved by fully utilizing the network's low-level features. For research on small target detection, small target datasets contain objects that are either too large or too small, resulting in significant scale variations in the detected images. Convolutional neural networks have weak semantic information and high resolution in their low-level features, while high-level features have strong semantic information and low resolution; however, low-level features are crucial for detecting small targets. This embodiment achieves this by fusing low-level features, ensuring that the improved YOLOX helmet detection model has strong semantic information at all scales, thus establishing a more complete feature pyramid network.
[0066] Specifically, in this embodiment, in the improved YOLOX helmet detection model, the 20×20 feature layer output by the fourth residual unit 205 is denoted as the L feature layer. The L feature layer is directly input to the first output module 401 responsible for large target detection. Simultaneously, the L feature layer is upsampled by 2 times through the first upsampling module 301, and then concatenated with the 40×40 feature layer output by the third residual unit 204. Then, the first feature concatenation module 302 is used for feature extraction, and the resulting 40×40 feature layer is denoted as the M feature layer. The M feature layer is directly input to the second output module 402 responsible for medium target detection. Subsequently, the M feature layer is upsampled by 2 times through the second upsampling module 303, and the L feature layer is upsampled by 4 times through the fourth upsampling module 307, and then concatenated with the 80×80 feature layer output by the second residual unit 203. The 0 feature layer is stitched together. After the three feature layers are stitched together, the second feature stitching module 304 is used for feature extraction, and the resulting feature layer is denoted as the S1 feature layer. At the same time, the S1 feature layer is upsampled by 2 times by the third upsampling module 305, the M feature layer is upsampled by 4 times by the fifth upsampling module 308, and the L feature layer is upsampled by 8 times by the sixth upsampling module 309. Then, it is stitched together with the 160×160 feature layer output by the first residual unit 202. After these four feature layers are stitched together, the third feature stitching module 306 is used for feature extraction, and the resulting feature layer is denoted as the S2 feature layer. The S2 feature layer is downsampled by 2 times by the downsampling module 310 and then stitched together with the S1 feature layer. The resulting feature layer is denoted as the S feature layer. The S feature layer is input to the third output module 403, which is responsible for small target detection. Therefore, this embodiment uses dense connections to ensure that the input of each feature fusion layer contains information from deeper feature layers. This allows for the concatenation and combination of features from deeper feature layers, resulting in a richer description and discrimination of the target features, enabling feature reuse and ultimately achieving better feature representation. Specifically, the M and L feature layers, after upsampling, are concatenated with the 80×80 feature layer output by the second residual unit 203 to obtain the S1 feature layer. The S1, M, and L feature layers, after upsampling, are concatenated with the 160×160 feature layer output by the first residual unit 202 to obtain the S2 feature layer. The process of downsampling the S2 feature layer and concatenating it with the S1 feature layer is also a process of repeated feature extraction, which can enrich the semantic information of the convolutional layer and improve the performance of small target detection.
[0067] In this embodiment, by adding a 160×160 feature map output to the existing three feature map output modules of the YOLOX model, the 8x downsampling of this feature map output is changed to 4x downsampling. This effectively enhances the small target feature extraction capability and multi-scale detection performance of the feature extraction network, and also provides more small target features for subsequent feature fusion. Specifically, the structure diagram of the feature fusion module is as follows:Figure 5 As shown in the figure. This embodiment constructs a novel feature fusion network based on the idea of dense connections. The deep feature layers are upsampled and connected to all shallow feature layers to form a feature fusion network similar to a dense block. This allows the shallow feature layers to have rich semantic information of the safety helmet features of the convolutional layers, so that the third output module 403, which is responsible for small target detection, can combine the features of different layers to obtain better target detection and classification results.
[0068] In this embodiment, multiple residual units are connected through an MCA (Multi-Spectral Channel Attention) module 206, and the outputs of multiple residual units are all connected to the feature fusion layer 3 through the MCA attention module 206.
[0069] It should be noted that in this embodiment, by introducing the MCA attention module 206, resources can be rationally allocated and features can be effectively selected to better learn small object features. Specifically, resources here refer to the size of the model, the hardware used for training the model, the training time required, etc. Small object detection allocates more resources to the generation of candidate boxes. The essence of the attention mechanism is to quickly find the region of interest and ignore unimportant information. In this embodiment, although the MCA attention module 206 and other attention modules share the same starting point, the MCA attention module 206 not only retains the global average pooling but also uses frequency components other than the global average pooling. This can solve the problem of information loss caused by focusing only on a single frequency, making the network model focus more on important features, filtering out redundant features, and allocating more resources to the region of interest for more accurate detection. Specifically, a schematic diagram of adding the MCA attention module 206 to the backbone is shown below. Figure 4 As shown.
[0070] S2. Obtain the safety helmet dataset and preprocess the safety helmet dataset to obtain the preprocessed dataset;
[0071] In this embodiment, a safety helmet dataset is obtained, and the safety helmet dataset is preprocessed to obtain a preprocessed dataset, including:
[0072] S201. Obtain the safety helmet dataset and perform image annotation on the samples in the safety helmet dataset to obtain the annotated dataset. In this embodiment, the safety helmet dataset is obtained through web crawling and / or autonomous collection. Specifically, during the collection of the safety helmet dataset, video images from surveillance cameras located in areas such as substation gates, distribution rooms, substation control rooms, and substation power equipment can be captured to obtain images of people in the substation scene. Multiple images of people constitute the safety helmet dataset. The safety helmet data in this dataset includes images from different indoor and outdoor scenes in the substation, under different lighting conditions, and from different camera angles. In this embodiment, the LabelImg tool is used to annotate the samples in the safety helmet dataset to obtain the labels of the corresponding detection objects. Tools such as Labelme, YOLO Mark, Vatic, or Sloth can also be used for annotation. Among them, LabelImg is an open-source image labeling tool with stable basic software functions, simple operation, and a concise interface.
[0073] S202. Perform data augmentation on the labeled dataset to obtain a preprocessed dataset. It should be noted that data augmentation is a crucial component of training deep learning models. In deep learning, a sufficient number of samples is generally required; the more samples, the better the trained model and the stronger its generalization ability. However, in practice, there are often insufficient samples or samples of poor quality. Therefore, data augmentation is necessary to improve sample quality. Data augmentation refers to artificially increasing the number of samples in the training set using methods such as translation, scaling, color transformation, and noise addition, thereby obtaining sufficient training data and improving model training performance. Since image annotation is costly, in this embodiment, performing data augmentation on the labeled dataset can reduce the number of samples to be annotated, thus lowering the application cost of small object detection in this embodiment.
[0074] Specifically, the labeled dataset undergoes data augmentation to obtain a preprocessed dataset, including:
[0075] a. Increase the number of stitched samples in the labeled dataset to a specified number, such as increasing the number of stitched samples from 4 to 9, where the specified number is 9. It can also be increased to 16, etc., in order to increase the amount of training data for small targets.
[0076] b. Crop the image according to the smallest rectangular area of the target image in the sample to obtain the cropped image. Compared with random cropping, cropping the image according to the smallest rectangular area can minimize the boundary area, increase the probability that the target image will not be cropped, and help ensure the integrity of the target image.
[0077] c. Scale the cropped image to obtain a scaled image;
[0078] d. Stitch the specified number of scaled images together to obtain an enhanced image. Multiple enhanced images constitute the preprocessed dataset.
[0079] In this embodiment, the data augmentation method is an improved mosaic data augmentation method, which can ensure that the target is not truncated as much as possible, thereby increasing the amount of training data for small targets. Specifically, compared with the data augmentation method before the improvement, the improved mosaic data augmentation method in this embodiment reduces a lot of useless boundary area, speeds up model convergence, and improves training efficiency. On the other hand, it forms a large number of small targets, enriching the safety helmet sample dataset, and thus significantly improving the model's performance in detecting small-scale safety helmets.
[0080] S3. Based on the preprocessed dataset, the improved YOLOX helmet detection model is trained to obtain the trained helmet detection model;
[0081] In this embodiment, the improved YOLOX helmet detection model is trained based on the preprocessed dataset, resulting in a trained helmet detection model, including:
[0082] Obtain the model parameters of the preset pre-trained model;
[0083] The model parameters of the improved YOLOX helmet detection model are replaced with the model parameters of the preset pre-trained model. Then, the preprocessed dataset is input into the improved YOLOX helmet detection model for training to obtain the trained helmet detection model.
[0084] It should be noted that, taking PyTorch as an example of a pre-trained model, it provides a `state_dict` dictionary object to store and load model parameters, saving the model parameters in dictionary form. In this embodiment, when obtaining the model parameters of the preset pre-trained model, firstly, the current model parameters corresponding to the improved YOLOX helmet detection model are read: `model_dict = model.state_dict()`; then, the pre-trained model is read: `pretrained_dict = torch.load(model_path, map_location = device)`; `pretrained_dict = {k:v for k, v in pretrained_dict.items() if np.shape(model_dict[k]) == np.shape(v)}`; subsequently, the current model parameters are updated using the model parameters of the pre-trained model: `model_dict.update(pretrained_dict)`; finally, the model parameters are loaded: `model.load_state_dict(model_dict)`, so that the model parameters of the improved YOLOX helmet detection model are replaced with the model parameters of the preset pre-trained model. In this embodiment, when loading model parameters, the key-value type of the saved model parameters must be completely consistent with the model. At this time, pre-trained weights of the neural network can be used. Training is divided into two phases: a freeze phase and a unfreeze phase. In the freeze phase, the model's backbone is frozen, the feature extraction network remains unchanged, and the memory usage is small; only fine-tuning of the network is performed. In the unfreeze phase, the model's backbone is not frozen, the feature extraction network changes, the memory usage is larger, and all network parameters change. During network training, the parameters are continuously adjusted until the network's loss becomes increasingly smaller. During training, the initially initialized model parameters will continuously change. Once the expected effect is achieved, the trained model parameters are saved and used directly as the initialization parameters for this task. Then, during training, these parameters are continuously modified based on the results to ultimately achieve the best effect.
[0085] Specifically, some existing deep learning frameworks (such as PyTorch and TensorFlow) provide classic, pre-trained network models (such as ResNet and AlexNet). These pre-trained models have good generalization performance and perform well for most common tasks such as detection, segmentation, and recognition. In this embodiment, the improved YOLOX helmet detection model uses a pre-trained model, adjusting its parameters before retraining. This avoids the cumbersome process of training the model from scratch, thus saving a significant amount of time.
[0086] S4. Obtain substation operation data;
[0087] S5. Input the substation operation data into the trained safety helmet detection model to obtain the safety helmet wearing status detection result of the substation operation data.
[0088] This embodiment improves the model's helmet detection performance in substation environments, exhibits strong generalization ability in small target scenarios, reduces false negatives and missed detections, and enhances helmet detection accuracy and speed. It also improves detection performance in small target scenarios, essentially meeting the accuracy requirements for helmet detection in complex substation environments. Specifically, in this embodiment, the introduction of the DenseBlock module 201 replaces the slicing operation performed by the Focus module in the existing backbone network 2, significantly preserving the complete information of small targets. The feature fusion module is improved using a dense connection approach, enabling feature reuse to enhance multi-scale feature extraction and detection capabilities. By connecting the outputs of multiple residual units to the output layer 4 via the feature fusion layer 3, the improved YOLOX helmet detection model in this embodiment can utilize both low-level and high-level features of the network, increasing output beyond the existing YOLO model's feature map output to provide more small target feature information, thereby enhancing the network's small target detection capability and enabling multi-scale fusion detection.
[0089] Example 2: This example provides a helmet detection system based on an improved YOLOX, used to implement the helmet detection method based on an improved YOLOX in Example 1; such as Figure 6 As shown, the improved YOLOX-based helmet detection system includes a model building unit, a dataset acquisition unit, a model training unit, a data acquisition unit, and a prediction unit; wherein,
[0090] The model building unit is used to build an improved YOLOX helmet detection model.
[0091] The dataset acquisition unit is used to acquire the safety helmet dataset and preprocess the safety helmet dataset to obtain the preprocessed dataset.
[0092] The model training unit is communicatively connected to the dataset acquisition unit and the model building unit, respectively, and is used to train the improved YOLOX helmet detection model based on the preprocessed dataset input to obtain the trained helmet detection model, and then input the trained helmet detection model into the prediction unit.
[0093] The data acquisition unit is used to acquire substation operation data;
[0094] The prediction unit is communicatively connected to the data acquisition unit and is used to input the substation operation data into the trained safety helmet detection model to obtain the safety helmet wearing status detection result of the substation operation data.
[0095] Example 3: Based on Example 1 or 2, this example discloses an electronic device, which may be a smartphone, tablet computer, laptop computer, or desktop computer, etc. The electronic device may be referred to as a terminal, portable terminal, desktop terminal, etc., and includes:
[0096] Memory, used to store computer program instructions; and,
[0097] A processor is configured to execute the computer program instructions to perform the operation of the helmet detection method based on the improved YOLOX as described in any of Embodiment 1.
[0098] Example 4: Based on any one of Examples 1 to 3, this example discloses a computer-readable storage medium for storing computer-readable computer program instructions, which are configured to execute the operation of the improved YOLOX-based helmet detection method as described in Example 1.
[0099] It should be noted that if the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0100] Obviously, those skilled in the art will understand that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, thereby storing them in a storage device for execution by a computing device, or fabricating them separately as individual integrated circuit modules, or fabricating multiple modules or steps as a single integrated circuit module. Thus, the present invention is not limited to any particular hardware and software combination.
[0101] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. These modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
[0102] Finally, it should be noted that the above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A safety helmet detection method based on improved YOLOX, characterized in that: The application relates to a safety helmet detection model based on an improved YOLOX. The application relates to a safety helmet detection model based on an improved YOLOX. The application relates to a safety helmet detection model based on an improved YOLOX. The application relates to a safety helmet detection model based on an improved YOLOX. Each residual unit comprises a Conv module and a CspLayer module which are sequentially connected. The feature fusion layer comprises a first up-sampling module, a first feature splicing module, a second up-sampling module, a second feature splicing module, a third up-sampling module, a third feature splicing module, a fourth up-sampling module, a fifth up-sampling module, a sixth up-sampling module, a down-sampling module and a fourth feature splicing module. The output end of the fourth residual unit is connected with the input end of the first feature splicing module through the first up-sampling module, and the output end of the third residual unit is connected with the input end of the first feature splicing module. The output end of the second feature splicing module is connected with the input end of the fourth feature splicing module through the down-sampling module. The output layer comprises a first output module connected with the output end of the fourth residual unit, a second output module connected with the output end of the first feature splicing module and a third output module connected with the output end of the fourth feature splicing module. The plurality of residual units are connected through an MCA attention module, and the output ends of the plurality of residual units are connected with the feature fusion layer through the MCA attention module.
2. The safety helmet detection method based on improved YOLOX according to claim 1, characterized in that: An safety helmet dataset is acquired, and the safety helmet dataset is preprocessed to obtain a preprocessed dataset, including: An safety helmet dataset is acquired, and the samples in the safety helmet dataset are image-labeled to obtain a labeled dataset; The labeled dataset is data-augmented to obtain a preprocessed dataset.
3. The safety helmet detection method based on improved YOLOX according to claim 2, characterized in that: The labeled dataset is data-augmented to obtain a preprocessed dataset, including: The number of spliced samples in the labeled dataset is expanded to a specified number; The target image in the sample is cropped according to the minimum rectangular area to obtain a cropped image; The cropped image is scaled to obtain a scaled image; The specified number of scaled images are spliced into one image to obtain an augmented image, and a plurality of augmented images constitute the preprocessed dataset.
4. The safety helmet detection method based on improved YOLOX according to claim 1, characterized in that: The improved YOLOX safety helmet detection model is trained based on the preprocessed dataset to obtain a trained safety helmet detection model, including: The model parameters of a preset pre-training model are acquired; The model parameters of the improved YOLOX safety helmet detection model are replaced with the model parameters of the preset pre-training model, and then the preprocessed dataset is input into the improved YOLOX safety helmet detection model for training to obtain a trained safety helmet detection model.
5. A safety helmet detection system based on improved YOLOX, characterized in that: The improved YOLOX-based safety helmet detection method of any one of claims 1-4 is implemented; the improved YOLOX-based safety helmet detection system includes a model construction unit, a dataset acquisition unit, a model training unit, a data acquisition unit, and a prediction unit; wherein, The model construction unit is configured to construct an improved YOLOX safety helmet detection model. The dataset acquisition unit is configured to acquire a safety helmet dataset and preprocess the safety helmet dataset to obtain a preprocessed dataset. The model training unit is in communication connection with the dataset acquisition unit and the model construction unit, respectively, and is configured to train the improved YOLOX safety helmet detection model based on the preprocessed dataset to obtain a trained safety helmet detection model, and then input the trained safety helmet detection model into the prediction unit. The data acquisition unit is configured to acquire substation operation data. The prediction unit is in communication connection with the data acquisition unit and is configured to input the substation operation data into the trained safety helmet detection model to obtain a safety helmet wearing state detection result of the substation operation data.
6. An electronic device, comprising: including: a memory for storing computer program instructions; and a processor for executing the computer program instructions to complete the operations of the improved YOLOX-based safety helmet detection method of any one of claims 1-4. The computer program instructions are configured to execute the operations of the improved YOLOX-based safety helmet detection method of any one of claims 1-4 when running.
7. A computer readable storage medium for storing computer readable computer program instructions, characterized in that: