Improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism
By introducing the channel selection multi-scale fusion module and CBAM attention mechanism into the YOLOv5 network, the problem of low multi-scale target detection accuracy of YOLOv5 in complex construction site environments is solved, especially in the detection of small targets, achieving higher detection accuracy and robustness.
Patent Information
- Application Number
- CN202510769022.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-10
- Publication Date
- 2025-09-12
AI Technical Summary
The existing YOLOv5 network has low detection accuracy for multi-scale targets in complex construction site environments, especially for small targets such as protective gloves.
By replacing the spatial pyramid pooling fusion module of the YOLOv5 backbone network with the Channel Selective Multi-Scale Fusion Module (CSMF), and combining it with a feature adaptive weighted fusion strategy based on a multi-channel selection mechanism, the fusion weights of feature channels under different receptive fields are dynamically adjusted. Furthermore, the CBAM attention mechanism is introduced to enhance the MBconv module, improving the discriminative ability of feature maps.
The model's adaptability to multi-scale targets has been significantly improved, especially the detection accuracy of small targets in complex construction site environments, which reduces information redundancy and enhances robustness to target occlusion and background interference.
Smart Images

Figure CN120635573A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer vision and deep learning technology, and specifically relates to an improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism. Background Art
[0002] With the accelerating pace of industrialization and urbanization, safety requirements in hazardous work environments such as construction sites and mines are becoming increasingly stringent. National and industry safety standards explicitly require workers to wear appropriate protective equipment, such as helmets, reflective vests, and protective gloves, to mitigate potential safety hazards during production. However, traditional safety oversight relies primarily on manual inspections, which suffer from low efficiency, high costs, and susceptibility to human error. This makes it difficult to meet the real-time monitoring needs of large, complex environments.
[0003] In recent years, automated detection technologies based on computer vision have garnered widespread attention. The YOLOv5 algorithm, a representative example of industrial-grade real-time object detection, has found application in various industrial and security scenarios thanks to its high detection speed and excellent accuracy. However, YOLOv5 still suffers from low accuracy in detecting small objects (such as protective gloves) in complex environments, unstructured scenes, and with numerous obstructions. Furthermore, the feature extraction module of the traditional YOLOv5 model is limited in its ability to process multi-scale information, hindering its overall performance in detecting small objects across multiple categories. Therefore, targeted improvements to YOLOv5 are urgently needed to meet the demands of practical applications. Summary of the Invention
[0004] The purpose of this paper is to provide an improved YOLOv5 protective equipment detection method that combines channel selection and attention mechanism, aiming to solve the problem that the existing YOLOv5 network has low accuracy in detecting multi-scale targets in complex construction site environments.
[0005] The technical solution adopted by the present invention is an improved YOLOv5 protective equipment detection method that combines channel selection and attention mechanism, which specifically includes the following steps: The original spatial pyramid pooling fusion module SPPF in the YOLOv5 backbone network is replaced with the channel selection multi-scale fusion module CSMF. The channel selection multi-scale fusion module CSMF is based on the feature adaptive weighted fusion strategy of the multi-channel selection mechanism. According to the contextual information and semantic distribution of the input image features, it dynamically adjusts the fusion weights of feature channels under different receptive fields, thereby achieving more discriminative multi-scale feature integration. The specific operation steps are as follows: Step 1: Image preprocessing and enhancement The images collected at the construction site are normalized, resized, and color enhanced to ensure consistent image quality under different lighting and viewing angles. The processed images are used as a dataset and further divided into a training set and a test set. Step 2: Build a target detection model Based on the YOLOv5 backbone network structure, a feature multi-scale fusion module CSMF with a multi-channel selection mechanism is designed. The feature multi-scale fusion module CSMF performs weighted fusion on multi-scale feature maps to effectively integrate semantic information at different levels. The mobile inverted bottleneck convolution module MBconv is inserted into the YOLOv5 neck network part, and the attention module SE is replaced by the CBAM module; compared with the SE attention mechanism which only has channel attention, the CBAM module also includes the channel attention module CAM and the spatial attention module SAM; Step 3: Train the constructed target detection model; Step 4: Design the total loss function of the target detection model, which consists of classification loss, confidence loss, and positioning loss to form the overall optimization goal.
[0006] The present invention is also characterized in that: The feature multi-scale fusion module CSMF in step 2 is as follows: In step 2.1, we first perform preliminary feature extraction on the image in the dataset in step 1 to obtain a feature map F as input for subsequent processing. Subsequently, we design three parallel MBConv feature extraction pathways, using 3×3, 5×5, and 7×7 convolution kernels to independently process the input feature map F to capture semantic information from different receptive fields. The 3×3 convolution branch is used to extract fine-grained local texture and edge features, the 5×5 convolution focuses on mid-scale structures such as region boundaries and object contours, and the 7×7 convolution is used to obtain global semantics and background information of the image. The feature maps extracted by each of the three branches are denoted as: (1) Step 2.2, obtain the feature maps under three receptive fields 、 and After that, first perform a global average pooling GAP operation on each feature map. The pooling method is as follows: (2) in, Indicates the i In the road feature map c The channels are located in space ( x , y ), is the number of channels;H and W are the height and width of the feature map, respectively. g i c Indicates the i Road feature map c The value of each channel after GAP compression; through the GAP operation, three groups of channel-level global description vectors are obtained respectively g 1. g 2. g 3. A feature map has C channels, so each GAP operation outputs a one-dimensional vector containing C numbers, so It is a C-dimensional vector, each set of vectors represents the global response degree of the scale feature map on each channel; Subsequently, the three sets of global vectors are concatenated as input and fed into a weight-sharing multi-layer perceptron (MLP) structure. The MLP structure consists of two layers of fully connected neural networks with a nonlinear activation function ReLU added in the middle. The MLP outputs a channel weight coefficient vector of length 3. s : (3) Among them, || represents the vector concatenation operation, and Softmax is used to normalize the original weighted vector to between 0 and 1. is the weighting factor, and satisfies , each weighting factor Indicates the model's current input i Importance estimation of road-scale features; In step 2.3, after obtaining the channel weights of each scale branch, the three feature maps are weighted fused proportionally to generate the final fused feature map: (4) Step 2.4, the fused feature map F fused The input is sent to the AIFI module, which uses its embedded two-dimensional sine-cosine position embedding and multi-head self-attention mechanism to further model the long-distance dependency and spatial semantic structure between features. The AIFI module outputs the enhanced feature map for subsequent detection tasks. The process can be briefly described as follows: (5) in, AIFI Represents the operation of spatial context modeling and global semantic enhancement on the fused feature map.
[0007] Step 2: Insert the mobile inverted bottleneck convolution module MBconv into the YOLOv5 neck network as follows: (1) In the neck network structure of YOLOv5, the improved MBconv module is introduced before the original Concat feature splicing module. The MBconv module adopts the structural design of extended convolution, depthwise separable convolution, and compressed convolution. The convolution process is expressed as formula (6) (6) in, F is the input feature map, F MB is the output feature map, SE() is the attention mechanism, σ is the activation function, Exp 1×1 Denotes the 1×1 convolution of the expanded dimension, Dep k×k Represents depth convolution, Conv1×1 is used to compress the dimension and return to the original number of channels; (2) In the above Mbconv module, the original SE attention mechanism is replaced by the more expressive CBAM attention mechanism; the CBAM attention mechanism combines the channel attention and spatial attention mechanisms to perform saliency modeling on the feature map in the channel dimension and spatial dimension respectively; the working process of the CBAM attention mechanism is expressed as formula (7): (7) in, is the feature map of the input CBAM, F CBAM It is the feature map enhanced by the CBAM attention mechanism. M c is the channel attention weight map, M s is the spatial attention map, Represents element-wise multiplication operation; Finally, the enhanced feature map output by the MBconv module integrated with the CBAM attention mechanism will be fed into the Concat feature concatenation module as input to participate in the fusion calculation of multi-level feature information, thereby obtaining an improved target detection model.
[0008] Step 4 is as follows: The improved target detection model is trained to obtain the optimal target detection network after training; specifically: The PyTorch 2.2.1 platform was selected for training, the Adam optimizer was used, the number of images trained each time was 8, the initial learning rate was set to 0.01, and the weight decay regularization coefficient was 0.0005. During the training process, the classification loss, confidence loss, and localization loss were jointly optimized. After 100 epochs of training, the detection model with the best performance was obtained.
[0009] The total loss function in step 5 is expressed as: (8) in, L total represents the total loss, L cls represents the classification loss, L conf represents the confidence loss, L loc represents the positioning loss, λ cls Represents the weight of classification loss, taking 1.0, λ conf Represents the weight of confidence loss, taking 1.0, λ loc Represents the weight of the positioning loss, which is 10.0.
[0010] The classification loss and confidence loss both use a binary cross entropy loss function based on the Sigmoid function, and their mathematical expressions are: (9) in, x Represents the predicted value of the model output; y is the label value, 1 represents the positive class and 0 represents the negative class; is the Sigmoid activation function, defined as .
[0011] The positioning loss is used to measure the degree of match between the predicted bounding box and the true bounding box, taking into account three factors: overlap IoU, center point distance, and aspect ratio difference. Its mathematical expression is: (10) (11) (12) in, b is the center coordinate value of the predicted bounding box, IoU is the image overlapping area, is the coordinate of the center point of the real bounding box, α is a balance coefficient, express The Euclidean distance between the center point of the prediction box and the target box, v It is a parameter used to measure the aspect ratio between the predicted box and the real box. c 2 Represents the diagonal distance of the minimum bounding box that encloses the predicted bounding box and the true bounding box.
[0012] The beneficial effects of the present invention are: First, the CSMF module significantly improves the model's adaptability to multi-scale targets, solving the problems of inaccurate recognition of small targets such as gloves and large information redundancy in traditional models. Second, after using CBAM to enhance the MBconv module, the model can more effectively distinguish the key areas and background areas in the image, and enhance the robustness to target occlusion and background interference in complex scenes; Third, we find the optimal loss function weights through training and adjust the parameters of the composite loss function to preserve the detailed structure of small targets while ensuring detection accuracy; Fourth, while maintaining the lightweight structure of the model, the method of the present invention achieved an accuracy improvement of mAP@0.5 from 0.846 to 0.861, and the F1 score was improved to 0.84. The accuracy improvement was particularly significant on glove-type targets, proving that the improved strategy has good practical value and deployment prospects in actual construction site environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 Schematic diagram of the structure of the channel selection multi-scale fusion module (CSMF) proposed in the present invention; Figure 2 This is a schematic diagram of the CBAM attention module structure; Figure 3 Schematic diagram of the present invention using CBAM to enhance MBconv; Figure 4 This is a network framework diagram of the target detection model of the present invention; Figure 5(a) is the PR curve of the original YOLOv5 model; Figure 5(b) is the F1 score curve of the original YOLOv5 model; Figure 5 (c) is a PR curve diagram of the target detection model of the present invention; FIG5( d ) is a graph showing the F1 score of the target detection model of the present invention; DETAILED DESCRIPTION The following is a further description of the improved multi-scale adaptive fusion protective equipment detection method based on YOLOv5 of the present invention with reference to the accompanying drawings and specific embodiments.
[0014] Example 1 The present invention combines channel selection with an improved YOLOv5 protective equipment detection method with an attention mechanism. The original spatial pyramid pooling fusion module SPPF of the YOLOv5 backbone network is replaced by a channel selection multi-scale fusion module CSMF. The channel selection multi-scale fusion module CSMF adopts a feature adaptive weighted fusion strategy based on the multi-channel selection mechanism. According to the contextual information and semantic distribution of the input image features, the fusion weights of feature channels under different receptive fields are dynamically adjusted, thereby achieving more discriminative multi-scale feature integration.
[0015] Example 2 The improved YOLOv5 protective equipment detection method that combines channel selection and attention mechanism has the following specific steps: Step 1: Image preprocessing and enhancement The images collected at the construction site are normalized, resized, and color enhanced to ensure consistent image quality under different lighting and viewing angles. The processed images are used as a dataset and further divided into a training set and a test set. Step 2: Build a target detection model The original YOLOv5 network structure consists of four main components: input, backbone, neck, and head. The input preprocesses the image, including scaling, padding, and normalization, to bring it to the fixed size required by the network. The backbone extracts deep semantic features from the image. The YOLOv5 backbone includes a feature extraction module (convolution + batch normalization + SiLU activation function module), a cross-stage residual module (convolution + two feature extraction blocks + skip connection + SiLU activation function module), and an SPPF module, ensuring both feature expression and computational efficiency. The neck fuses and enhances feature maps at different levels by introducing a feature pyramid network and a path aggregation network structure, improving the model's ability to perceive objects at multiple scales. Finally, the output detection head makes predictions at multiple scales, outputting the bounding box location, category label, and corresponding confidence score for each object.
[0016] like Figure 4 As shown in FIG, the present invention designs a feature multi-scale fusion module CSMF with a multi-channel selection mechanism based on the YOLOv5 backbone network structure; the feature multi-scale fusion module CSMF performs weighted fusion on multi-scale feature maps to effectively integrate semantic information at different levels; The mobile inverted bottleneck convolution module MBconv is inserted into the YOLOv5 neck network part, and the attention module SE is replaced by the CBAM module; compared with the SE attention mechanism which only has channel attention, the CBAM module also includes the channel attention module CAM and the spatial attention module SAM; Step 3: Train the constructed target detection model; Step 4: Design the total loss function of the target detection model, which consists of classification loss, confidence loss, and positioning loss to form the overall optimization goal.
[0017] like Figure 1 As shown in Figure 2, the feature multi-scale fusion module CSMF in step 2 is as follows: In step 2.1, we first perform preliminary feature extraction on the image of the dataset in step 1 to obtain the feature map F as the input for subsequent processing. Subsequently, we design three parallel MBConv feature extraction pathways, using 3×3, 5×5, and 7×7 convolution kernels respectively to independently process the input feature map F to capture semantic information from different receptive fields. Among them, the 3×3 convolution branch is used to extract fine-grained local texture and edge features, the 5×5 convolution focuses on mid-scale structures such as region boundaries and object contours, and the 7×7 convolution is used to obtain the global semantics and background information of the image; the feature maps extracted by each of the three branches are denoted as: (1) Step 2.2, obtain the feature maps under three receptive fields 、 and After that, first perform a global average pooling GAP operation on each feature map. The pooling method is as follows: (2) in, Indicates the i In the road feature map c The channels are located in space ( x , y ), is the number of channels; H and W are the height and width of the feature map, respectively. g i c Indicates the i Road feature map c The value of each channel after GAP compression; through the GAP operation, three groups of channel-level global description vectors are obtained respectively g 1. g 2. g 3. A feature map has C channels, so each GAP operation outputs a one-dimensional vector containing C numbers, so It is a C-dimensional vector, each set of vectors represents the global response degree of the scale feature map on each channel; Subsequently, the three sets of global vectors are concatenated as input and fed into a weight-sharing multi-layer perceptron (MLP) structure. The MLP structure consists of two layers of fully connected neural networks with a nonlinear activation function ReLU added in the middle. The MLP outputs a channel weight coefficient vector of length 3. s : (3) Among them, || represents the vector concatenation operation, and Softmax is used to normalize the original weighted vector to between 0 and 1. is the weighting factor, and satisfies , each weighting factor Indicates the model's current input i Importance estimation of road-scale features; In step 2.3, after obtaining the channel weights of each scale branch, the three feature maps are weighted fused proportionally to generate the final fused feature map: (4) Step 2.4, the fused feature map F fused The input is sent to the AIFI module, which uses its embedded two-dimensional sine-cosine position embedding and multi-head self-attention mechanism to further model the long-distance dependency and spatial semantic structure between features. The AIFI module outputs the enhanced feature map for subsequent detection tasks. The process can be briefly described as follows: (5) Among them, AIFI represents the operation of spatial context modeling and global semantic enhancement on the fused feature map.
[0018] Example 3 Based on Example 2, the method of inserting the mobile inverted bottleneck convolution module MBconv into the YOLOv5 neck network part in step 2 is as follows: (1) In the neck network structure of YOLOv5, the improved MBconv module is introduced before the original Concat feature splicing module. The MBconv module adopts the structural design of extended convolution, depthwise separable convolution, and compressed convolution. The convolution process is expressed as formula (6) (6) in, F is the input feature map, F MB is the output feature map, SE() is the attention mechanism, σ is the activation function, Exp 1×1 Denotes the 1×1 convolution of the expanded dimension, Dep k×k Represents depth convolution, Conv1×1 is used to compress the dimension and return to the original number of channels; (2) In the above Mbconv module, as Figure 2-3 As shown in Figure 7, the original SE attention mechanism is replaced by the more expressive CBAM attention mechanism. The CBAM attention mechanism combines the channel attention and spatial attention mechanisms to perform saliency modeling on the feature map in the channel dimension and spatial dimension respectively. The working process of the CBAM attention mechanism is expressed as formula (7): (7) in, is the feature map of the input CBAM, F CBAM It is the feature map enhanced by the CBAM attention mechanism. M c is the channel attention weight map, M s is the spatial attention map, Represents element-wise multiplication operation; Finally, the enhanced feature map output by the MBconv module integrated with the CBAM attention mechanism will be fed into the Concat feature concatenation module as input to participate in the fusion calculation of multi-level feature information, thereby obtaining an improved target detection model.
[0019] Step 4 is as follows: The improved target detection model is trained to obtain the optimal target detection network after training; specifically: The PyTorch 2.2.1 platform was selected for training, the Adam optimizer was used, the number of images trained each time was 8, the initial learning rate was set to 0.01, and the weight decay regularization coefficient was 0.0005. During the training process, the classification loss, confidence loss, and localization loss were jointly optimized. After 100 epochs of training, the detection model with the best performance was obtained.
[0020] Example 4 Based on Example 3, the total loss function of step 5 is expressed as: (8) in, L total represents the total loss, L cls represents the classification loss, L conf represents the confidence loss, L loc represents the positioning loss, λ cls Represents the weight of classification loss, taking 1.0, λ conf Represents the weight of confidence loss, taking 1.0, λ loc Represents the weight of the positioning loss, which is 10.0.
[0021] The classification loss and confidence loss both use a binary cross entropy loss function based on the Sigmoid function, and their mathematical expressions are: (9) in, x Represents the predicted value of the model output; y is the label value, 1 represents the positive class and 0 represents the negative class; is the Sigmoid activation function, defined as .
[0022] The positioning loss is used to measure the degree of match between the predicted bounding box and the true bounding box. It takes into account three factors: overlap IoU, center point distance, and aspect ratio difference. Its mathematical expression is: (10) (11) (12) in, b is the center coordinate value of the predicted bounding box, IoU is the image overlapping area, is the coordinate of the center point of the real bounding box, α is a balance coefficient, express The Euclidean distance between the center point of the prediction box and the target box, v It is a parameter used to measure the aspect ratio between the predicted box and the real box. c 2 Represents the diagonal distance of the minimum bounding box that encloses the predicted bounding box and the true bounding box.
[0023] Example 5 This paper is based on a dataset dedicated to protective equipment (PPE). This dataset contains approximately 4,600 images, covering categories such as "protective gloves," "helmets," "reflective vests," and "people." The data samples are sourced from actual construction sites, public datasets, and simulated scene capture, ensuring data diversity and coverage.
[0024] During data preprocessing, images were first resized to 640×640 to accommodate the input requirements of the YOLOv5 network. Data augmentation was then performed, including random cropping, rotation, horizontal flipping, and color perturbation, to improve the model's robustness and generalization capabilities. The dataset was split into training and test sets in a 9:1 ratio, providing standard input for subsequent model training and performance evaluation.
[0025] The protective equipment detection method proposed in this paper is based on the YOLOv5 target detection architecture. By introducing multiple structural optimizations and attention mechanism improvements, a detection model with greater accuracy and robustness in complex construction site environments is constructed. The overall detection process is as follows: Step 1: Normalize the original construction site monitoring images or construction site photos to 640×640 size and complete the standardized preprocessing before feeding them into the model.
[0026] Step 2: After the initial feature extraction is performed through the YOLOv5 backbone network, the image in step 1 is converted into a feature map F that can reflect the features. In order to improve the network's perception of multi-scale targets, especially small-sized targets, the present invention proposes a channel-selective multi-scale fusion module (CSMF) to replace the original spatial pyramid pooling fusion module (SPPF). Based on the basic AIFI structure, this module integrates three parallel MBConv feature extraction branches with different receptive fields, and uses 3×3, 5×5 and 7×7 convolution kernels to process the input feature map F, extract local, mid-scale and global features, and the three output feature maps are recorded as F 1 、 F 2 and F 3 .
[0027] In order to achieve more discriminative multi-scale feature fusion, the CSMF module further introduces a channel selection mechanism. Global Average Pooling (GAP) is applied to the three feature maps to obtain their corresponding global context vectors. , and then the three sets of vectors are input into a shared multi-layer perceptron (MLP), and the channel selection weight vector is generated through the Softmax function , to measure the importance of feature maps at each scale. Weight vector s The calculation process is as follows:
[0028] Among them, || represents the vector concatenation operation, and Softmax is used to normalize the original weighted vector to between 0 and 1, that is, is the weighting factor, and satisfies , each weighting factor Indicates the model's current input i The importance of road-scale features is estimated. Finally, the three-way features are fused in a weighted manner and input into the AIFI module for global dependency modeling and spatial semantic enhancement. The feature fusion and enhancement process can be expressed as follows:
[0029] in, AIFIThe parentheses ( ) represent the AIFI module's enhancements to the feature map. The AIFI module leverages two-dimensional sine and cosine positional encoding and a multi-head attention mechanism to globally model long-range dependencies between features, enhancing spatial structure and semantic consistency. This significantly improves the model's detection accuracy and robustness for multiple target categories in complex construction environments.
[0030] Next, we will describe the structural principles of the AIFI (Attention-Induced Feature Interaction) module: The AIFI module is an image feature encoding module based on the Transformer structure and integrated with a two-dimensional sine-cosine position encoding mechanism. It is mainly used to enhance the semantic modeling and spatial structure understanding capabilities of convolutional neural networks in image target detection. Its output is used as an enhanced feature map for target classification and bounding box regression in subsequent detection heads.
[0031] During data flow processing, the input feature map is first represented as a four-dimensional tensor x with dimensions B×C×H×W, where B represents the batch size, C represents the number of channels, and H and W represent the image height and width, respectively. In order to adapt to the Transformer's requirements for sequence structure, the input features are first flattened into a two-dimensional sequence form, that is, x is converted to x' with dimensions B×N×C, where N is equal to H×W. Subsequently, a two-dimensional sine-cosine position embedding is introduced into the sequence to provide information constraints on the spatial position. Specifically, the second position of each position p in the position embedding is i The dimensions are calculated using the following formula:
[0032] 2nd i The +1 dimension is calculated using the following formula:
[0033] in, PE () is the position code, p Represents the position index, i represents the sub-index under the embedding dimension, d This embedding method can provide a unique and continuously distinguishable encoding for each spatial position in the sequence, allowing the Transformer to perceive the spatial position of each pixel in the image and thus preserve the spatial structure characteristics.
[0034] The feature sequence with positional encoding is then fed into a multi-head self-attention mechanism for global context modeling. In this mechanism, the feature sequence is linearly transformed into a query (Q), key (K), and value (V) matrix, and an attention score is calculated. The attention is calculated as follows:
[0035] in, , , V=xW denote query, key, and value matrices respectively, , , is the learnable weight matrix, The attention dimension. Softmax ()After calculating the attention weight, and the value vector V Weighted combination achieves dynamic aggregation of global information, which is the dimension of the key vector. Through this mechanism, the model can dynamically assign attention weights, establish long-range dependencies between different regions of the image, and effectively extract semantic information.
[0036] Subsequently, the features output by the attention mechanism are input into the feedforward neural network module through the residual connection to further complete the nonlinear transformation between feature dimensions. The feedforward module consists of two layers of linear transformation and a GELU activation function, and the output is:
[0037] in, and is the weight matrix of the linear layer, and is the bias term. This feedforward structure improves the expressiveness of features and enhances the nonlinear modeling capability of the network.
[0038] Finally, the features processed by the self-attention and feedforward networks are re-arranged and restored to the same four-dimensional structure as the original input (B×C×H×W), for further processing by subsequent modules. The entire AIFI module structurally integrates image spatial structure and semantic relationships, offering high scalability and suitability for use with convolutional architectures to achieve deep modeling and representation of image features in complex scenes.
[0039] Step 3: In the network's neck phase, the model uses a path aggregation network structure to enable interaction between features at different levels. To further enhance information transfer and feature alignment, the present invention introduces an MBconv module before each Concat fusion node to perform channel compression and nonlinear enhancement on the input feature map, effectively mitigating information redundancy.
[0040] In addition, considering that the SE attention mechanism originally used in the MBconv module only focuses on the channel dimension and is difficult to capture spatial saliency, the present invention replaces it with the more expressive CBAM attention module. The CBAM module integrates the two-level mechanisms of channel attention and spatial attention, where the channel attention is connected to the multi-layer perceptron (MLP) after maximum pooling and average pooling to obtain the channel weight coefficient, and the spatial attention uses convolution operations to identify the saliency of the target area, so that the network has both channel focusing and spatial selection capabilities. This mechanism enables the network to have stronger discrimination capabilities for small-sized protective targets (such as protective gloves) or scenes with complex backgrounds. The enhanced feature map output by the MBconv module integrated with CBAM will be fed into the Concat module as input to participate in the fusion calculation of multi-level feature information. The MB convolution process enhanced by CBAM can be expressed as the following process:
[0041] in, F is the input feature map, F MB is the output feature map, CBAM() is the attention mechanism, σ is the activation function, Exp 1×1 Denotes the 1×1 convolution of the expanded dimension, Dep k×k Denotes deep convolution, Conv1×1 is used to compress the dimension and return to the original number of channels; the working process of the CBAM attention mechanism is expressed as follows:
[0042] in, is the input feature map, F CBAM It is the feature map enhanced by the CBAM attention mechanism. M c is the channel attention weight map, M s is the spatial attention map, Represents element-wise multiplication operation; Step 4: The multi-scale prediction and output module feeds the fused feature map into three detection heads of different scales, achieving refined recognition of small, medium, and large objects. Each detection head outputs the object's bounding box coordinates, class probability, and confidence score, comprehensively covering the detection requirements of objects of different sizes. To improve the accuracy and stability of detection results, the model uses a non-maximum suppression (NMS) strategy during the prediction phase to effectively remove redundant candidate boxes with high overlap. Furthermore, the model determines the consistency of the predicted boxes with the semantic regions of the image, further enhancing the rationality of the detection results at both the visual and semantic levels.
[0043] During the training phase, the model is effectively constrained by a comprehensive loss function to improve detection performance. The total loss is composed of the classification loss L cls , confidence loss L conf and positioning loss L loc Common components:
[0044] in, L total represents the total loss, L cls represents the classification loss, L conf represents the confidence loss, L loc represents the positioning loss, λ cls The weight of the classification loss is 1.0, λ conf The weight of confidence loss is 1.0, λ loc The weight of the positioning loss is 10.0. The weight coefficient is used to balance the contribution of each loss term to ensure the coordinated optimization of the model in spatial positioning and category discrimination.
[0045] The specific contents of the loss function are as follows: Both classification loss and confidence loss use the binary cross entropy loss function (BCE) based on the Sigmoid function, and its mathematical expression is:
[0046] in, x represents the predicted value of the model output, y is the label value (1 for positive class, 0 for negative class), is the Sigmoid activation function, defined as ; This loss function calculates the confidence of each predicted category or target independently, so that the multi-label problem in multi-target detection can be effectively modeled.
[0047] Positioning loss (L loc The loss function is used to measure the degree of match between the predicted bounding box and the true bounding box, taking into account three factors: overlap (IoU), center point distance, and aspect ratio difference. Its mathematical expression is:
[0048]
[0049]
[0050] in, b is the center coordinate value of the predicted bounding box, IoU is the image overlapping area, is the coordinate of the center point of the real bounding box, α is a balance coefficient, express The Euclidean distance between the center point of the prediction box and the target box, v It is a parameter used to measure the aspect ratio between the predicted box and the real box. c 2 Represents the diagonal distance between the minimum bounding box enclosing the predicted bounding box and the ground-truth bounding box. Through the organic integration of structural design and loss constraints, the model achieves more accurate, stable, and semantically consistent object detection performance at multiple scales.
[0051] The Adam optimizer was used in the model training process, with an initial learning rate of 0.001 and a batch size of 8. Training optimization was performed on an NVIDIA GPU environment. The loss function used a joint loss strategy that included classification loss, confidence loss, and localization loss, and appropriately increased the weight of the localization loss ( λ loc =10) to improve the positioning accuracy of small target detection.
[0052] Quantitative evaluation on the test set showed that the improved YOLOv5 model achieved a significant improvement in mAP@0.5 from the original 0.846 to 0.861, with an F1 score of 0.84. This improvement was particularly evident in the detection of small objects like protective gloves, demonstrating the practicality and advancement of this method in complex construction site scenarios.
[0053] Example 6 To verify the effectiveness of the improved YOLOv5 protective gear detection model proposed in this paper, we conducted a comparative experiment with the original YOLOv5 model. By evaluating the detection performance of different models on a unified dataset, we further verified the advantages of the proposed model in terms of detection accuracy and stability.
[0054] As shown in Figures 5(a)-5(d), a comparison of the Precision-Recall (PR) curves and the F1 score curves of the original YOLOv5 model and the improved object detection model of our invention demonstrates that the proposed model performs well overall in detection tasks. The PR curve (i.e., precision-recall curve) reflects the trade-off between precision and recall at different confidence thresholds. The closer the curve is to the upper right corner, the better the overall detection performance of the model. The F1 score curve is the harmonic mean of precision and recall, and comprehensively evaluates the detection accuracy and coverage of the model. A higher value indicates a more stable and reliable model.
[0055] Experimental results show that the proposed model maintains a high F1 value in most confidence intervals, and its PR curve is generally better than the comparison model, showing stronger target recognition ability and robustness, especially in the complex construction site environment. The recognition accuracy of small targets (such as gloves) is significantly improved, and the missed detection and false detection of small targets and occluded targets in complex situations are reduced, which effectively verifies the advanced nature and practicality of the proposed method.
[0056] Table 1 presents objective metrics for the proposed method and widely used representative versions of the YOLO family (such as YOLOv3, YOLOv5, YOLOv6, and YOLOv8) on a protective equipment (PPE) dataset. Experimental data analysis demonstrates that the average detection accuracy of the improved YOLOv5s model proposed in this paper surpasses that of other models. In particular, in the detection of protective gloves, it demonstrates significant performance gains compared to the basic YOLOv5s model. Therefore, the proposed method demonstrates superior performance to other methods in quantitative evaluations.
[0057] Table 1
Claims
1. An improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism, characterized by: The original spatial pyramid pooling fusion module SPPF of the YOLOv5 backbone network is replaced by the channel selection multi-scale fusion module CSMF. The channel selection multi-scale fusion module CSMF is based on the feature adaptive weighted fusion strategy of the multi-channel selection mechanism. According to the contextual information and semantic distribution of the input image features, it dynamically adjusts the fusion weights of feature channels under different receptive fields, thereby achieving more discriminative multi-scale feature integration.
2. The improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism according to claim 1 is characterized in that: The specific steps are as follows: Step 1: Image preprocessing and enhancement The images collected at the construction site are normalized, resized, and color enhanced to ensure consistent image quality under different lighting and viewing angles. The processed images are used as a dataset and further divided into a training set and a test set. Step 2: Build a target detection model Based on the YOLOv5 backbone network structure, a feature multi-scale fusion module CSMF with a multi-channel selection mechanism is designed; The feature multi-scale fusion module CSMF performs weighted fusion on multi-scale feature maps to effectively integrate semantic information at different levels; Insert the mobile inverted bottleneck convolution module MBconv into the YOLOv5 neck network part, and replace the attention module SE with the CBAM module; Compared with the SE attention mechanism which only has channel attention, the CBAM module includes both the channel attention module CAM and the spatial attention module SAM; Step 3: Train the constructed target detection model; Step 4: Design the total loss function of the target detection model, which consists of classification loss, confidence loss, and positioning loss to form the overall optimization goal.
3. The improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism according to claim 2 is characterized in that: The feature multi-scale fusion module CSMF in step 2 is as follows: In step 2.1, we first perform preliminary feature extraction on the images in the dataset of step 1 to obtain the feature map F as the input for subsequent processing. Subsequently, we design three parallel MBConv feature extraction pathways, using 3×3, 5×5, and 7×7 convolution kernels respectively to independently process the input feature map F and capture information from different receptive fields. The 3×3 convolution branch is used to extract fine-grained local texture and edge features, the 5×5 convolution focuses on mid-scale structures such as region boundaries and object contours, and the 7×7 convolution is used to obtain the global semantics and background information of the image. The feature maps extracted by each of the three branches are denoted as: (1) Step 2.2, obtain the feature maps under three receptive fields 、 and After that, first perform a global average pooling GAP operation on each feature map. The pooling method is as follows: (2) in, Indicates the i In the road feature map c The channels are located in space ( x , y ), is the number of channels; H and W are the height and width of the feature map, respectively. g i c Indicates the i Road feature map c The value of each channel after GAP compression; through the GAP operation, three groups of channel-level global description vectors are obtained respectively , a feature map has C channels, so each GAP operation outputs a one-dimensional vector containing C numbers, so It is a C-dimensional vector, each set of vectors represents the global response degree of the scale feature map on each channel; Subsequently, the three sets of global vectors are concatenated as input and fed into a weight-sharing multi-layer perceptron (MLP) structure. The MLP structure consists of two layers of fully connected neural networks with a nonlinear activation function ReLU added in the middle. The MLP outputs a channel weight coefficient vector of length 3. s : (3) Among them, || represents the vector concatenation operation, and Softmax is used to normalize the original weighted vector to between 0 and 1. is the weighting factor, and satisfies , each weighting factor Indicates the model's current input i Importance estimation of road-scale features; In step 2.3, after obtaining the channel weights of each scale branch, the three feature maps are weighted fused proportionally to generate the final fused feature map: (4) Step 2.4, fuse the feature map F fused The input is sent to the AIFI module, which uses its embedded two-dimensional sine-cosine position embedding and multi-head self-attention mechanism to further model the long-distance dependency and spatial semantic structure between features. The AIFI module outputs the enhanced feature map for subsequent detection tasks. The process is briefly described as follows: (5) in, AIFI Represents the operation of spatial context modeling and global semantic enhancement on the fused feature map.
4. The improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism according to claim 1 is characterized in that: Step 2: Insert the mobile inverted bottleneck convolution module MBconv into the YOLOv5 neck network as follows: (1) In the neck network structure of YOLOv5, the improved MBconv module is introduced before the original Concat feature splicing module. The MBconv module adopts the structural design of extended convolution, depthwise separable convolution, and compressed convolution. The convolution process is expressed as formula (6) (6) in, F is the input feature map, F MB is the output feature map, SE() is the attention mechanism, σ is the activation function, Exp 1×1 Denotes the 1×1 convolution of the expanded dimension, Dep k×k Represents depth convolution, Conv1×1 is used to compress the dimension and return to the original number of channels; (2) In the above Mbconv module, the original SE attention mechanism is replaced by the more expressive CBAM attention mechanism; the CBAM attention mechanism combines the channel attention and spatial attention mechanisms to perform saliency modeling on the feature map in the channel dimension and spatial dimension respectively; the working process of the CBAM attention mechanism is expressed as formula (7): (7) in, is the feature map of the input CBAM, F CBAM It is the feature map enhanced by the CBAM attention mechanism. M c is the channel attention weight map, M s is the spatial attention map, Represents element-wise multiplication operation; Finally, the enhanced feature map output by the MBconv module integrated with the CBAM attention mechanism will be fed into the Concat feature concatenation module as input to participate in the fusion calculation of multi-level feature information, thereby obtaining an improved target detection model.
5. The improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism according to claim 1 is characterized in that: Step 4 is as follows: The improved target detection model is trained to obtain the optimal target detection network after training; specifically: The PyTorch 2.2.1 platform was selected for training, the Adam optimizer was used, the number of images trained each time was 8, the initial learning rate was set to 0.01, and the weight decay regularization coefficient was 0.0005. During the training process, the classification loss, confidence loss, and localization loss were jointly optimized. After 100 epochs of training, the detection model with the best performance was obtained.
6. The improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism according to claim 1 is characterized in that: The total loss function in step 5 is expressed as: (8) in, L total represents the total loss, L cls represents the classification loss, L conf represents the confidence loss, L loc represents the positioning loss, λ cls Represents the weight of classification loss, taking 1.0, λ conf Represents the weight of confidence loss, taking 1.0, λ loc Represents the weight of the positioning loss, which is 10.
0.
7. The improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism according to claim 6 is characterized in that: The classification loss and confidence loss both use a binary cross entropy loss function based on the Sigmoid function, and their mathematical expressions are: (9) in, x Represents the predicted value of the model output; y is the label value, 1 represents the positive class and 0 represents the negative class; is the Sigmoid activation function, defined as .
8. The improved YOLOv5 protective equipment detection method combining channel selection and attention mechanism according to claim 7 is characterized in that: The positioning loss is used to measure the degree of match between the predicted bounding box and the true bounding box, taking into account three factors: overlap IoU, center point distance, and aspect ratio difference. Its mathematical expression is: (10) (11) (12) in, b is the center coordinate value of the predicted bounding box, IoU is the image overlapping area, is the coordinate of the center point of the real bounding box, α is a balance coefficient, express The Euclidean distance between the center point of the prediction box and the target box, v It is a parameter used to measure the aspect ratio between the predicted box and the real box. C 2 Represents the diagonal distance of the minimum bounding box that encloses the predicted bounding box and the true bounding box.
Citation Information
Cited By
Insulator ultraviolet corona discharge target detection method based on YOLO-SM
CN120912997A
Pyramid type YOLOv5 industrial small target detection system fusing attention mechanism
CN121213532A
Lightweight SAR (Synthetic Aperture Radar) image target detection system and method fused with multi-scale attention
CN121353648A
Construction site dynamic adaptive target detection method, device and equipment and storage medium
CN121582877A
Cell real-time detection method and device based on improved YOLOv12 and storage medium
CN121685440A