A Substation Weed Detection Method and System Based on YOLOv5 and Attention Mechanism

By improving the YOLOv5 network model and introducing the Weed Self-Attention Module (WSA), the problems of low efficiency and insufficient accuracy in substation weed detection were solved, achieving higher accuracy and faster speed weed detection, adapting to complex backgrounds and varying lighting conditions.

CN117237696BActive Publication Date: 2026-01-06STATE GRID HUNAN ELECTRIC POWER COMPANY LIMITED +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310959093.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-01
Publication Date
2026-01-06
Estimated Expiration
2043-08-01

AI Technical Summary

Technical Problem

Existing technologies are inefficient, inaccurate, and lack robustness in weed detection in substations, making it difficult to meet the detection challenges under complex backgrounds and varying lighting conditions.

Method used

An improved YOLOv5 network model was adopted, combined with an attention mechanism. By adding a Weed Self-Attention (WSA) module to the Neck network, long-range dependencies were captured, and the network's attention to key areas was adaptively adjusted to enhance the detection capability of weeds.

Benefits of technology

It improves the accuracy and robustness of weed detection in substations, enabling faster processing of weeds under complex backgrounds and varying lighting conditions, and achieving real-time detection and location.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117237696B_ABST
    Figure CN117237696B_ABST
Patent Text Reader

Abstract

The application discloses a transformer substation weed detection method and system based on YOLOv5 and an attention mechanism, the method comprising using a YOLOv5 network model improved by using an attention mechanism to realize detection of weeds in a transformer substation, wherein the YOLOv5 network model improved by using the attention mechanism refers to that on the basis of a YOLOv5 network model composed of a backbone network, a neck network and a prediction network, a weed self-attention module WSA is added in front of a feature enhancement module CBS of a top-down feature fusion channel and a bottom-up feature fusion channel in the neck network to enhance the detection capability of weeds under complex background and variable light conditions. The application aims to optimize and improve YOLOv5 to make it more suitable for weed conditions in transformer substations, so that it has higher detection precision, better robustness and faster processing speed, and can effectively cope with the challenges of weed detection under complex background, easy to be blocked and variable light conditions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer vision processing technology, specifically to a method and system for detecting weeds in substations based on YOLOv5 and attention mechanisms. Background Technology

[0002] In recent years, deep learning technology has made significant progress in computer vision and pattern recognition. By constructing multi-layer neural network models, deep learning can automatically learn and extract high-level features from large-scale data to achieve highly accurate image recognition and object detection. In the field of image processing and analysis, the emergence of deep learning has provided new opportunities and methods for object detection. With the rise of deep learning, object detection methods based on deep neural networks have made great progress. Among them, YOLOv5 is a relatively new object detection algorithm, characterized by its speed, accuracy, and end-to-end capabilities. YOLOv5 achieves real-time object detection and localization by segmenting images into grid cells and predicting the bounding box and category of the target in each cell. Compared with traditional methods, the YOLOv5 algorithm can process large-scale image data faster and has better robustness. Furthermore, attention mechanisms, as a key technology in deep learning, can help the network focus on important regions in an image, improving its ability to perceive targets. By introducing attention mechanisms, the network can adaptively adjust the degree of attention given to different regions, thereby enhancing the model's detection capabilities. Attention mechanisms have been widely used in image processing and object detection, effectively improving the accuracy and robustness of models.

[0003] Substation weed detection is a crucial task in power system maintenance and management. With the development of power systems and the increase in the number of substations, the growth of weeds around substations has become a problem that cannot be ignored. Substations, as hubs for power transmission, play a vital role in the power system. The operating environment of equipment within a substation directly affects the safe and stable operation of the power system. However, every spring, abundant rainfall leads to vigorous growth of trees and weeds in the outdoor areas of substations. If not cleared in time, this not only affects the appearance of the substation, but when weeds grow to a certain height, especially climbing vines, they can potentially cause damage to substation equipment, power transmission interruptions, and even fire hazards. Therefore, real-time and accurate detection and location of substation weeds are of great significance for the normal operation and safety of the power system. Currently, the management of the substation operating environment mainly relies on inspections by maintenance personnel. However, substations are not only widely distributed but also increasingly numerous, making manual inspections by maintenance personnel inefficient and ineffective. Summary of the Invention

[0004] The technical problem to be solved by this invention is to provide a method and system for detecting weeds in substations based on YOLOv5 and attention mechanism, which addresses the above-mentioned problems in the prior art. This invention aims to optimize and improve YOLOv5 to make it more suitable for the weed situation in substations, so that it has higher detection accuracy, better robustness and faster processing speed, and can effectively cope with the challenges of weed detection under complex backgrounds, easy occlusion and changing light conditions.

[0005] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:

