A transmission line cotter defect detection method based on improved YOLOv8
By improving the YOLOv8 model and combining image preprocessing, data augmentation, a small target detection head, a PSA module, and an MCA attention module, the problems of low accuracy and fine granularity in cotter pin detection are solved, achieving more efficient detection of cotter pin defects in transmission lines.
Patent Information
- Application Number
- CN202411895049.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-21
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2044-12-21
AI Technical Summary
Existing cotter pin defect detection methods are fast but low in accuracy for small target detection. While multi-stage cascaded algorithms are highly accurate, they are computationally complex and subject to scenario limitations, making it difficult to effectively detect fine-grained defects in cotter pins in transmission lines.
An improved YOLOv8 model is adopted, which increases the relative size of cotter pins in the image through image preprocessing and data augmentation. The model also introduces a small target detection head P2, a P-C2f module integrating PSA module and MCA attention module, optimizes the loss function, and improves feature extraction and detection accuracy.
It improves the detection accuracy and speed of cotter pin defects, especially the detection capability of small targets, enhances the model's ability to process fine-grained information, and improves detection accuracy and classification accuracy.
Smart Images

Figure CN119832212B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of target detection technology, specifically a method for detecting cotter pin defects in transmission lines based on an improved YOLOv8. Background Technology
[0002] Object detection aims to solve the problem of determining the category and location of objects. Traditional machine learning methods included HOG+SVM, but these have largely been replaced by deep learning models. Small object detection is challenging due to its limited pixel count, weak features, and difficulty in annotation. While multi-scale feature fusion and dataset augmentation can improve the efficiency of small object detection, their effectiveness is limited for cotter pin detection, and background information also negatively impacts its detection. Fine-grained identification and differentiation of similar subcategories is difficult. Methods include localization-based classification subnetworks, end-to-end feature encoding, and the use of auxiliary information. However, the first two methods have drawbacks such as high workload when used for cotter pin detection.
[0003] Current mainstream methods for cotter pin defect detection utilize deep learning, including single-stage and multi-stage cascaded detection algorithms. Single-stage algorithms, such as automatic detection models, focus on missing cotter pins and utilize YOLOv5 optimizations to improve speed and accuracy. However, single-stage algorithms are susceptible to interference from target size and deformation, and are prone to false positives or false negatives when dealing with small targets or complex backgrounds, exhibiting a fine-grained problem. Multi-stage cascaded algorithms first generate candidate regions using a region proposal network, followed by classification and regression, such as CSSAdet combined with an attention mechanism. Two-stage cascaded detectors and cascaded network-based methods have shown some effectiveness, but their applicability is limited by small cotter pin targets, fine-grained detection, and background interference, and they are also computationally complex and slow. Currently, each cotter pin defect detection algorithm has its shortcomings: single-stage detection is fast but has low accuracy, while multi-stage cascaded algorithms, although offering accuracy advantages, are limited by the specific scenarios they can be applied to.
[0004] In summary, there is an urgent need for a new technical solution based on the improved YOLOv8 to address the defects in cotter pins of transmission lines, in order to overcome the aforementioned technical problems. Summary of the Invention
[0005] The purpose of this application is to provide a method for detecting cotter pin defects in transmission lines based on an improved YOLOv8, so as to solve the technical problems mentioned in the background art.
[0006] To achieve the above objectives, this application discloses the following technical solution: a method for detecting cotter pin defects in transmission lines based on an improved YOLOv8, comprising:
[0007] Step 1: Perform image preprocessing and data augmentation; wherein, the image preprocessing is used to adjust the image size, and the data augmentation is used to increase the relative size of the cotter pin in the image;
[0008] Step 2: Construct the PMW-YOLOv8 model; wherein, the PMW-YOLOv8 model is used for the detection of cotter pin defects in transmission lines, and the PMW-YOLOv8 model includes at least a small target detection head P2, a P-C2f module integrating a PSA module, an MCA attention module and a WIOU loss function, and the MCA attention module is integrated in front of each detection head;
[0009] Step 3: Train the PMW-YOLOv8 model to extract image features of cotter pin defects;
[0010] Step 4: Fuse and enhance the image features to obtain the fused features;
[0011] Step 5: Store the fused features into the PMW-YOLOv8 model to complete the model construction, and run the PMW-YOLOv8 model to generate the detection results of cotter pin defects in transmission lines.
[0012] Preferably, step one specifically involves: adjusting the input image to a uniform preset size, dividing the resized image into several sub-images with equal pixel counts, and excluding sub-images without cotter pins based on a preset cropping overlap rate.
[0013] Preferably, the small target detection head P2 is positioned in front of the three detection heads P3 to P5 of different sizes in the original YOLOv8 model, and the operation of the small target detection head P2 is as follows:
[0014] After the C2f module of the original YOLOv8 model outputs a feature map of size 80×80×256, the feature map is upsampled to output a feature map of size 160×160×128. The 160×160×128 feature map is then fused with the shallow feature skip connections in the backbone network to generate a large-size feature map.
[0015] Preferably, the P-C2f module is:
[0016] By using the channel self-attention mechanism of PSA to compress information and the spatial self-attention mechanism of PSA to retain high-resolution information, the channel self-attention mechanism and the spatial self-attention mechanism are connected in series to obtain a complete PSA module. The PSA module is then integrated with the original C2f module to obtain the P-C2f module.
[0017] Preferably, the P-C2f module is used to replace part of the C2F module in the original YOLOv8.
[0018] Preferably, the MCA attention module receives the features extracted and processed by the backbone network, and performs modeling attention in the channel, width and height dimensions based on a preset three-branch architecture.
[0019] Preferably, the WIOU loss function is constructed based on the center point of the detection box, the center point of the target box, and the width and height of the joint region.
[0020] Preferably, the image feature extraction process includes:
[0021] The preprocessed image is input into the backbone network, and shallow and deep features are extracted based on the increase in the number of layers in the backbone network.
[0022] Preferably, the fusion process of the fusion feature includes:
[0023] The extracted shallow and deep features are then concatenated in the neck network.
[0024] The stitched features are enhanced by the P-C2f module and the MCA attention module, and then fed into the decoupled detection head for target box detection and classification recognition, respectively. Each detection head outputs feature maps at two scales: classification and regression. The feature maps from the four detection heads are stitched together to obtain the detection boxes. The detection boxes are then filtered and restored to the original image for detection.
[0025] Preferably, the process of generating detection results for cotter pin defects in transmission lines by running the PMW-YOLOv8 model specifically includes:
[0026] Acquire real-time images and execute steps one and five to perform cotter pin defect detection on transmission lines. The results of this detection include normal cotter pins, loose cotter pins, and missing cotter pins.
[0027] Beneficial Effects: This application presents an improved YOLOv8-based method for detecting cotter pin defects in transmission lines. Addressing the small target problem faced by existing cotter pin detection methods, the method segments high-resolution images into several sub-images during the model training data processing stage, increasing the relative size of the cotter pins within the image and improving detection accuracy. In the PMW-YOLOv8 model, a small target detection head is added, fully utilizing the edge information and detailed features of small targets to further enhance detection accuracy. An MCA attention module is integrated into the front end of each of the four target detection heads (P2-P5), further enhancing the extracted features and improving the model's ability to detect and classify small targets. To address the fine-grained problem in cotter pin detection, a P-C2f module is proposed based on the C2f module, incorporating a polarization self-attention mechanism (PSA) and integrating it into the model. This strengthens the model's extraction and processing of fine-grained information, improving the detection accuracy of fine-grained cotter pin targets. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 A flowchart illustrating the defect detection method for cotter pins in transmission lines based on the improved YOLOv8 provided in this application embodiment;
[0030] Figure 2 The structural block diagram of the PMW-YOLOv8 model provided in the embodiments of this application is shown. Detailed Implementation
[0031] The technical solutions in the embodiments of this application will be clearly and completely described below. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0032] In this document, the term "comprising" is intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0033] Cotter pins occupy a small proportion of images in routine inspections, and their defect morphology differs only slightly from their normal state, making defect detection a challenging task. This embodiment utilizes a cropping data augmentation method for small targets to increase their relative size. This method not only simulates the effect of target region selection in the initial stage of multi-stage detection but also limits its application to the data processing stage, ensuring that detection speed is not affected and effectively improving detection accuracy. Simultaneously, a PMW-YOLOv8 cotter pin detection model is constructed. This model uses the YOLOv8 model as its backbone network and incorporates an attention mechanism to enhance the network's focus on important target regions, addressing the low accuracy problem of single-stage detection algorithms. Furthermore, this embodiment optimizes the loss function to reduce the adverse effects of data quality fluctuations on the training process, thereby further improving the model's stability and performance.
[0034] This embodiment discloses, as follows: Figure 1The method for detecting cotter pin defects in transmission lines based on an improved YOLOv8, as shown, includes:
[0035] Step 1: Perform image preprocessing and data augmentation; image preprocessing is used to adjust the image size, and data augmentation is used to increase the relative size of the cotter pin in the image;
[0036] Step 2: Construct the PMW-YOLOv8 model; The PMW-YOLOv8 model is used for the detection of cotter pin defects in transmission lines. The PMW-YOLOv8 model includes at least a small target detection head P2, a P-C2f module with integrated PSA module, an MCA attention module and WIOU loss function, and the MCA attention module is integrated in front of each detection head.
[0037] Step 3: Train the PMW-YOLOv8 model to extract image features of cotter pin defects;
[0038] Step 4: Fuse and enhance image features to obtain fused features;
[0039] Step 5: Store the fused features into the PMW-YOLOv8 model to complete the model construction, and run the PMW-YOLOv8 model to generate the detection results of cotter pin defects in transmission lines.
[0040] This invention improves upon the YOLOv8 structure, proposing a new PMW-YOLOv8 model. The structure of the PMW-YOLOv8 model is as follows: Figure 2 As shown.
[0041] First, the input power line inspection images are preprocessed, and their size is adjusted to 640×640×3 to ensure that all images maintain the same size when input into the neural network. After the preprocessed images enter the backbone network, the backbone network, composed of convolutional layers, pooling layers, and activation functions, extracts image features. As the number of layers in the backbone network increases, deeper image features are extracted.
[0042] Subsequently, the extracted deep features and shallow features (such as...) Figure 2 In the first Concat step, the deep information of the Upsample layer is fused with the shallow information of the C2f layer. The concatenation operation in the Neck network achieves feature fusion, enhancing the model's detection performance for targets of different sizes. Finally, the fused features are enhanced by the P-C2f module and the MCA attention module and then fed into the decoupled detection heads for target box detection and classification. Each detection head outputs feature maps at two scales: classification and regression. The feature maps from the four detection heads are concatenated to obtain the model's detection boxes. After filtering, the detection boxes are restored to the original image to obtain the final detection result.
[0043] like Figure 2 As shown, to improve the model's ability to detect small targets, the improved model adds a small target detection head P2 to the YOLOv8 structure. This head receives shallower, larger feature maps, thus utilizing shallower image features. The contours of small targets are preserved in these shallower features, improving detection accuracy. Simultaneously, a new P-C2f module replaces the original C2f module. The P-C2f module is composed of a PSA module added to the original C2f structure. The PSA module can finely control feature information filtering and enhancement while effectively preventing information loss, thus handling the complex task of cotter pin defect detection and improving detection accuracy. To enhance the model's fine-grained detection capability for cotter pin defects, an MCA attention module is added to the small target detection head. The feature information extracted by the P-C2f module is fed into the MCA module. This module can fully extract the correlation between different dimensions and calibrate the attention weights generated in different dimensions, thereby extracting more refined features and further improving the detection and classification accuracy of small cotter pin targets.
[0044] Specifically, step one involves: adjusting the input image to a uniform preset size, dividing the resized image into several sub-images with equal pixel counts, and excluding sub-images without cotter pins based on a preset cropping overlap rate.
[0045] Specifically, the small target detection head P2 is positioned before the three detection heads P3 to P5 of different sizes in the original YOLOv8 model, and the operation of the small target detection head P2 is as follows:
[0046] After the C2f module of the original YOLOv8 model outputs a feature map of size 80×80×256, the feature map is upsampled to output a feature map of size 160×160×128. The 160×160×128 feature map is then fused with the shallow feature skip connections in the backbone network to generate a large-size feature map.
[0047] In this embodiment, the small target detection head P2 constitutes the small target detection layer. YOLOv8 is designed with three layers of feature mapping, using three detection heads of different sizes (i.e., P3-P5) for the detection of targets of different sizes. However, since the cotter pin targets on the transmission line are small, the deep features obtained after continuous downsampling contain less feature information about such small targets, which reduces the detection accuracy of the algorithm for cotter pin targets.
[0048] Therefore, in PMW-YOLOv8, based on the original YOLOv8 model architecture, a new small target detection head P2 and a corresponding detection layer are added. After the original model's C2f module outputs a feature map of size 80×80×256, this feature map is upsampled again to increase its size, resulting in a feature map of size 160×160×128. This feature map is then fused with the shallow feature skip connections in the backbone network to generate a large feature map containing richer small target feature information. Compared to the original three detection layers of YOLOv8, the newly added small target detection layer structure can cleverly fuse the shallower original features of the image with the features extracted and enhanced by the network depth. The resulting features therefore contain more shallow detail information, significantly improving the detection accuracy for small targets such as cotter pins and their defects, and to some extent making up for the model's performance shortcomings in small target detection.
[0049] Specifically, the P-C2f module is as follows:
[0050] By using the channel self-attention mechanism of PSA to compress information and the spatial self-attention mechanism of PSA to retain high-resolution information, the channel self-attention mechanism and the spatial self-attention mechanism are arranged in series to obtain a complete PSA module. The PSA module is then integrated with the original C2f module to obtain the P-C2f module.
[0051] In this embodiment, due to the diversity of cotter pin targets in inspection images, they exhibit high complexity in terms of size, shape, position, and angle. This results in the normal, loose, and missing forms having similar features, which reduces the model's classification accuracy for different categories. Although the C2f feature fusion module in YOLOv8 allows the model to simultaneously acquire contextual information and high-resolution details, it treats features at multiple scales and levels equally, maintaining a relatively similar level of attention to features at different scales. For the detection of cotter pin defect targets, most of the features presented by cotter pin targets are small in scale and have fine-grained characteristics, requiring special attention to shallow features and detailed features of the target. Therefore, this invention introduces a polarization self-attention mechanism on the basis of C2f, proposing a new P-C2f module.
[0052] The new P-C2f module first compresses information in one direction while retaining high-resolution information in the other. Then, it uses a non-linear method, Softmax-Sigmoid combination, to process the data, increase the dynamic range, fully utilize high-resolution information, improve the model's attention to important features and processing efficiency, thereby improving the model's detection accuracy. The PSA is divided into two parts: channel self-attention and spatial self-attention mechanism. The calculation process of the channel self-attention branch can be represented by equation (1):
[0053]
[0054] The computation process of the spatial self-attention branch is as follows:
[0055]
[0056] Among them, Wz, Wv and W q This is a standard 1×1 convolution (Conv), where θ1 is the intermediate parameter of the convolution, and σ1 and σ2 are matrix reshaping operators that transform matrices (or three-dimensional arrays) of shape 1×H×W and C / 2×H×W into matrices of shape HW×1×1 and C / 2×1, respectively. F SG and F SM These are the Sigmoid and Softmax operators, respectively, F GP It is a global pooling operator, and "×" is the dot product operation of the matrix. The two modules are connected in series to form a complete PSA attention module. The operation of the complete PSA attention module is as shown in equation (3). The feature vector processed by the channel attention branch is used as input to the spatial attention branch:
[0057] PSA s (X)=A sp (A ch (3)
[0058] This embodiment proposes a new P-C2f module by combining PSA and C2f, replacing part of the C2f module in YOLOv8. This enhances the model's feature representation capabilities and improves its detection accuracy. C2f is a two-branch structure. After generating an intermediate feature map of size H×W×C from the input via the CBS (Conv2d+batchNorm2d+Silu) module, the feature maps are split... Figure 1The features are split into two parts, each with a size of H×W×1 / 2C. One branch outputs directly to the final Concat block, while the other branch outputs directly to the Concat block and then undergoes further processing through multiple Botleneck blocks before being passed to the Concat block. Botleneck processing is a process of extracting deeper features from the image. In this process, the bottleneck module processes the features layer by layer to extract deeper features. PSA is added to the bottleneck, allowing it to participate in the entire layer-by-layer feature processing. The Softmax function in PSA transforms the input feature values into a probability distribution. This means that Softmax can make larger feature values more prominent while suppressing smaller feature values (unimportant channel features). By adjusting the weights of each channel, it enables the model to automatically focus on the most relevant channels and spatial information, highlighting key features in the global context and allowing important features to dominate in subsequent processing. This was verified in subsequent experiments.
[0059] The expression for PSA-Bottleneck is as shown in equation (4): X PSA-Bottleneck =PSA s (W 3×3 (W 3×3 (X)))+X (4)
[0060] Where X is the input of PSA-Bottleneck, X PSA-Bottleneck Its output, W 3×3 It is a 3×3 convolution, and the expression for P-C2f, which replaces Bottleneck with PSA-Bottleneck, is as shown in equation (5):
[0061]
[0062] in, This is the output of P-C2f. It is the input of C2f, W 1×1 It is a 1×1 convolution, X Split It is the part that is directly passed to the Concat block after the Split feature segmentation. It is a stack of n PSA-Bottlenecks.
[0063] Specifically, the P-C2f module replaces some of the C2F modules in the original YOLOv8.
[0064] Specifically, the MCA attention module receives the features extracted and processed by the backbone network, and performs modeling attention in the channel, width and height dimensions based on the preset three-branch architecture.
[0065] In this embodiment, to further improve the model's feature representation capability, as well as its detection accuracy and efficiency for small targets, an MCA attention module is added before each detection head of the YOLOv8 model. Figure 2 At positions 1, 2, 3, and 4, the features extracted and processed by the backbone network are fed into the MCA module to further enhance the image features, thereby improving the detection and classification capabilities of the detection head and reducing the false detection rate of the model.
[0066] MCA employs a three-branch architecture, with each branch responsible for modeling attention in the channel, width, and height dimensions, respectively. This embodiment uses the width W branch as an example; the entire process of this branch can be summarized by equation (6):
[0067]
[0068] The features that are input to the MCA are sent to each branch. In the first branch, PM H (*) indicates a 90° rotation along the H direction. This indicates that the characteristic matrix is rotated 90° clockwise along the H direction by (permute-1)°, T sq (*) indicates average pooling and standard pooling, T ex (*) is the activation transformation of a 1×K convolution kernel, F SG (*) is the Sigmoid function. This is matrix multiplication. Similarly, performing the same operation along the other height H direction in the spatial dimension yields F'. H The channel C is similar to the first two channels, but with two fewer rotation operations, resulting in F′. C Finally, the outputs of the three branches are simply averaged to obtain the feature map after optimization by different dimensional weights.
[0069] PMW-YOLOv8 integrates an MCA module before each detector head, enhancing the feature maps to be passed to the detector head and the next layer structure from both channel and spatial dimensions. This enhancement mechanism improves the representational power of small target features in the feature maps, ensuring that these fine-grained features are more significant in subsequent processing. Specifically, the MCA module is integrated after the P-C2f and C2f modules. Before the P-C2f and C2f modules, the Concat module receives the feature map from the previous layer and the shallow feature map passed through skip connections, concatenating them to fuse deep and shallow features. The fused feature map is then fed into the P-C2f and C2f modules, which further extract the input features.
[0070] The integrated MCA module enhances the feature weights of the target region on the feature maps output by the P-C2f and C2f modules, amplifying the response of small target features in both channel and spatial dimensions, ensuring that they do not lose saliency in deep networks, thereby improving the accuracy of small target detection. The mechanism of MCA in PM-YOLOv8 is shown in equation (7):
[0071]
[0072] Among them, F MCA F represents the output of MCA. C2f This represents the input to MCA, i.e., the output of C2f or P-C2f. The enhanced feature F after integration. MCA There are two processing paths: on the one hand, the enhanced features are directly passed to the corresponding detection head for classification and localization prediction of feature maps at different resolutions; on the other hand, these features are further downsampled, fused with deeper features, and then the deep detection head completes the target detection task. This optimization mechanism enables the model to more effectively highlight the features of the target region while suppressing irrelevant background interference, showing a significant advantage, especially in small target detection tasks.
[0073] Specifically, the WIOU loss function is constructed based on the center point of the detection box, the center point of the target box, and the width and height of the joint region.
[0074] In this embodiment, the loss function of Yolov8 is divided into classification and regression branches. The classification loss function is the BCE loss function, which helps the model correctly classify the detected targets. Its calculation is expressed by equation (8), where y i It is the true label of the sample, p i The predicted probability is the model's probability; the regression loss is a combination of CIOU and DFL (DistributionFocalLoss) loss functions, used to help the model locate the detected target.
[0075]
[0076] The DFL loss function is calculated as shown in equation (9), S i and S i+1 These are the model's predicted values and nearest-neighbor predicted values, y and y'. i y i+1 These are the neighboring label value, the predicted value, and the label value, respectively.
[0077] DFL(S i ,S i+1 )=-((y i+1 -y)log(S i )+(yy i )log(S i+1(9)
[0078] In the training dataset, some low-quality samples inevitably appear, such as those with low IOU between the anchor box and the target box, or those with low resolution between the target and the background. Geometric factors such as distance and aspect ratio in the CIOU used by YOLOv8 will aggravate the penalty for these low-quality samples, and the computational cost is also large. Therefore, the CIOU loss function used in YOLOv8 is partially replaced with the WIOU loss function. When the detection box and the target box match well, attention and intervention are reduced, the penalty of geometric factors is weakened, and the impact of low-quality samples on the generalization performance of the model is reduced, thereby improving the generalization ability of the model. The loss function of the improved model is shown in Equation (10):
[0079] Loss total =ηLoss BCE +μLoss DFL +γLoss WIOU (10)
[0080] In the formula, the three loss functions are derived by weighting the weights proportionally, and the hyperparameters η, β, and γ are the weights of the three loss functions. In this embodiment, η, μ, and γ are taken as 7.5, 0.5, and 1.5, respectively. WIOU The WIOU loss function is expressed as shown in equations (11) and (12):
[0081] Loss WIOU =rR WIOU L IOU (11)
[0082]
[0083] (x,y) and (x gt ,y gt ) are the center points of the detection box and the target box, respectively, while W g and H g L represents the width and height of the joint region. When the detection box fits the target box well, L... IOU A smaller R value can significantly reduce attention to detection boxes with good matching results. Conversely, when the presence of hard samples leads to poor detection box fit, R... WIoU The value is relatively small, which allows the model to focus on most ordinary samples during training, reducing attention to high-quality and low-quality samples and enhancing the model's generalization ability. The specific expression for parameter r is shown in (13).
[0084]
[0085] In equation (13), α and δ are hyperparameters. In this embodiment, α = 1.9 and δ = 3. β is a parameter that expresses the degree of matching between two boxes and is inversely proportional to the degree of matching. The specific expression of β is shown in equation (13). As shown, This is the moving average of the IOU loss. β can dynamically adjust the gradient based on the current matching degree between the two bounding boxes, making a gradient gain allocation strategy that best suits the current situation. This keeps the overall gradient descent speed at a high level, accelerating training and improving detection accuracy.
[0086] Specifically, the image feature extraction process includes:
[0087] The preprocessed image is input into the backbone network, and shallow and deep features are extracted based on the increase in the number of layers in the backbone network.
[0088] Specifically, the feature fusion process includes:
[0089] The extracted shallow and deep features are then concatenated in the neck network.
[0090] The concatenated features are enhanced by the P-C2f module and the MCA attention module, and then fed into the decoupled detection head for target box detection and classification, respectively. Each detection head outputs feature maps at two scales: classification and regression. The feature maps from the four detection heads are concatenated to obtain the detection boxes. The detection boxes are then filtered and restored to the original image for use in detection.
[0091] The specific improvements and algorithm flow of this embodiment compared to the original YOLOv8 model are as follows:
[0092] The first CBS layer consists of a convolutional module, a batch normalization module, and a Silu activation function. It is a common convolutional block structure with 64 channels and a kernel size of 3×3. It performs convolution operations on the input image. After passing through this convolutional layer, the number of image channels becomes 64, and the feature map is halved.
[0093] The second CBS layer performs convolution operations on the feature map, with 128 channels and a kernel size of 3×3. After passing through this convolution layer, the number of image channels is doubled, and the feature map is shrunk to half its original size.
[0094] The third layer C2f structure is as follows Figure 2 It shows that it fuses features at different scales, and the scale and number of channels of the feature maps remain unchanged before and after processing;
[0095] The subsequent fourth to ninth layers are arranged in the order of the second CBS layer and the third C2f layer. The CBS convolutional layer extracts features. Each time a CBS layer is passed, the size of the feature map is reduced to half of its original size, while the number of channels doubles.
[0096] The tenth layer is the SPPF layer, which performs pooling operations on the spatial pyramid structure to extract feature information of the target at different scales.
[0097] The eleventh layer, Upsample, is an upsampling layer that upsamples the feature map fed in from SPFF, doubling the size of the feature map but halving the number of channels, keeping the feature map size and number of channels consistent with the seventh layer, C2f.
[0098] The twelfth Concat layer performs a spatial dimension concatenation operation on the feature maps of the eleventh and seventh layers, thus fusing their features.
[0099] The thirteenth layer, P-C2f, was originally C2f. Building upon C2f, it integrates a PSA (Polarized Self-Attention) module. PSA performs deep encoding of global information, suppressing unimportant features while highlighting key features, thus enriching the hierarchy of feature representation while maintaining the same number of output channels as the original structure. After processing with P-C2f, the feature map size and number of channels remain unchanged.
[0100] like Figure 2 As shown, layers 14 to 19 of the model repeat the module order of layers 11 to 13 to process the feature map, but only layer 19 uses the P-C2f module, while layer 16 uses the native C2f module of the YOLOv8 model.
[0101] The twentieth layer introduces an MCA module, which can fully extract the correlation between different dimensions and calibrate the attention weights generated in different dimensions, thereby extracting more refined features and further improving the detection and classification accuracy of small targets such as cotter pins. Simultaneously, the feature map of this layer is fed into the P2 detection head, which has a feature map size of 160×160×128. This detection head locates and classifies the target based on the feature map, thus achieving target detection. Due to the large feature map size of this layer, it contains more target features and edge details, which is of great help in the detection of small targets.
[0102] The twenty-first CBS layer performs a convolution operation on the feature map, halving the feature map size and doubling the number of channels.
[0103] The 22nd layer performs a stitching operation on the feature map of the previous layer and the feature map of the 16th layer to fuse the features, while keeping the feature map size and number of channels unchanged.
[0104] The 23rd layer, C2f, fuses features at different scales, keeping the scale and number of channels of the feature maps unchanged before and after processing.
[0105] The twenty-fourth layer introduces the MCA module to enhance the feature map and sends the 80×80×256 feature map into the P3 target detection head;
[0106] Layers 25 through 32 process the feature maps in the order of CBS, Concat, C2f, and MCA. In layers 29 and 33, the 40×40×512 and 20×20×512 feature maps are sent to the P4 and P5 detection heads, respectively.
[0107] The feature map sizes received by the P2-5 detection heads decrease sequentially. After all the detection heads predict the location and classify the target, each detection head will output feature maps at two scales: classification and regression. The feature maps of the four detection heads are stitched together to obtain the detection box of the model. The detection box is then filtered and restored to the original image to obtain the final detection result.
[0108] Specifically, the PMW-YOLOv8 model is used to generate detection results for cotter pin defects in transmission lines, as follows:
[0109] Acquire real-time images and perform steps one and five to detect cotter pin defects in transmission lines. The results of this detection include normal cotter pins, loose cotter pins, and missing cotter pins.
[0110] As a comparative example of this embodiment, to evaluate the effectiveness of the proposed method, experiments were conducted on a transmission line cotter pin defect dataset. This dataset was provided by a power supply bureau in Yunnan Province and, after screening and organization, contained 4218 inspection images suitable for this task. The images included power transmission line scenes under different environments, weather conditions, and angles collected during inspections, which can effectively ensure the generalization performance of the model. The labeled targets included three categories: normal, loose, and missing cotter pins. Among them, since the proportion of loose and missing cotter pins in normal transmission lines is small, the sample imbalance between defective and normal cotter pins is extremely severe. To solve this problem, data augmentation was performed on the images containing defective cotter pins using methods such as inversion, skewing, and adding noise. The final dataset reached 9108 images, which were divided into training, validation, and test sets in a 6:2:2 ratio.
[0111] To evaluate the proposed improved PMW-YOLOv8 model, this invention selects precision (P), recall (R), and mean average precision (mAP@0.5) as core evaluation metrics. These metrics not only independently reflect different aspects of the model's capabilities in the detection task, but also complement each other, together forming a comprehensive evaluation system for the model's performance.
[0112] I. Dataset
[0113] The dataset for this experiment was provided by a power supply bureau in Yunnan Province. After screening and organization, a total of 4218 inspection images suitable for this task were collected. These images include power transmission line scenes under different environments, weather conditions, and angles during inspections, which can effectively ensure the generalization performance of the model. The labeled targets include three categories: normal, loose, and missing cotter pins. Among them, since the proportion of loose and missing cotter pins in normal transmission lines is small, the sample is extremely imbalanced between defective and normal cotter pins. To solve this problem, data augmentation was performed on the images containing defective cotter pins using methods such as inversion, skewing, and adding noise. The final dataset reached 9108 images, which were divided into training, validation, and test sets in a 6:2:2 ratio.
[0114] Cotter pins are inherently small, and standard power line inspection images often have very high resolutions due to the need for detailed observation of numerous power components. This high-resolution processing further reduces the relative size of the cotter pins in the image, undoubtedly increasing the difficulty of accurately detecting cotter pin defects. To overcome this challenge, specific image processing methods were employed during model training. Specifically, the high-resolution inspection image was divided into several small sub-images. To fit the model's input, the size of the cropped sub-images was set to 640×640 pixels, with a 20% cropping overlap rate. The relative size of all target boxes was less than 20% of the image area, with most being less than 5%. Therefore, the 20% cropping overlap rate avoids incomplete targets due to cropping. On the other hand, sub-images without targets in the training set were directly excluded to improve training efficiency.
[0115] In the image slicing operation, the number of sub-images for each image is as follows:
[0116] N = N w +N h (15)
[0117]
[0118]
[0119] Where, N w and N h These represent the number of subimages in the horizontal and vertical directions of the image, respectively. W and H are the width and length of the image in pixels, respectively, while P... w and P h The pixel width and pixel length of the subimage, and α and β are the subimage overlap ratios in the horizontal and vertical directions, respectively. This indicates rounding down to the nearest integer.
[0120] After cropping, the number of sub-images in the training, validation, and test sets are 12977, 4217, and 4203, respectively. Although small targets still constitute the majority of the dataset after cropping, their relative size has increased significantly, which is beneficial for detecting cotter pin defects.
[0121] Training and testing were conducted on datasets before and after slicing, and the results are shown in Table 1. All performance metrics showed significant improvements, with accuracy and recall increasing by 6.57% and 14.36%, respectively. The mAP@0.5 for the three classes improved by 15.08%, 5.72%, and 16.41%, respectively, indicating that the method significantly improves performance across different classes. Furthermore, the overall mAP@0.5 improved by 13.60%, further validating the universality of the performance improvement effect of slicing on the dataset. In a broader performance evaluation range, the mAP@0.5–0.95 performance metric improved by 10.98%. This result not only demonstrates the effectiveness of slicing in improving model performance but also further proves the stability and reliability of the method under different thresholds.
[0122]
[0123] Table 1
[0124] II. Model Improvement Ablation Experiment
[0125] To explore the effectiveness of model improvement measures and the independence of each module's contribution to model performance, a series of ablation experiments were conducted. The model performance was quantitatively evaluated and compared by progressively integrating the P2 detector head, the P-C2f module, the MCA module, and employing the WIOU loss function. A unified training strategy and hyperparameter configuration were used in all experiments to ensure the academic rigor and reproducibility of the results. The experimental results (as shown in Table 2) clearly demonstrate the positive impact of each improvement step on model performance. After adding the small target detector head P2, the model's accuracy improved by 1.24%, with accuracy for loose cotter pins and missing cotter pins increasing to 2.83% and 0.21%, respectively. mAP@0.5 improved by 0.54%. The introduction of the P-C2f module significantly improved the model's mAP@0.5 by 1.14 percentage points, and the overall accuracy also slightly improved (0.04%). Particularly noteworthy were the significant increases in accuracy for identifying loose and missing cotter pins, achieving increases of 1.21% and 2.50%, respectively. This result strongly supports the effectiveness of polarization self-attention mechanisms in enhancing the model's feature representation capabilities.
[0126]
[0127] Table 2
[0128] Subsequently, after integrating the MCA module based on the P-C2f module, the model performance was significantly improved again. The mAP@0.5 metric improved by 1.84 percentage points, and the overall accuracy also increased slightly (0.03%), especially in the tasks of recognizing loose and missing cotter pins, where the accuracy increased by 1.80% and 0.59%, respectively. This result shows that the introduction of the MCA module effectively enhances the model's ability to handle complex scenes and capture multi-dimensional contextual information.
[0129] Finally, the model achieved optimal performance when trained using the WIOU loss function. The mAP@0.5 metric reached 66.34%, a 3.07 percentage point improvement over the baseline network, while other key performance indicators also showed significant improvements. This result not only verifies the effectiveness of the WIOU loss function in optimizing model training but also comprehensively demonstrates the significant effect of our model improvement strategy in enhancing overall model performance.
[0130] (1) Validation of the MCA module
[0131] To fully verify the effectiveness and superiority of the MCA attention module in model optimization, several classic attention modules, such as GAM, CA, and CBAM, were selected and compared with the MCA module in comparative experiments. The results, as shown in Table 3, are obtained by comparing the detection performance. The data in the table clearly shows that the model incorporating the MCA module achieves optimal performance in key metrics such as accuracy and mAP@0.5. Specifically, compared to the baseline model, the accuracy of the model significantly improved by 1.74%, and the recall also improved by 2.39% after introducing the MCA module.
[0132]
[0133] Table 3
[0134] Further analysis revealed that the inclusion of the MCA module significantly improved performance in tasks targeting specific defect categories (such as loose cotter pins and missing cotter pins). Specifically, the mAP@0.5 for loose cotter pin defects improved by 3.82%, while the mAP@0.5 for missing cotter pin defects also saw a 1.39% increase. This demonstrates the MCA module's strong targeted optimization capabilities for subtle yet crucial detection tasks. Furthermore, the overall model mAP@0.5 improved by 1.53%, a comprehensive performance enhancement that fully validates the core value and outstanding effectiveness of the MCA module in model optimization. This series of improvements fully demonstrates the effectiveness of the MCA module in model optimization.
[0135] (2) Validation of the MCA module location
[0136] To further explore the rationality of the optimal insertion position of the MCA module in the model, four sets of control experiments were designed (see Table 4), labeled as groups a, b, c, and d, each representing a different application strategy of the MCA module. Group d represents the scheme ultimately adopted in this study. In Table 4, numbers 1, 2, 3, and 4 correspond to four potential MCA module insertion points, and a "√" mark indicates that the MCA module was introduced at that position. Specifically, scheme d... Figure 2 All four locations shown integrate the MCA module, enabling comprehensive feature enhancement.
[0137]
[0138] The experimental results are summarized in Table 5. Through comparative analysis, it can be observed that compared with the three groups of experiments a, b, and c, the model using scheme d achieved significant advantages in several key performance indicators. These indicators include overall accuracy, mAP@0.5 for cotter pin loosening and missing defects, overall mAP@0.5, and a more comprehensive evaluation of the mAP@0.5 to 0.95 range. Scheme d demonstrated the best performance in these aspects, which not only confirmed the rationality of selecting the MCA module insertion position in the model, but also further demonstrated the effectiveness of this scheme in improving detection accuracy and robustness.
[0139]
[0140] Table 5
[0141] III. Comparative Experiment
[0142] To comprehensively evaluate the performance of the PMW-YOLOv8 algorithm in the cotter pin defect detection task, a series of classic and current state-of-the-art target detection algorithms were selected, including but not limited to the classic YOLO series networks, the anchorless algorithm CenterNet, the two-stage algorithm Faster-RCNN, and some other currently advanced algorithms.
[0143] The model was evaluated by comparing the accuracy of each category and the overall average accuracy. The experimental results are shown in Table 6. The results show that compared with the Faster-RCNN model, YOLOv5 series models, SSD model, YOLOX model, YOLOv7 model, and YOLOX model, PMW-YOLOv8 exhibits relatively better performance in terms of P, R, and mAP@0.5 for different types of cotter pin defects. Among them, P, R, AP for loose and missing cotter pins, overall mAP@0.5, and mAP0.5–0.95 all achieve the best performance among many detection models. It is worth mentioning that in the key indicator of mAP@0.5, PMW-YOLOv8 improves by 3.07% compared with the native YOLOv8 model, and even compared with TPH-YOLOv5, which performs the best among all comparison models, it still achieves an improvement of 3.24%. Furthermore, while the addition of an extra attention module in the model sacrifices some detection speed, it still maintains a certain advantage in detecting defects compared to the two-stage model. Therefore, the proposed PMW-YOLOv8 model achieves good detection performance on the cotter pin defect dataset, creating favorable conditions for intelligent inspection of cotter pin defects in power line inspection.
[0144]
[0145] Table 6
[0146] In summary, the transmission line cotter pin defect detection method based on the improved YOLOv8 in this embodiment addresses the small target problem faced by existing cotter pin detection methods. During the data processing stage of model training, the high-resolution image is segmented into several sub-images, increasing the relative size of the cotter pin in the image and improving the detection accuracy. In the PMW-YOLOv8 model, a small target detection head is added, fully utilizing the edge information and detailed features of small targets to improve detection accuracy. An MCA attention module is integrated into the front end of each of the four target detection heads (P2-P5) to further enhance the extracted features, thereby improving the model's ability to detect and classify small targets. To address the fine-grained problem in cotter pin detection, a P-C2f module is proposed based on the C2f module, incorporating a polarization self-attention mechanism (PSA) and integrating it into the model. This strengthens the model's extraction and processing of fine-grained information, improving the detection accuracy of fine-grained cotter pin targets.
[0147] In the embodiments provided in this application, it should be understood that the embodiments described herein can be implemented in hardware, software, firmware, middleware, code, or any suitable combination thereof. For hardware implementation, the processor may be implemented in one or more of the following: application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), processors, controllers, microcontrollers, microprocessors, other electronic units designed to implement the functions described herein, or combinations thereof. For software implementation, some or all of the processes of the embodiments may be performed by a computer program instructing the associated hardware. During implementation, the program may be stored in a computer-readable storage medium or transmitted as one or more instructions or code on a computer-readable storage medium. Computer-readable storage media include computer storage media and communication media, wherein communication media include any medium that facilitates the transmission of a computer program from one place to another. Storage media may be any available medium accessible to a computer. Computer-readable storage media may include, but are not limited to, RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code having the form of instructions or data structures and accessible to a computer.
[0148] Finally, it should be noted that the above description is only a preferred embodiment of this application and is not intended to limit this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for detecting cotter pin defects in transmission lines based on an improved YOLOv8, characterized in that, include: Step 1: Perform image preprocessing and data augmentation; wherein, the image preprocessing is used to adjust the image size, and the data augmentation is used to increase the relative size of the cotter pin in the image; Step 2: Construct the PMW-YOLOv8 model; wherein, the PMW-YOLOv8 model is used for the detection of cotter pin defects in transmission lines, and the PMW-YOLOv8 model includes at least a small target detection head P2, a P-C2f module integrating a PSA module, an MCA attention module and a WIOU loss function, and the MCA attention module is integrated in front of each detection head; Step 3: Train the PMW-YOLOv8 model to extract image features of cotter pin defects; Step 4: Fuse and enhance the image features to obtain fused features; Step 5: Store the fused features into the PMW-YOLOv8 model to complete model construction, and run the PMW-YOLOv8 model to generate detection results for cotter pin defects in transmission lines; The first step specifically involves: adjusting the input image to a uniform preset size, dividing the resized image into several sub-images with equal pixel counts, and excluding sub-images without cotter pins based on a preset cropping overlap rate. The small target detection head P2 is set in front of the three detection heads P3 to P5 of different sizes in the original YOLOv8 model. The operation of the small target detection head P2 is as follows: after the C2f module of the original YOLOv8 model outputs a feature map with a size of 80×80×256, the feature map is upsampled to output a feature map with a size of 160×160×128. The 160×160×128 feature map is then fused with the shallow feature skip connections in the backbone network to generate a large-size feature map. The P-C2f module is specifically designed as follows: information is compressed using the channel self-attention mechanism of PSA, and high-resolution information is preserved using the spatial self-attention mechanism of PSA. The channel self-attention mechanism and the spatial self-attention mechanism are connected in series to obtain a complete PSA module. The PSA module is then integrated with the original C2f module to obtain the P-C2f module. The P-C2f module is used to replace part of the C2F module in the original YOLOv8. The MCA attention module receives features extracted and processed by the backbone network, and performs modeling attention in the channel, width and height dimensions based on a preset three-branch architecture. The WIOU loss function is constructed based on the center point of the detection box, the center point of the target box, and the width and height of the joint region.
2. The method for detecting cotter pin defects in transmission lines based on improved YOLOv8 according to claim 1, characterized in that, The image feature extraction process includes: The preprocessed image is input into the backbone network, and shallow and deep features are extracted based on the increase in the number of layers in the backbone network.
3. The method for detecting cotter pin defects in transmission lines based on improved YOLOv8 according to claim 2, characterized in that, The fusion process of the fusion features includes: The extracted shallow and deep features are then concatenated in the neck network. The stitched features are enhanced by the P-C2f module and the MCA attention module, and then fed into the decoupled detection head for target box detection and classification recognition, respectively. Each detection head outputs feature maps at two scales: classification and regression. The feature maps from the four detection heads are stitched together to obtain the detection boxes. The detection boxes are then filtered and restored to the original image for detection.
4. The method for detecting cotter pin defects in transmission lines based on improved YOLOv8 according to claim 3, characterized in that, The process of generating detection results for cotter pin defects in transmission lines by running the PMW-YOLOv8 model specifically includes: Real-time images are acquired and steps one and five are performed to detect cotter pin defects in transmission lines. The results of the detection include normal cotter pins, loose cotter pins, and missing cotter pins.
Citation Information
Patent Citations
PCB small target defect detection optimization method based on YOLOv8s
CN118691577A
Method and system for machine vision detection
US11151405B1