Safety helmet detection method and device, storage medium and electronic equipment
By introducing the parallel connection of the channel and spatial attention modules into the helmet detection model, the problems of low accuracy and low efficiency of helmet detection in the existing technology are solved, and more efficient helmet wearing detection is achieved.
Patent Information
- Application Number
- CN202410636370.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-06
AI Technical Summary
Existing safety helmet detection methods have low accuracy, low efficiency and poor flexibility in complex operating environments, making it difficult to effectively detect safety helmet wearing conditions.
A helmet detection model including a channel attention module and a spatial attention module is used to extract image features and improve detection accuracy and efficiency through multiple rounds of training and parallel connection of attention mechanism modules.
It improves the accuracy and efficiency of helmet detection, saves labor costs, and has strong flexibility and scalability to adapt to different application scenarios.
Smart Images

Figure CN118608937A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image recognition, and in particular to a helmet detection method, device, storage medium and electronic equipment. Background Art
[0002] In various industrial working environments, especially in construction sites, factories and high-risk areas, hard hats are essential protective equipment for workers. It is particularly important whether the wearing of hard hats meets quality standards. With the development of technology, especially the rapid progress of artificial intelligence, new possibilities have been provided for the detection of hard hat wearing. However, due to the many interference factors in complex working environments, such as light changes, occlusion, and crowded people, traditional hard hat detection methods have low accuracy, low efficiency, and poor flexibility. Summary of the invention
[0003] The main purpose of the present invention is to provide a helmet detection method, device, storage medium and electronic device, aiming to solve the problems of low accuracy, low efficiency and poor flexibility of the helmet detection method in the prior art.
[0004] To achieve the above objectives, the present disclosure provides a helmet detection method, the method comprising:
[0005] Acquire image data of the detection object;
[0006] Inputting the image data into a helmet detection model to obtain a helmet detection result output by the helmet detection model, wherein the helmet detection result is used to characterize the helmet wearing condition of the detection object;
[0007] Among them, the helmet detection model includes an attention mechanism module, and the attention mechanism module includes a channel attention module and a spatial attention module, and the channel attention module and the spatial attention module are connected in parallel.
[0008] Optionally, the training process of the helmet detection model includes:
[0009] Collecting helmet image data;
[0010] Preprocessing the helmet image data to obtain a helmet data set, wherein the helmet data set includes helmet images with helmet positions marked;
[0011] The initial detection model is trained according to the helmet data set to obtain the helmet detection model.
[0012] Optionally, the training process of the helmet detection model includes multiple rounds of training, and each round of training process includes:
[0013] Inputting the hard hat data set into the hard hat detection model, determining a predicted hard hat detection result set corresponding to the hard hat data set, wherein the predicted hard hat detection result set includes a sampled feature image containing multiple image features;
[0014] By means of the attention mechanism module, a weight parameter of each image feature in the predicted helmet detection result set is updated;
[0015] The next round of training is performed based on the updated weight parameters.
[0016] Optionally, updating the weight parameters of the image features in the predicted helmet detection result set through the attention mechanism module includes:
[0017] Inputting the sampled feature image into the channel attention module and the spatial attention module simultaneously;
[0018] Performing attention calculation on the sampled feature image through the channel attention module to obtain a channel attention feature image, wherein the channel attention feature image includes an attention weight of each channel;
[0019] Performing attention calculation on the sampled feature image through the spatial attention module to obtain a spatial attention feature image, wherein the spatial attention feature image includes an attention weight of each space;
[0020] Obtain a target attention feature image according to the channel attention feature image and the spatial attention feature image;
[0021] Based on the target attention feature image, the weight parameters are updated.
[0022] Optionally, performing attention calculation on the sampled feature image by the channel attention module to obtain a channel attention feature image includes:
[0023] The attention calculation is performed on the sampled feature image according to the following formula:
[0024]
[0025] Among them, F c represents the channel attention feature image, F represents the sampling feature image, sigmoid represents the sigmoid activation function, MaxPool represents the maximum pooling, and AvgPool represents the average pooling.
[0026] Optionally, performing attention calculation on the sampled feature image by the spatial attention module to obtain a spatial attention feature image includes:
[0027] The attention calculation is performed on the sampled feature image according to the following formula:
[0028]
[0029] Among them, k 7*7 Represents the 7*7 convolution function, F s represents the spatial attention feature image, F represents the sampling feature image, sigmoid represents the sigmoid activation function, MaxPool represents the maximum pooling, and AvgPool represents the average pooling.
[0030] Optionally, obtaining a target attention feature image according to the channel attention feature image and the spatial attention feature image comprises:
[0031] The attention calculation is performed on the channel attention feature image and the spatial attention feature image according to the following formula:
[0032] F m =F c +F s
[0033] Among them, F m represents the target attention feature image, F c represents the channel attention feature image, F s Represents the spatial attention feature image.
[0034] Optionally, the method further comprises:
[0035] Analyze the helmet detection result to obtain the helmet wearing condition, wherein the helmet wearing condition includes the identity information of the detection object and the helmet wearing standard;
[0036] The detection object is reminded according to the wearing condition of the safety helmet.
[0037] Optionally, the helmet detection model is a YOLOv5 target detection model.
[0038] In addition, to achieve the above-mentioned purpose, the present disclosure also provides a safety helmet detection device, the safety helmet detection device comprising:
[0039] An acquisition module, used for acquiring image data of the detection object;
[0040] A detection module, used for inputting the image data into a helmet detection model to obtain a helmet detection result output by the helmet detection model, wherein the helmet detection result is used to characterize the helmet wearing condition of the detected object;
[0041] Among them, the helmet detection model includes an attention mechanism module, and the attention mechanism module includes a channel attention module and a spatial attention module, and the channel attention module and the spatial attention module are connected in parallel.
[0042] In addition, to achieve the above objectives, the present disclosure also provides a computer-readable storage medium, on which a computer program is stored, and a processor executes the computer program to implement the above method.
[0043] In addition, to achieve the above-mentioned purpose, the present disclosure also provides an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-mentioned method.
[0044] In addition, to achieve the above objectives, the present disclosure also provides a computer program product, which implements the above method when executed by a processor.
[0045] Through the above technical solution, the image data of the detection object is input into the trained helmet detection model, and the helmet detection result output by the helmet detection model can be obtained, thereby improving the efficiency of helmet detection and saving labor costs. By adding an attention mechanism module including a channel attention module and a spatial attention module to the helmet detection model, it can be ensured that the helmet detection model pays attention to the correct channel during feature extraction and extracts features at the correct position, making the helmet detection model more accurate and efficient in the feature extraction process. Furthermore, the channel attention module and the spatial attention module are connected in parallel, so that the helmet detection model can simultaneously consider the information of the two dimensions of channel and space, thereby more comprehensively extracting the features of the input image. In addition, the parallel connection method also has strong flexibility and scalability. The channel attention module and the spatial attention module can be adjusted and optimized according to the needs of specific tasks to adapt to different application scenarios. At the same time, other types of attention mechanism modules can also be easily added to the model to further improve the performance of the helmet detection model. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0047] Figure 1 A schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present disclosure;
[0048] Figure 2 This is a schematic diagram of the process of the first embodiment of the safety helmet detection method disclosed in the present invention;
[0049] Figure 3 This is a YOLOv5 network structure diagram of the first embodiment of the helmet detection method disclosed in the present invention;
[0050] Figure 4 A parallel structure diagram of a channel attention module and a spatial attention module of the first embodiment of the helmet detection method disclosed in the present invention;
[0051] Figure 5 This is a structural diagram of a channel attention module of the first embodiment of the helmet detection method disclosed in the present invention;
[0052] Figure 6 This is a structural diagram of a spatial attention module of the first embodiment of the helmet detection method disclosed in the present invention;
[0053] Figure 7 This is a structural block diagram of the first embodiment of the safety helmet detection device disclosed in the present invention.
[0054] The realization of the objectives, functional features and advantages of the present disclosure will be further described in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0055] The following will be combined with the drawings in the embodiments of the present disclosure to clearly and completely describe the technical solutions in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0056] Reference Figure 1 , Figure 1 The figure is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present disclosure.
[0057] Typically, the device comprises: at least one processor 301, a memory 302, and a helmet detection program stored in the memory 302 and executable on the processor 301, wherein the helmet detection program is configured to implement the steps of the helmet detection method as described above.
[0058] The processor 301 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 301 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 301 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 301 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. The processor 301 may also include an AI (Artificial Intelligence) processor, which is used to process operations related to the helmet detection method, so that the helmet detection method model can be trained and learned autonomously to improve efficiency and accuracy.
[0059] The memory 302 may include one or more storage media, which may be non-transitory. The memory 302 may also include a high-speed random access memory and a non-volatile memory, such as one or more disk storage devices and flash memory storage devices. In some embodiments, the non-transitory storage medium in the memory 302 is used to store at least one instruction, which is used to be executed by the processor 301 to implement the helmet detection method provided in the method embodiment of the present disclosure.
[0060] In some embodiments, the terminal may further optionally include: a communication interface 303 and at least one peripheral device. The processor 301, the memory 302 and the communication interface 303 may be connected via a bus or a signal line. Each peripheral device may be connected to the communication interface 303 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 304, a display screen 305 and a power supply 306.
[0061] The communication interface 303 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 301 and the memory 302. In some embodiments, the processor 301, the memory 302, and the communication interface 303 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 301, the memory 302, and the communication interface 303 may be implemented on a separate chip or circuit board, which is not limited in this embodiment.
[0062] The radio frequency circuit 304 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 304 communicates with the communication network and other communication devices through electromagnetic signals. The radio frequency circuit 304 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the radio frequency circuit 304 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency circuit 304 can communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: a metropolitan area network, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 304 may also include circuits related to NFC (Near Field Communication), which is not limited in the present disclosure.
[0063] The display screen 305 is used to display the UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 305 is a touch display screen, the display screen 305 also has the ability to collect touch signals on the surface or above the surface of the display screen 305. The touch signal can be input to the processor 301 as a control signal for processing. At this time, the display screen 305 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 305 can be one, the front panel of the electronic device; in other embodiments, the display screen 305 can be at least two, respectively arranged on different surfaces of the electronic device or in a folding design; in some embodiments, the display screen 305 can be a flexible display screen, arranged on a curved surface or a folding surface of the electronic device. Even, the display screen 305 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 305 can be made of materials such as LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode, organic light-emitting diode).
[0064] The power supply 306 is used to power various components in the electronic device. The power supply 306 can be AC power, DC power, a disposable battery, or a rechargeable battery. When the power supply 306 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also be used to support fast charging technology. Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation of the device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0065] In addition, the embodiment of the present disclosure further proposes a storage medium, on which a helmet detection program is stored, and when the helmet detection program is executed by the processor, the steps of the helmet detection method described above are implemented. Therefore, it will not be repeated here. In addition, the description of the beneficial effects of adopting the same method will not be repeated. For technical details not disclosed in the storage medium embodiment involved in the present disclosure, please refer to the description of the method embodiment of the present disclosure. As an example, the program instructions can be deployed to be executed on one device, or on multiple devices located at one location, or on multiple devices distributed at multiple locations and interconnected by a communication network.
[0066] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the above-mentioned program can be stored in a storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the above-mentioned storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0067] First, it should be understood that the helmet detection model may include the following steps:
[0068] First, collect a large amount of image data containing helmet wearing conditions, including front, side, back and other different angles, as well as scenes with different lighting conditions, occlusion and personnel density. Then divide these data into training set, validation set and test set. Then select a deep learning model suitable for target detection, such as Faster R-CNN, YOLO (You Only Look Once) or SSD (Single Shot MultiBox Detector). Then use the training set to train the model to learn how to extract the features of the helmet from the image and classify them. Among them, transfer learning technology can be used in the training process, and the pre-trained model parameters can be used for initialization to accelerate the training process and improve the generalization ability of the model. The accuracy and real-time performance of the model can be further improved by adjusting the model's hyperparameters, optimization algorithms and loss functions. In addition, data enhancement techniques such as rotation, scaling, cropping, etc. can also be used to increase the robustness of the model.
[0069] After the model training is completed, the trained model is deployed to the actual application scenario to obtain images of the work site and detect the wearing of safety helmets.
[0070] Reference Figure 2 , Figure 2 This is a flow chart of the first embodiment of the helmet detection method disclosed in the present invention, which includes the following steps:
[0071] Step S11: Acquire image data of the detection object.
[0072] Step S12: input the image data into the helmet detection model to obtain the helmet detection result output by the helmet detection model, and the helmet detection result is used to characterize the helmet wearing condition of the detection object. The helmet detection model includes an attention mechanism module, and the attention mechanism module includes a channel attention module and a spatial attention module, and the channel attention module and the spatial attention module are connected in parallel.
[0073] It should be understood that the detection object can be a specific person or a certain space, that is, the helmet detection is performed on the people in the space, and the detection object can be set or adjusted manually or automatically, which is not specifically limited in the embodiments of the present disclosure. The image data of the detection object can be obtained in real time through, for example, a surveillance camera or a newly added dedicated camera, or it can be obtained from a local historical file, which is not specifically limited in the embodiments of the present disclosure.
[0074] Through the above technical solution, the image data of the detection object is input into the trained helmet detection model, and the helmet detection result output by the helmet detection model can be obtained, thereby improving the efficiency of helmet detection and saving labor costs. By adding an attention mechanism module including a channel attention module and a spatial attention module to the helmet detection model, it can be ensured that the helmet detection model pays attention to the correct channel during feature extraction and extracts features at the correct position, making the helmet detection model more accurate and efficient in the feature extraction process. Furthermore, the channel attention module and the spatial attention module are connected in parallel, so that the helmet detection model can simultaneously consider the information of the two dimensions of channel and space, so as to more comprehensively understand the features of the input image. In addition, the parallel connection method also has strong flexibility and scalability. The channel attention module and the spatial attention module can be adjusted and optimized according to the needs of specific tasks to adapt to different application scenarios. At the same time, other types of attention mechanism modules can also be easily added to the model to further improve the performance of the helmet detection model.
[0075] In a possible manner, the helmet detection model is a YOLOv5 object detection model.
[0076] It should be understood that YOLOv5 mainly consists of three parts:
[0077] (1) Backbone network: The backbone network is the core part of YOLOv5 and is mainly responsible for extracting the features of the input image. This part of the network is usually composed of a series of convolutional layers, batch normalization layers, and activation functions. Through continuous convolution and pooling operations, it gradually extracts high-level features of the image.
[0078] (2) Neck network: The main function of the Neck network is to process and process the feature image from the feature extraction network to improve the performance and accuracy of target detection. Specifically, the Neck network can further process and fuse the features extracted by the detector, and fuse the features at different levels through a series of convolutional layers, pooling layers, upsampling layers and other structures. At the same time, it can also reduce and increase the dimension of the features to better adapt to the detection tasks of targets of different sizes and proportions.
[0079] (3) Head network: The Head network is the output part of YOLOv5, which is mainly responsible for predicting the features extracted by the Backbone network, generating bounding boxes and predicting categories. This part of the network usually includes a series of fully connected layers or convolutional layers to convert feature images into final detection results. In YOLOv5, the Head network adopts the head structure of YOLOv3, which has excellent detection performance and speed.
[0080] For example, the output of the YOLOv5 target detection model can be a five-parameter coordinate (x, y, w, h, c), (x, y) represents the coordinate of the upper left corner of the prediction box, (w, h) represents the width and height of the prediction box, and c represents the confidence of the prediction result. During the training process, the error correction of the target output by the YOLOv5 target detection model can be performed by using clustering and non-maximum suppression methods, and the result with a larger confidence is selected as the output result. The network weights can be adjusted through back propagation and loss function, and the loss can be calculated using the intersection scale method to calculate the loss function of the YOLOv5 network GIOU loss , and its calculation formula is:
[0081]
[0082] Among them, IOU (Intersection over Union) represents the ratio of the intersection and union of the predicted bounding box and the real bounding box, C represents the minimum enclosing rectangle between the real bounding box given by the label and the predicted bounding box given by the model, Q represents the difference, that is, the difference between C and the union B, and B represents the union of the real box and the predicted box.
[0083] For example, it should also be understood that the helmet image in a complex working environment contains both a rich foreground and a complex background. The shallow feature image contains a large amount of low-level information such as edges and textures, among which more non-target information is not conducive to the feature extraction of the target. Therefore, in order to reduce the interference of non-target information and pay more attention to the target detail information, the present disclosure adds an attention mechanism on the basis of the backbone network to reduce false detection and speed up the reasoning speed of the model in response to the shortcomings of the original YOLOv5. The essence of the attention mechanism is to achieve efficient allocation of information processing resources. It can dynamically adjust the attention to the input information according to the task requirements, focus on important information with high weights, and ignore irrelevant information with low weights, thereby achieving efficient utilization of information processing resources.
[0084] Figure 3 This is a YOLOv5 network structure diagram of the first embodiment of the helmet detection method disclosed in the present invention, as shown in Figure 3As shown in the figure, the image is input into the BackBone network, and the output of the BackBone network is passed to the PANet network (Path Aggregation Network). The PANet network performs feature fusion and extraction on the input, and the feature image output by the PANet network enters the Output layer to generate the final helmet detection result. Among them, the BottleNeckCSP module, that is, the bottleneck layer with a CSP (Cross Stage Partial) structure, is used for feature extraction and fusion. The output feature image is input into the SPP (Spatial Pyramid Pooling) module to extract multi-scale features, and then the output feature image is input into the attention mechanism module. The attention mechanism module can integrate the feature extraction results of all previous layers and assign different weights to different features according to the requirements of the task.
[0085] In a possible way, the training process of the helmet detection model includes:
[0086] Collecting helmet image data;
[0087] Preprocessing the helmet image data to obtain a helmet data set, where the helmet data set includes helmet images with helmet positions marked;
[0088] The initial detection model is trained according to the helmet data set to obtain the helmet detection model.
[0089] It should be understood that the collection of helmet image data collects a large number of images related to helmets from data sources such as public data sets, web crawlers, and self-owned equipment. The helmet images may include separate helmet images, images of people wearing helmets, and images of people not wearing helmets. Preprocessing the helmet image data may include operations such as adjusting the image size, normalization, and data enhancement (such as rotation, cropping, flipping, etc.) to increase the generalization ability of the model, and then the helmets in the image may be annotated manually or using annotation tools. The annotation method may be annotated by bounding boxes, key points, or pixel-level segmentation. The disclosed embodiments do not specifically limit the selection of the above-mentioned technical methods.
[0090] After determining the helmet dataset, you can select a suitable image detection network model based on the helmet detection requirements, and then determine hyperparameters such as learning rate, batch size, and optimization algorithm, and randomly initialize the model weights or use pre-trained weights. Then use the labeled dataset for multiple rounds of iterative training, calculate the loss through forward propagation, and update the weights through back propagation. The model validation method can include dividing a part of the dataset as a validation set to ensure that it does not overlap with the training set. Then select appropriate evaluation indicators, such as accuracy, recall, average precision mean, etc., and use the validation set to evaluate the trained model and calculate the evaluation indicators.
[0091] In a possible way, the training process of the helmet detection model includes multiple rounds of training, and each round of training includes:
[0092] Inputting the hard hat data set into the hard hat detection model, determining a predicted hard hat detection result set corresponding to the hard hat data set, wherein the predicted hard hat detection result set includes a sampled feature image containing multiple image features;
[0093] Through the attention mechanism module, the weight parameters of each image feature in the predicted helmet detection result set are updated;
[0094] The next round of training is performed based on the updated weight parameters.
[0095] It should be understood that in the forward propagation process of the model, the original image is extracted and fused through network layers such as BackBone and PANet to generate a series of sampled feature images. These sampled feature images contain rich semantic information and provide a basis for subsequent image detection tasks. The attention mechanism module receives these sampled feature images as input, and emphasizes important features and suppresses unimportant features by adjusting the weights of the sampled feature images globally or locally, and then performs the next round of model training based on the adjusted weights.
[0096] For example, the attention mechanism module can calculate the weight of each position in the feature image. These weights reflect the importance of the position to the final detection result. In the process of calculating the weights, the attention mechanism may use some additional information, such as the spatial relationship between the feature images, contextual information, etc. By comprehensively considering this information, the attention mechanism module can generate a more accurate weight distribution. After the weight calculation is completed, the attention mechanism will apply these weights to the feature image and perform weighted processing on the feature image. In this way, important features will be amplified, while unimportant features will be weakened. The feature image adjusted by the attention mechanism module has a more accurate and efficient information representation. Finally, the feature image adjusted by the attention mechanism module will be further passed to the subsequent network layer to generate the final detection result. Since the attention mechanism has updated the weights of the feature image, the detection performance of the model will be significantly improved.
[0097] Among the possible ways, the weight parameters of the image features in the predicted helmet detection result set are updated through the attention mechanism module, including:
[0098] The sampled feature image is input into the channel attention module and the spatial attention module simultaneously;
[0099] The channel attention module performs attention calculation on the sampled feature image to obtain a channel attention feature image, which includes the attention weight of each channel;
[0100] The spatial attention module performs attention calculation on the sampled feature image to obtain a spatial attention feature image, which includes the attention weight of each space;
[0101] Obtain a target attention feature image according to the channel attention feature image and the spatial attention feature image;
[0102] Based on the target attention feature image, update the weight parameters.
[0103] Figure 4 FIG. 1 is a parallel structure diagram of the channel attention module and the spatial attention module of the first embodiment of the helmet detection method disclosed in the present invention. Figure 4 As shown in the figure, the attention mechanism module is composed of two modules, spatial attention and channel attention, connected in parallel. The sampled feature image can be input into the spatial attention module and the channel attention module at the same time, and the channel attention feature image output by the spatial attention module and the spatial attention feature image output by the channel attention module are obtained at the same time. Then the channel attention feature image and the spatial attention feature image are added element by element, and the output is an attention feature image including the channel attention feature and the spatial attention feature.
[0104] Among them, the spatial attention module focuses on locating important areas in the image. By calculating the spatial importance of each pixel, it captures the spatial structure in the image, allowing the model to pay more attention to specific areas related to the target task. The channel attention module focuses on selecting the most discriminative feature channels in the image. By calculating the input sampled feature image in the channel dimension, it distinguishes the features of different channels and assigns corresponding weights to each channel, thereby improving the expressiveness of the features.
[0105] Spatial attention and channel attention are used in parallel, and the two modules can complement each other and improve the performance of the model together. The spatial attention module ensures that the model focuses on key locations in the image, and the channel attention module ensures that the model can make full use of important features at these locations. This combination enables the model to more accurately select and utilize important information during feature extraction. In addition, the parallel design allows the two modules to learn and optimize independently to adapt to different inputs and tasks. This makes the model more flexible and adaptable, and can achieve better performance in various scenarios.
[0106] In a possible manner, the channel attention module is used to perform attention calculation on the sampled feature image to obtain a channel attention feature image, including:
[0107] According to the following formula, the attention calculation is performed on the sampled feature image:
[0108]
[0109] Among them, F c represents the channel attention feature image, F represents the sampling feature image, sigmoid represents the sigmoid activation function, MaxPool represents the maximum pooling, and AvgPool represents the average pooling.
[0110] It should be understood that the semantic information expressed by each channel in the feature image is different, and the channel attention module can capture the correlation between channels and pay more attention to the contribution of the effective area in the feature image. Considering that some key areas in the deep feature image are likely to be lost, the present disclosure increases the attention to the channel. The channel attention module strengthens or suppresses different channels according to the importance of different feature channels and gives corresponding weights. In this way, attention can be focused on the important semantic information in the current task.
[0111] Figure 5 This is a structural diagram of the channel attention module of the first embodiment of the helmet detection method disclosed in the present invention. Figure 5As shown in the figure, the sampled feature image first uses the maximum pooling and average pooling methods at the same time, that is, it passes through a maximum pooling layer (MaxPool) and an average pooling layer (AvgPool) at the same time to aggregate the channel dimension information and obtain two feature images for each channel. Then these two feature images are sent to a shared MLP (multi-layer perceptron) with a hidden layer to obtain a more representative feature vector. Then the output feature vector is summed element-wise, and finally the final feature image is obtained through the sigmoid activation function. In order to better utilize the detailed information of the previous feature image, the input sampled feature image is multiplied by the normalized feature image according to the corresponding elements to obtain the channel attention feature image.
[0112] In a possible manner, the spatial attention module is used to perform attention calculation on the sampled feature image to obtain a spatial attention feature image, including:
[0113] According to the following formula, the attention calculation is performed on the sampled feature image:
[0114]
[0115] Among them, k 7*7 Represents the 7*7 convolution function, F s represents the spatial attention feature image, F represents the sampling feature image, sigmoid represents the sigmoid activation function, MaxPool represents the maximum pooling, and AvgPool represents the average pooling.
[0116] Figure 6 FIG. 1 is a structural diagram of a spatial attention module of the first embodiment of the helmet detection method disclosed in the present invention. Figure 6 As shown in Figure 1, the sampled feature image first passes through a maximum pooling layer (MaxPool) and an average pooling layer (AvgPool) in sequence, and is compressed in the channel direction to integrate the information in the spatial dimension. At this time, a two-dimensional feature image F is generated. (Avg , Max) , F (Avg , Max) ∈R 1×H×W , where R 1×H×W Represents a two-dimensional feature image with 1 channel, height H, and width W.
[0117] Then, we use convolution with a kernel size of 7*7 to extract features, output feature images of the same spatial size, and perform sigmoid operation to achieve (0, 1) normalization. In order to better utilize the detailed information of the previous feature image, we can multiply the input feature image and the normalized feature image by the corresponding elements. At this time, we get the spatial attention feature image F S , FS ∈R 1×H×W .
[0118] In a possible manner, obtaining a target attention feature image according to the channel attention feature image and the spatial attention feature image includes:
[0119] According to the following formula, attention is calculated for the channel attention feature image and the spatial attention feature image:
[0120] F m =F c +F s
[0121] Among them, F m represents the target attention feature image, F c represents the channel attention feature image, F s Represents the spatial attention feature image.
[0122] It is worth noting that the attention calculation is performed on the channel attention feature image and the spatial attention feature image, and its mathematical expression can be to add and sum the corresponding elements in the channel attention feature image and the spatial attention feature image of the same shape and size. Specifically, it can be completed using the torch.cat() function in PyTorch, and the present disclosure embodiment does not specifically limit this.
[0123] Among the possible methods, they also include:
[0124] Analyze the helmet test results to obtain the helmet wearing situation, which includes the identity information of the test object and the helmet wearing standard;
[0125] Remind the test object according to the wearing condition of the helmet.
[0126] It should be understood that if the detection object is a specific one or more persons, the helmet wearing situation may also include the preset helmet wearing standard of the person and the identity information and communication method of the corresponding operator or manager. Accordingly, when the helmet wearing situation does not meet the standard, a reminder can be made through a mobile electronic device, and the helmet wearing situation and the reminder are sent to the manager end for management. If the detection object is a certain space area, the helmet wearing situation may also include the preset number of operators in the space area, the helmet wearing standard, and the identity information and communication method of the operator or manager corresponding to the space area. Accordingly, when the helmet wearing situation does not meet the standard, a reminder can be made through a mobile electronic device or a speaker or warning light set in the space area, and the helmet wearing situation and the reminder are sent to the manager end for management. The embodiments of the present disclosure do not specifically limit this.
[0127] Reference Figure 7 , Figure 7 This is a structural block diagram of the first embodiment of the safety helmet detection device disclosed in the present invention. Based on the same inventive concept as the previous embodiment, the device includes:
[0128] An acquisition module 10 is used to acquire image data of a detection object;
[0129] A detection module 20, for inputting the image data into a helmet detection model to obtain a helmet detection result output by the helmet detection model, wherein the helmet detection result is used to characterize the helmet wearing condition of the detection object;
[0130] Among them, the helmet detection model includes an attention mechanism module, and the attention mechanism module includes a channel attention module and a spatial attention module, and the channel attention module and the spatial attention module are connected in parallel.
[0131] Optionally, the training process of the helmet detection model includes:
[0132] Collecting helmet image data;
[0133] Preprocessing the helmet image data to obtain a helmet data set, wherein the helmet data set includes helmet images with helmet positions marked;
[0134] The initial detection model is trained according to the helmet data set to obtain the helmet detection model.
[0135] Optionally, the training process of the helmet detection model includes multiple rounds of training, and each round of training process includes:
[0136] Inputting the hard hat data set into the hard hat detection model, determining a predicted hard hat detection result set corresponding to the hard hat data set, wherein the predicted hard hat detection result set includes a sampled feature image containing multiple image features;
[0137] By means of the attention mechanism module, a weight parameter of each image feature in the predicted helmet detection result set is updated;
[0138] The next round of training is performed based on the updated weight parameters.
[0139] Optionally, updating the weight parameters of the image features in the predicted helmet detection result set through the attention mechanism module includes:
[0140] Inputting the sampled feature image into the channel attention module and the spatial attention module simultaneously;
[0141] Performing attention calculation on the sampled feature image through the channel attention module to obtain a channel attention feature image, wherein the channel attention feature image includes an attention weight of each channel;
[0142] Performing attention calculation on the sampled feature image through the spatial attention module to obtain a spatial attention feature image, wherein the spatial attention feature image includes an attention weight of each space;
[0143] Obtain a target attention feature image according to the channel attention feature image and the spatial attention feature image;
[0144] Based on the target attention feature image, the weight parameters are updated.
[0145] Optionally, performing attention calculation on the sampled feature image by the channel attention module to obtain a channel attention feature image includes:
[0146] The attention calculation is performed on the sampled feature image according to the following formula:
[0147]
[0148] Among them, F c represents the channel attention feature image, F represents the sampling feature image, sigmoid represents the sigmoid activation function, MaxPool represents the maximum pooling, and AvgPool represents the average pooling.
[0149] Optionally, performing attention calculation on the sampled feature image by the spatial attention module to obtain a spatial attention feature image includes:
[0150] The attention calculation is performed on the sampled feature image according to the following formula:
[0151]
[0152] Among them, k 7*7 Represents the 7*7 convolution function, F s represents the spatial attention feature image, F represents the sampling feature image, sigmoid represents the sigmoid activation function, MaxPool represents the maximum pooling, and AvgPool represents the average pooling.
[0153] Optionally, obtaining a target attention feature image according to the channel attention feature image and the spatial attention feature image comprises:
[0154] The attention calculation is performed on the channel attention feature image and the spatial attention feature image according to the following formula:
[0155] F m =F c +F s
[0156] Among them, F m represents the target attention feature image, F c represents the channel attention feature image, F s Represents the spatial attention feature image.
[0157] Optionally, the device further comprises:
[0158] An analysis module, used for analyzing the helmet detection result to obtain the helmet wearing condition, wherein the helmet wearing condition includes the identity information of the detection object and the helmet wearing standard;
[0159] The reminder module is used to remind the detection object according to the wearing condition of the safety helmet.
[0160] Optionally, the helmet detection model is a YOLOv5 target detection model.
[0161] It should be noted that, since the steps executed by the device of this embodiment are the same as the steps of the aforementioned method embodiment, its specific implementation method and the technical effects that can be achieved can refer to the aforementioned embodiment and will not be repeated here.
[0162] In addition, in one embodiment, an embodiment of the present disclosure further provides an electronic device, which includes a processor, a memory, and a computer program stored in the memory, and the computer program implements the steps of the method in the aforementioned embodiment when executed by the processor.
[0163] In addition, in one embodiment, an embodiment of the present disclosure further provides a computer storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method in the aforementioned embodiment are implemented.
[0164] In some embodiments, the computer readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or various devices including one or any combination of the above memories. The computer may be various computing devices including intelligent terminals and servers.
[0165] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0166] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0167] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.
[0168] It should be noted that, in this article, the terms "include", "may include" or any other variations thereof are intended to cover non-exclusive inclusions, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0169] The serial numbers of the above-mentioned embodiments of the present disclosure are only for description and do not represent the advantages or disadvantages of the embodiments.
[0170] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present disclosure, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory / random access memory, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a multimedia terminal device (which can be a mobile phone, a computer, a television receiver, or a network device, etc.) to execute the methods described in each embodiment of the present disclosure.
[0171] The above descriptions are only optional embodiments of the present disclosure, and are not intended to limit the patent scope of the present disclosure. All equivalent structural transformations made using the contents of the present disclosure and the drawings under the inventive concept of the present disclosure, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present disclosure.
Claims
1. A method for detecting a safety helmet, characterized in that: The method comprises: Acquire image data of the detection object; Inputting the image data into a helmet detection model to obtain a helmet detection result output by the helmet detection model, wherein the helmet detection result is used to characterize the helmet wearing condition of the detection object; Among them, the helmet detection model includes an attention mechanism module, and the attention mechanism module includes a channel attention module and a spatial attention module, and the channel attention module and the spatial attention module are connected in parallel.
2. The method according to claim 1, characterized in that: The training process of the helmet detection model includes: Collecting helmet image data; Preprocessing the helmet image data to obtain a helmet data set, wherein the helmet data set includes helmet images with helmet positions marked; The initial detection model is trained according to the helmet data set to obtain the helmet detection model.
3. The method according to claim 2, characterized in that: The training process of the helmet detection model includes multiple rounds of training, and each round of training includes: Inputting the hard hat data set into the hard hat detection model, determining a predicted hard hat detection result set corresponding to the hard hat data set, wherein the predicted hard hat detection result set includes a sampled feature image containing multiple image features; By means of the attention mechanism module, a weight parameter of each image feature in the predicted helmet detection result set is updated; The next round of training is performed based on the updated weight parameters.
4. The method according to claim 3, characterized in that: The updating of the weight parameters of the image features in the predicted helmet detection result set by the attention mechanism module includes: Inputting the sampled feature image into the channel attention module and the spatial attention module simultaneously; Performing attention calculation on the sampled feature image through the channel attention module to obtain a channel attention feature image, wherein the channel attention feature image includes an attention weight of each channel; Performing attention calculation on the sampled feature image through the spatial attention module to obtain a spatial attention feature image, wherein the spatial attention feature image includes an attention weight of each space; Obtain a target attention feature image according to the channel attention feature image and the spatial attention feature image; Based on the target attention feature image, the weight parameters are updated.
5. The method according to claim 4, characterized in that: The step of performing attention calculation on the sampled feature image by the channel attention module to obtain a channel attention feature image includes: The attention calculation is performed on the sampled feature image according to the following formula: Among them, F c represents the channel attention feature image, F represents the sampling feature image, sigmoid represents the sigmoid activation function, MaxPool represents the maximum pooling, and AvgPool represents the average pooling.
6. The method according to claim 4, characterized in that: The step of performing attention calculation on the sampled feature image by the spatial attention module to obtain a spatial attention feature image includes: The attention calculation is performed on the sampled feature image according to the following formula: Among them, k 7*7 Represents the 7*7 convolution function, F s represents the spatial attention feature image, F represents the sampling feature image, sigmoid represents the sigmoid activation function, MaxPool represents the maximum pooling, and AvgPool represents the average pooling.
7. The method according to claim 4, characterized in that: The obtaining of a target attention feature image according to the channel attention feature image and the spatial attention feature image comprises: The attention calculation is performed on the channel attention feature image and the spatial attention feature image according to the following formula: F m =F c +F s Among them, F m represents the target attention feature image, F C represents the channel attention feature image, F s Represents the spatial attention feature image.
8. The method according to claim 1, characterized in that: The method further comprises: Analyze the helmet detection result to obtain the helmet wearing condition, wherein the helmet wearing condition includes the identity information of the detection object and the helmet wearing standard; The detection object is reminded according to the wearing condition of the safety helmet.
9. The method according to any one of claims 1 to 8, characterized in that: The helmet detection model is a YOLOv5 target detection model.
10. A safety helmet detection device, characterized in that: include: An acquisition module, used for acquiring image data of the detection object; A detection module, used for inputting the image data into a helmet detection model to obtain a helmet detection result output by the helmet detection model, wherein the helmet detection result is used to characterize the helmet wearing condition of the detected object; Among them, the helmet detection model includes an attention mechanism module, and the attention mechanism module includes a channel attention module and a spatial attention module, and the channel attention module and the spatial attention module are connected in parallel.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the processor executes the computer program to implement the method according to any one of claims 1 to 9.
12. An electronic device, characterized in that: The electronic device comprises a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method according to any one of claims 1 to 9.