[0006] A substation weed detection method based on YOLOv5 and attention mechanism includes using a YOLOv5 network model improved with attention mechanism to detect weeds in the substation. The improved YOLOv5 network model refers to adding a weed self-attention module (WSA) before the feature enhancement modules (CBS) of the top-down and bottom-up feature fusion channels in the Neck network. This WSA captures long-range dependencies and adaptively adjusts the network's attention to key areas to enhance weed detection capabilities under complex backgrounds and varying lighting conditions. The WSA has an input dimension of [missing information]. The processing of the H×W×C feature map X includes: passing the feature map X through two convolutional layers (Conv) to obtain features X1 and X2, with dimensions of H×W×2C and H×W×C / 2 respectively; then, performing feature fusion on the channel dimension by concatenating features X1 and X2 through the concatenation operation (Concat), restoring the channel dimension to C, and obtaining matrix Q; simultaneously, feeding the feature map X into a convolutional layer for feature extraction, obtaining feature X3, whose dimension remains unchanged at H×W×C; then, using feature X3 as matrix K, multiplying matrix Q by the transpose of matrix K, dividing by a scaling factor, and then processing the result using the Softmax function; finally, using the feature map X directly as matrix V, multiplying it by the result obtained after the Softmax function, and obtaining the final output feature X' with the same dimension of H×W×C.

[0007] Optionally, the feature maps output by the backbone network include feature maps F1 to F4 arranged from largest to smallest. The processing of feature maps F1 to F4 by the neck network includes: processing feature map F4 through the second cross-processing stage CSP2 and the first feature enhancement module CBS of the neck network to obtain feature map F41; upsampling feature map F41 and connecting it with feature map F3 through the connection module Concat; then processing it through the second cross-processing stage CSP2, the weed self-attention module WSA, and the second feature enhancement module CBS of the neck network to obtain feature map F31; upsampling feature map F31 and connecting it with feature map F3 through the connection module Concat; and finally processing feature map F31 through the second cross-processing stage CSP2, the weed self-attention module WSA, and the second feature enhancement module CBS of the neck network to obtain feature map F31; and upsampling feature map F31 and connecting it with feature map F31 through the connection module Concat. F2 is connected via the Concat module, then processed by the second cross-processing stage (CSP2), the Weed Self-Attention module (WSA), and the third feature enhancement module (CBS) of the Neck network to obtain feature map F21. Feature map F21 is then upsampled by the upsampling module and connected to feature map F1 via the Concat module. After processing by the second cross-processing stage (CSP2), feature map F11 is obtained. Feature map F11 is then fed into the first detection head of the Prediction network after passing through the Conv module. Finally, feature map F11 is processed by the Weed Self-Attention module (WSA) and the fourth feature enhancement module (CBS) of the Neck network to obtain feature map F. 12. Feature maps F12 and F21 are concatenated using the concatenation module Concat, and then processed through the second cross-processing stage CSP2 to obtain feature map F22. Feature map F22 is then fed into the second detection head of the prediction network Prediction after passing through the convolution module Conv. Feature map F22 is then processed through the weed self-attention module WSA and the fifth feature enhancement module CBS of the neck network Neck to obtain feature map F32. Feature maps F32 and F31 are concatenated using the concatenation module Concat, and then processed through the second cross-processing stage CSP2 to obtain feature map F33. Feature map F33 is then fed into the prediction network P after passing through the convolution module Conv. The third detection head of the prediction network, Prediction, processes feature map F32 through the Weed Self-Attention Module (WSA) and the sixth feature enhancement module (CBS) of the Neck network to obtain feature map F42. Feature map F21 and feature map F31 are processed through convolutional layers. The features obtained from the convolutional layers of feature maps F11 and F21, the features obtained from the convolutional layer of feature map F31, and feature map F42 are then connected through the Concat module. After processing through the second cross-processing stage (CSP2), feature map F43 is obtained. Feature map F43 is then fed into the fourth detection head of the prediction network, Prediction, after passing through the Conv module.

[0008] Optionally, the feature enhancement module CBS processes the input features by sequentially passing the input features through convolution, batch normalization, and SiLU activation function to obtain the output features.

[0009] Optionally, the second cross-stage CSP2 process for the input features includes: dividing the input features into two branches, one branch being processed by a feature enhancement module CBS, and the other branch being processed by multiple cascaded feature enhancement modules CBS. The features output from the two branches are then connected by a connection module Concat, and then processed by another feature enhancement module CBS to obtain the output features.

[0010] Optionally, the processing of the input weed detection image in the substation by the backbone network includes: passing the weed detection image sequentially through the Focus module, the Feature Enhancement module CBS, and the first cross-stage part CSP1 to obtain feature map F1; passing feature map F1 through the Feature Enhancement module CBS and the first cross-stage part CSP1 to obtain feature map F2; passing feature map F2 through the Feature Enhancement module CBS and the first cross-stage part CSP1 to obtain feature map F3; and passing feature map F3 through the Feature Enhancement module CBS and the Spatial Pyramid Pooling module SPP to obtain feature map F4.

[0011] Optionally, the Focus module's processing of the weed detection image includes: slicing the weed detection image into multiple slices using multiple Slice modules, then connecting the multiple slices using a Concat module, and finally processing them using a feature enhancement module CBS to obtain output features.

[0012] Optionally, the spatial pyramid pooling module SPP processes the input features by: processing the input features through the feature enhancement module CBS, then performing max pooling on the features obtained after CBS processing through multiple max pooling modules, finally concatenating all max pooling results through the concat module, and then processing them through another feature enhancement module CBS to obtain the output features.

[0013] Optionally, the first cross-stage CSP1 processes the input features by: dividing the input features into two branches, one branch being processed by a feature enhancement module CBS, and the other branch being processed by a feature enhancement module CBS and a multi-level residual unit; then concatenating the features output from the two branches through a connection module Concat, and then processing them through a feature enhancement module CBS to obtain the output features; the residual unit processes the input features by: processing the input features sequentially through two feature enhancement modules CBS, and then adding them to the original input features of the residual unit to obtain the output features of the residual unit.

[0014] Furthermore, the present invention also provides a substation weed detection system based on YOLOv5 and attention mechanism, including a microprocessor and a memory interconnected thereto, wherein the microprocessor is programmed or configured to execute the substation weed detection method based on YOLOv5 and attention mechanism.

[0015] Furthermore, the present invention also provides a computer-readable storage medium storing a computer program for being programmed or configured by a microprocessor to execute the substation weed detection method based on YOLOv5 and attention mechanism.

[0016] Compared with existing technologies, this invention has the following main advantages: The substation weed detection method based on YOLOv5 and attention mechanisms includes adding a weed self-attention module (WSA) before the feature enhancement modules (CBS) of the top-down and bottom-up feature fusion channels in the Neck network. This captures long-range dependencies and adaptively adjusts the network's attention to key areas to enhance weed detection capabilities under complex backgrounds and varying lighting conditions. It can learn and extract features of substation weeds, achieving real-time detection and localization. Compared to traditional YOLOv5 methods, this method is more suitable for substation weed conditions, offering higher detection accuracy, better robustness, and faster processing speed, effectively addressing the challenges of weed detection under complex backgrounds and varying lighting conditions. Attached Figure Description

[0017] Figure 1 This is a schematic diagram of the network structure of the Weed Self-Attention Module (WSA) in an embodiment of the present invention.

[0018] Figure 2 This is a schematic diagram of the network structure of the improved YOLOv5 network model in an embodiment of the present invention.

[0019] Figure 3This is a schematic diagram of the network structure of the feature enhancement module CBS in an embodiment of the present invention.

[0020] Figure 4 This is a schematic diagram of the network structure of the second cross-phase CSP2 in an embodiment of the present invention.

[0021] Figure 5 This is a schematic diagram of the network structure of the Focus module in an embodiment of the present invention.

[0022] Figure 6 This is a schematic diagram of the network structure of the spatial pyramid pooling module SPP in an embodiment of the present invention.

[0023] Figure 7 This is a schematic diagram of the network structure of the first cross-phase CSP1 in an embodiment of the present invention.

[0024] Figure 8 This is a schematic diagram of the network structure of the residual unit in an embodiment of the present invention. Detailed Implementation

[0025] This embodiment of the substation weed detection method based on YOLOv5 and attention mechanism includes using a YOLOv5 network model improved with attention mechanism to detect weeds in the substation. The improved YOLOv5 network model refers to adding a weed self-attention module (WSA) before the feature enhancement modules (CBS) of the top-down and bottom-up feature fusion channels in the Neck network to capture long-range dependencies and adaptively adjust the network's attention to key areas to enhance the detection capability of weeds in complex backgrounds and under varying lighting conditions.

[0026] like Figure 1 As shown, the Weed Self-Attention Module (WSA) processes the input feature map X of dimension H×W×C as follows: The feature map X is passed through two convolutional layers (Conv) to obtain features X1 and X2, with dimensions H×W×2C and H×W×C / 2 respectively; then, features X1 and X2 are fused along the channel dimension using the concatenation operation (Concat), restoring the channel dimension to C, resulting in matrix Q; simultaneously, the feature map X is fed into a convolutional layer for feature extraction, yielding feature X3, whose dimension remains unchanged at H×W×C; then, feature X3 is used as matrix K, matrix Q is multiplied by the transpose of matrix K, divided by a scaling factor, and the result is processed by the Softmax function; finally, the feature map X is directly used as matrix V, multiplied by the result obtained after the Softmax function, resulting in the final output feature X', still with a dimension of H×W×C. Figure 1 As shown, during Attention calculation, Q, K, and V are not obtained through linear transformations of the input feature maps. Specifically, assuming the input feature map is X with dimensions H×W×C, X is passed through two convolutional layers to obtain two features X1 and X2 with dimensions H×W×2C and H×W×C / 2 respectively. Then, features X1 and X2 are fused along the channel dimension using a Concat operation, restoring the channel dimension to C, resulting in matrix Q. X is then fed into a convolutional layer for feature extraction, yielding feature X3, whose dimension remains unchanged at H×W×C, and used as matrix K. Matrix Q is then multiplied by the transpose of K, divided by a scaling factor, and the result is processed using the Softmax activation function. Finally, feature X is directly used as matrix V and multiplied by the result of the Softmax activation function to obtain the final output feature X′, whose dimension remains H×W×C. This process can be represented as follows:

[0027]

[0028] Where Q = Concat(Conv(X), Conv(X)), K = Conv(X), and V = X. Concat() and Conv() represent the concatenation operation (Concat) and convolution operation, respectively. k For dimensions.

[0029] like Figure 2As shown, the feature maps output by the backbone network include feature maps F1 to F4 arranged from largest to smallest. The processing of feature maps F1 to F4 by the neck network includes: passing feature map F4 through the second cross-processing stage CSP2 and the first feature enhancement module CBS of the neck network to obtain feature map F41; upsampling feature map F41 and connecting it with feature map F3 through the connection module Concat; then passing it through the second cross-processing stage CSP2, the weed self-attention module WSA, and the second feature enhancement module CBS of the neck network to obtain feature map F31; upsampling feature map F31 and connecting it with feature map F2... The feature map F21 is obtained by performing a concatenation operation through the concat module, followed by processing through the second cross-processing stage (CSP2), the weed self-attention module (WSA), and the third feature enhancement module (CBS) of the neck network. Feature map F21 is then upsampled by the upsampling module and concatenated with feature map F1 through the concat module. After processing through the second cross-processing stage (CSP2), feature map F11 is obtained. Feature map F11 is then fed into the first detection head of the prediction network (Prediction) after passing through the convolution module (Conv). Finally, feature map F11 is processed through the weed self-attention module (WSA) and the fourth feature enhancement module (CBS) of the neck network to obtain feature map F1. 2. Feature maps F12 and F21 are concatenated using the concatenation module Concat, and then processed through the second cross-processing stage CSP2 to obtain feature map F22. Feature map F22 is then fed into the second detection head of the prediction network Prediction after passing through the convolution module Conv. Feature map F22 is then processed through the weed self-attention module WSA and the fifth feature enhancement module CBS of the neck network Neck to obtain feature map F32. Feature maps F32 and F31 are concatenated using the concatenation module Concat, and then processed through the second cross-processing stage CSP2 to obtain feature map F33. Feature map F33 is then fed into the prediction network P after passing through the convolution module Conv. The third detection head of the prediction network, Prediction, processes feature map F32 through the Weed Self-Attention Module (WSA) and the sixth feature enhancement module (CBS) of the Neck network to obtain feature map F42. Feature map F21 and feature map F31 are processed through convolutional layers. The features obtained from the convolutional layers of feature maps F11 and F21, the features obtained from the convolutional layer of feature map F31, and feature map F42 are then connected through the Concat module. After processing through the second cross-processing stage (CSP2), feature map F43 is obtained. Feature map F43 is then fed into the fourth detection head of the prediction network, Prediction, after passing through the Conv module.Compared to the YOLOv5 Neck, the Neck network increases the height of the feature pyramid, performs feature fusion at more scales, and obtains feature representations at more different scales. This allows it to capture features from details to the global picture, aiding in the detection of multi-scale targets and effectively addressing the low detection accuracy caused by the large differences in weed scale. Specifically, in the YOLOv5 Neck, during the top-down feature fusion process, after the last connection operation, it continues with the second cross-step (CSP2) phase, the feature enhancement module (CBS), and upsampling. The output is then fused with the features extracted in the first second cross-step (CSP2) phase of the backbone network, obtaining features at more scales. Simultaneously, a constructed Weed Self-Attention (WSA) module is incorporated. Adding WSA before each CBS input allows the network to learn spatial relationships between different feature maps at the same scale, making the network more focused on the target's location. This helps in target localization and handling occlusion and multiple targets, thereby improving target detection accuracy. Correspondingly, the bottom-up feature fusion height is also increased.

[0030] like Figure 3 As shown, the feature enhancement module CBS(Conv+BatchNorm+SiLU) processes the input features by sequentially activating them through convolution, batch normalization (BatchNorm), and SiLU activation functions to obtain the output features.

[0031] like Figure 4 As shown, the second cross-stage part (CSP) 2 processes the input features by dividing the input features into two branches. One branch is processed by a feature enhancement module (CBS), and the other branch is processed by multiple cascaded feature enhancement modules (CBS). The features output from the two branches are then connected by the connection module (Concat) and processed by another feature enhancement module (CBS) to obtain the output features.

[0032] like Figure 2As shown, the processing of the input weed detection image in the substation by the backbone network includes: passing the weed detection image sequentially through the Focus module, the CBS module, and the first cross-stage part CSP1 to obtain feature map F1; passing feature map F1 through the CBS module and the first cross-stage part CSP1 to obtain feature map F2; passing feature map F2 through the CBS module and the first cross-stage part CSP1 to obtain feature map F3; and passing feature map F3 through the CBS module and the spatial pyramid pooling module SPP to obtain feature map F4. The backbone network combines the characteristics of the first cross-stage part CSP1 and the Darknet53 network, and achieves efficient feature extraction of the input image through multi-level feature extraction.

[0033] like Figure 5 As shown, the Focus module processes the weed detection image by: slicing the weed detection image into multiple slices using the Slice module, then connecting the multiple slices using the Concat module, and finally processing them using the CBS feature enhancement module to obtain the output features.

[0034] like Figure 6 As shown, the spatial pyramid pooling module SPP processes the input features as follows: the input features are processed by the feature enhancement module CBS, the features obtained after processing by the feature enhancement module CBS are then processed by multiple max pooling modules, and finally all the max pooling results are concatenated by the connection module Concat, and then processed by another feature enhancement module CBS to obtain the output features.

[0035] like Figure 7 As shown, the first cross-processing stage CSP1 processes the input features by dividing them into two branches. One branch is processed by a feature enhancement module CBS, and the other branch is processed by the feature enhancement module CBS and a multi-level residual unit (CBS). Figure 7 The features are processed as X*ResUnit, and then the features output from the two branches are concatenated using the Concat module. Finally, they are processed by a feature enhancement module CBS to obtain the output features. Figure 8 As shown, the Residual Unit (ResUnit) processes the input features by sequentially passing the input features through two feature enhancement modules (CBS), and then adding them to the original input features of the Residual Unit as the output features of the Residual Unit.

[0036] The original image of the weeds to be detected has dimensions of H0×W0×C0 (H0=640, W0=640, C0=3), where the parameters represent the original height, width, and number of channels, respectively. After being input into the backbone network, the Focus module performs preliminary feature extraction to obtain feature S1, with dimensions of H_1×W_1×C_1 (H_1=320, W_1=320, C_1=64). Feature S1 then enters the multi-level feature enhancement module CBS (Conv+BatchNorm+SiLU) and the first cross-stage CSP1 (CrossStage Partial 1). The first cross-stage CSP1 divides the input feature map into a backbone branch and a cross-stage branch. The backbone branch extracts complex features through a series of multi-level feature enhancement modules CBS, while the cross-stage branch performs downsampling operations to reduce the spatial size of the feature map while keeping the number of channels unchanged. Finally, the feature maps of the backbone branch and the cross-stage branch are concatenated along the channel dimension to keep the output feature dimension unchanged. Finally, feature F1 is obtained, with dimensions H2×W2×C2 (H2=160, W2=160, C2=128). Feature F1 is then used for subsequent feature fusion and further extracted by the feature enhancement module CBS and the first cross-step CSP1, resulting in a richer feature F2 with dimensions H3×W3×C3 (H3=80, W3=80, C3=256). Similarly, feature F2 is used for subsequent feature fusion and further extracted by the feature enhancement module CBS and the first cross-step CSP1, resulting in feature F3 with dimensions H4×W4×C4 (H4=40, W4=40, C4=512). Feature F3 is also used for subsequent feature fusion and then input into the feature enhancement module CBS and the Spatial Pyramid Pooling module SPP. The Spatial Pyramid Pooling (SPP) module applies max pooling operations to pooling layers of varying sizes and merges multiple pooling results into a fixed-length vector. This allows for the extraction of spatial information at different scales from the input feature map, better capturing features of objects of varying sizes, improving detection performance, and enhancing the model's understanding of the entire image scene. Finally, feature F4 is obtained, with dimensions H5×W5×C5 (H5=20, W5=20, C5=1024).

[0037] The Neck network is used for bidirectional feature pyramid fusion. First, there is top-down feature fusion, which involves three upsampling operations. Before each upsampling, a Weed Self-Attention (WSA) module is added to allow the network to adaptively adjust its attention to key regions. After each upsampling, the feature is fused with the corresponding feature from the backbone network. Specifically, the final feature F4 obtained from the backbone network enters the Feature Enhancement (CBS) module, where the feature space size remains unchanged, but the number of channels is halved, resulting in feature F41 with dimensions H′1×W′1×C′1 (H′1=20, W′1=20, C′1=512). Feature F41 is then used for subsequent feature fusion and, after upsampling, is fused with feature F3 to obtain feature Z2 with dimensions H′2×W′2×C′2 (H′2=40, W′2=40, C′2=512). The calculation process is as follows:

[0038] Z2 = Concat(F3, Up(F41)),

[0039] Concat() and Up() represent the concatenation operation and the upsampling operation, respectively.

[0040] Next, feature Z2 is passed through the second cross-interval phase CSP2 and then enters the Weed-Self-Attention (WSA) module. The Weed-Self-Attention (WSA) module is an attention module, and its calculation method is as follows:

[0041]

[0042] Where Q = Concat(Conv(CSP(Z2)), Conv(CSP(Z2))), K = Conv(CSP(Z2)), and V = CSP(Z2). Concat(), Conv(), and CSP() represent the connection operation, convolution operation, and the operation of the second crossover phase CSP2, respectively. kThe features obtained from the Weed Self-Attention Module (WSA) enter the Feature Enhancement Module (CBS). While maintaining the spatial size of the features, the number of channels is doubled, resulting in feature F31 with dimensions H′3×W′3×C′3 (H′3=40, W′3=40, C′3=256). Feature F31 is then used for subsequent feature fusion and, after upsampling, is fused with feature F2 to obtain feature Z4, with dimensions H′4×W′4×C′4 (H′4=80, W′4=80, C′4=256). The calculation process is similar to that of Z2. Feature Z4 then enters the second cross-step phase (CSP2), the Weed Self-Attention Module (WSA), and the Feature Enhancement Module (CBS) to obtain feature F21, with dimensions H′5×W′5×C′5 (H′5=80, W′5=80, C′5=128). The calculation process is similar to that of F31. Similarly, feature F21 is used for subsequent feature fusion and, after upsampling, is fused with feature F12 to obtain feature Z6, which has dimensions of H′6×W′6×C′6 (H′6=160, W′6=160, C′6=128). The calculation process is similar to that of Z2. Then, the bottom-up feature fusion part, corresponding to the top-down feature fusion part, is introduced. This part includes three downsampling steps, namely the feature enhancement module CBS. Before each downsampling step, a weed self-attention module WSA is added, enabling the network to adaptively adjust its attention to key regions. After each downsampling step, it is fused with the corresponding features from the top-down feature fusion part. The specific process is as follows: Feature Z6 successively enters the second cross-stage CSP2, the weed self-attention module WSA, and the feature enhancement module CBS (the channel dimension remains unchanged, but the width and height are halved). The resulting feature F32 is then fused with feature F31 to obtain feature P1, whose dimension is H″1×W″1×C″1 (H″1=80, W″1=80, C″1=128). The calculation process is as follows:

[0043] P1=Concat(F21,CBS(WSA(CSP(Z6)))),

[0044] Here, Concat(), CBS(), WSA(), and CSP() represent the operation, feature enhancement module CBS, weed self-attention module WSA, and CSP module, respectively. Feature P1, like feature Z6, enters the second cross-step phase CSP2, the weed self-attention module WSA, and the feature enhancement module CBS sequentially. However, this second cross-step phase CSP2 differs from the previous one. The previous CSP2 did not change the feature size, but the current CSP2 doubles the channel dimension. The resulting feature is then fused with feature F31 to obtain feature P2, whose dimensions are H″2×W″2×C″2 (H″2=40, W″2=40, C″2=256). The calculation process is similar to that of feature P1. Feature P2 undergoes the same operation, successively entering the second cross-stage CSP2 (doubling the channel dimension), the Weed Self-Attention Module (WSA), and the Feature Enhancement Module (halving the width and height dimensions). The resulting feature is then fused with features F41, F31, and F32 to obtain feature P3, whose dimensions are H″3 × W″3 × C″3 (H″3 = 20, W″3 = 20, C″3 = 512). The calculation process is as follows:

[0045] P3=Concat(F41,Conv(F31),Conv(F21),F42),

[0046] Where F42 = CBS(WSA(CSP(P2))), Concat(), CBS(), WSA(), CSP(), and Conv() represent the Concat operation, the feature enhancement module CBS, the weed self-attention module WSA, the second cross-stage CSP2, and the convolutional module, respectively. Through the network's neck section, features from the backbone network are further extracted and integrated: allowing information transfer between features at different levels. Lower-level features typically contain more detailed information, while higher-level features contain richer semantic information. Through information transfer, the model can combine features from different levels, merging feature maps from different scales. The fused features possess rich semantic information and can retain low-level details while possessing high-level semantic information, thus helping to improve detection performance.

[0047] Next is the Prediction part of the network, which is the final part of the entire model and is responsible for converting the feature maps extracted by the network into the final object detection results. Features F11, F22, F33, and F43 from the feature pyramid fusion part are passed through the convolutional layers of the Prediction network, and then the input feature maps are processed to obtain four feature maps of different scales for generating the final detection results. In the Prediction part, due to the increased height of the feature pyramid in the Neck part of the network, the number of prediction heads in the Prediction part has also increased from 3 in YOLOv5 to 4. This helps improve the model's global perception ability, enabling the model to detect targets through features at more scales, handle targets of different scales, and enhance the detection ability of small targets such as weeds. To verify the substation weed detection method based on YOLOv5 and attention mechanism in this embodiment, this paper conducts comparative experiments on the classic YOLOv5 method, YOLOv5 + prediction head (including related improvements to the prediction head, which is equivalent to removing the WSA structure in the improved YOLOv5 network model of this embodiment), and the method of this embodiment (YOLOv5 + prediction head + WSA). Three well-known detection metrics, average precision (AP), small object detection precision (APs), and average recall (AR), are used. The final results are shown in Table 1.

[0048] Table 1: Comparison results of detection indicators.

[0049]

[0050]

[0051] As shown in Table 1, the "YOLOv5 + Prediction Head" method significantly improves various metrics compared to the classic YOLOv5 method, especially the improvement in accuracy (Aps) for small object detection. This embodiment demonstrates that the substation weed detection method based on YOLOv5 and an attention mechanism modifies the original PANet feature pyramid bidirectional fusion module, increasing the height of the feature pyramid and resulting in four prediction heads, thus enhancing the detection of small weed targets and mitigating the impact of large weed scale variations. Furthermore, the YOLOv5 + Prediction Head + WSA method shows significant improvements in various metrics compared to the comparison method. Specifically, by adding a new weed self-attention module (WSA), the network can adaptively adjust its focus on key regions based on multi-scale feature information, enhancing the accuracy of weed detection under complex conditions such as occlusion. Combining the improved network structure and the constructed weed self-attention module (WSA), the network architecture for the substation weed detection method based on YOLOv5 and an attention mechanism is constructed.

[0052] In summary, to address the low efficiency of manual substation maintenance and the insufficient accuracy and robustness of traditional methods in substation weed detection, this embodiment proposes a substation weed detection method based on YOLOv5 and an attention mechanism. This method modifies the YOLOv5 model structure and constructs a new attention module—the Weed Self-Attention Module (WSA)—which captures long-range dependencies and adaptively adjusts the network's focus on key areas, thereby enhancing weed detection capabilities under complex backgrounds and varying lighting conditions. Furthermore, this embodiment modifies the YOLOv5 network structure, increasing the feature pyramid height and adding a new prediction head (branch) to the Prediction network. This allows the model to better detect small-scale objects, learn and extract substation weed features, and achieve real-time weed detection and localization. Compared to the traditional YOLOv5 method, the substation weed detection method based on YOLOv5 and attention mechanism in this embodiment is more suitable for the weed situation in substations. It has higher detection accuracy, better robustness and faster processing speed, and can effectively cope with the weed detection challenges under complex backgrounds and changing lighting conditions.

[0053] Furthermore, this embodiment also provides a substation weed detection system based on YOLOv5 and an attention mechanism, including a microprocessor and a memory interconnected thereon. The microprocessor is programmed or configured to execute the substation weed detection method based on YOLOv5 and an attention mechanism. Additionally, this embodiment also provides a computer-readable storage medium storing a computer program for being programmed or configured by the microprocessor to execute the substation weed detection method based on YOLOv5 and an attention mechanism.

[0054] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-readable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The functions specified in one or more boxes. These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable apparatus for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0055] The above description is merely a preferred embodiment of the present invention. The scope of protection of the present invention is not limited to the above embodiments. All technical solutions falling within the scope of the present invention's concept are within the scope of protection of the present invention. It should be noted that for those skilled in the art, any improvements and modifications made without departing from the principles of the present invention should also be considered within the scope of protection of the present invention.

Claims

1. A substation weed detection method based on YOLOv5 and attention mechanism, characterized in that, The improved YOLOv5 network model with attention mechanism is used to realize the detection of weeds in the transformer substation, wherein the improved YOLOv5 network model with attention mechanism refers to adding a weed self-attention module WSA in front of a feature enhancement module CBS in a top-down feature fusion channel and a bottom-up feature fusion channel in a neck network Neck on the basis of a YOLOv5 network model composed of a backbone network Backbone, a neck network Neck and a prediction network Prediction, so as to capture long-range dependencies, adaptively adjust the attention degree of the network to the key area, and enhance the detection ability of weeds under complex background and variable light conditions; the processing of the weed self-attention module WSA on the input feature map X with the dimension size of H*W*C includes: passing the feature map X through two convolution layers Conv respectively to obtain features X1 and X2 with the dimension sizes of H*W*2C and H*W*C / 2 respectively; then, the features X1 and X2 are fused in the channel dimension through a connection operation Concat, and the channel dimension is restored to C to obtain a matrix Q; at the same time, the feature map X is sent to a convolution layer for feature extraction to obtain a feature X3 with the unchanged dimension size of H*W*C; then, the feature X3 is taken as a matrix K, the matrix Q is multiplied by the transpose of the matrix K, and then the result is divided by a scaling factor, and then the result is processed by a Softmax function; finally, the feature map X is directly taken as a matrix V, and the result obtained after the Softmax function processing is multiplied by the matrix V to obtain an output feature X' with the dimension size of H*W*C. The feature maps output by the backbone network Backbone include feature maps F1-F4 arranged from large to small, and processing of the feature maps F1-F4 by the neck network Neck includes: processing the feature map F4 through the second cross stage part CSP2, the first feature enhancement module CBS of the neck network Neck to obtain a feature map F41, connecting the feature map F41 after being up-sampled by an up-sampling module with the feature map F3 through a connection module Concat, and then processing through the second cross stage part CSP2, the weed self-attention module WSA, and the second feature enhancement module CBS of the neck network Neck to obtain a feature map F31, connecting the feature map F31 after being up-sampled by an up-sampling module with the feature map F2 through a connection module Concat, and then processing through the second cross stage part CSP2, the weed self-attention module WSA, and the third feature enhancement module CBS of the neck network Neck to obtain a feature map F21, connecting the feature map F21 after being up-sampled by an up-sampling module with the feature map F1 through a connection module Concat, and then processing through the second cross stage part CSP2 to obtain a feature map F11; sending the feature map F11 to a first detection head of the prediction network Prediction after processing by a convolution module Conv, and processing the feature map F11 through the weed self-attention module WSA and the fourth feature enhancement module CBS of the neck network Neck to obtain a feature map F12, connecting the feature map F12 and the feature map F21 through a connection module Concat, and then processing through the second cross stage part CSP2 to obtain a feature map F22; sending the feature map F22 to a second detection head of the prediction network Prediction after processing by a convolution module Conv, and processing the feature map F22 through the weed self-attention module WSA and the fifth feature enhancement module CBS of the neck network Neck to obtain a feature map F32, connecting the feature map F32 and the feature map F31 through a connection module Concat, and then processing through the second cross stage part CSP2 to obtain a feature map F33; sending the feature map F33 to a third detection head of the prediction network Prediction after processing by a convolution module Conv, and processing the feature map F32 through the weed self-attention module WSA and the sixth feature enhancement module CBS of the neck network Neck to obtain a feature map F42, processing the feature map F21 through a convolution layer, processing the feature map F31 through a convolution layer, connecting the feature obtained after processing the feature map F11 and the feature map F21 through a convolution layer, the feature obtained after processing the feature map F31 through a convolution layer, and the feature map F42 through a connection module Concat, and then processing through the second cross stage part CSP2 to obtain a feature map F43; and sending the feature map F43 to a fourth detection head of the prediction network Prediction after processing by a convolution module Conv.

2. The substation weed detection method based on YOLOv5 and attention mechanism according to claim 1, characterized in that, The processing of the input feature by the feature enhancement module CBS includes sequentially passing the input feature through a convolution, batch normalization and SiLU activation function to obtain an output feature.

3. The substation weed detection method based on YOLOv5 and attention mechanism according to claim 2, characterized in that, The processing of the input feature by the second cross stage part CSP2 includes: dividing the input feature into two branches, one branch is processed by a feature enhancement module CBS, the other branch is processed by a plurality of cascaded feature enhancement modules CBS, then the features output by the two branches are connected by a connection module Concat, and then processed by a feature enhancement module CBS to obtain an output feature.

4. The substation weed detection method based on YOLOv5 and attention mechanism according to claim 1, characterized in that, The processing of the input grass detection image by the backbone network Backbone includes: sequentially passing the grass detection image through a focus module Focus, a feature enhancement module CBS and a first cross stage part CSP1 to obtain a feature map F1, passing the feature map F1 through a feature enhancement module CBS, a first cross stage part CSP1 to obtain a feature map F2, passing the feature map F2 through a feature enhancement module CBS, a first cross stage part CSP1 to obtain a feature map F3, and passing the feature map F3 through a feature enhancement module CBS and a spatial pyramid pooling module SPP to obtain a feature map F4.

5. The substation weed detection method based on YOLOv5 and attention mechanism according to claim 4, characterized in that, The processing of the input grass detection image by the focus module Focus includes: passing the grass detection image through a plurality of slice modules Slice respectively to obtain a plurality of slices, then connecting the plurality of slices by a connection module Concat, and then processing by a feature enhancement module CBS to obtain an output feature.

6. The substation weed detection method based on YOLOv5 and attention mechanism according to claim 4, characterized in that, The processing of the input feature by the spatial pyramid pooling module SPP includes: processing the input feature by a feature enhancement module CBS, then performing maximum pooling processing on the feature output by the feature enhancement module CBS by a plurality of maximum pooling modules, finally connecting all the maximum pooling processing results by a connection module Concat, and then processing by a feature enhancement module CBS to obtain an output feature.

7. The substation weed detection method based on YOLOv5 and attention mechanism according to claim 4, characterized in that, The processing of the input feature by the first cross stage part CSP1 includes: dividing the input feature into two branches, one branch is processed by a feature enhancement module CBS, the other branch is processed by a feature enhancement module CBS and a multi-level residual unit, then the features output by the two branches are connected by a connection module Concat, and then processed by a feature enhancement module CBS to obtain an output feature; the processing of the input feature by the residual unit includes: sequentially passing the input feature through two feature enhancement modules CBS, and then adding the input feature and the original input feature of the residual unit to obtain an output feature of the residual unit.

8. A substation weed detection system based on YOLOv5 and attention mechanism, comprising a microprocessor and a memory connected to each other, characterized in that, The microprocessor is programmed or configured to perform the power substation weed detection method based on YOLOv5 and attention mechanism in any one of claims 1-7.

9. A computer-readable storage medium having stored therein a computer program, characterized in that, The computer program is used for being programmed or configured by the microprocessor to perform the power substation weed detection method based on YOLOv5 and attention mechanism in any one of claims 1-7.

Citation Information

Patent Citations

  • New material floor defect target detection system based on improved YOLOv5 algorithm

    CN112990392A

  • Target feature extraction method based on cross-correlation self-attention mechanism

    CN115131551A