Insulator defect detection method based on improved YOLOv5
By introducing the ECA attention mechanism into the backbone network C3 module of YOLOv5 and combining the adaptive spatial feature fusion module, the problem of YOLOv5's recognition accuracy decreased in complex backgrounds is solved, and higher detection accuracy and robustness are achieved.
Patent Information
- Application Number
- CN202411724888.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-03-21
AI Technical Summary
The existing YOLOv5 algorithm is difficult to effectively distinguish between targets and background features in complex backgrounds, resulting in a decrease in recognition accuracy, especially when dealing with small targets or special angles, the detection effect is poor.
By introducing the ECA attention mechanism into the backbone network C3 module of YOLOv5, the features in the channel dimension are weighted and calculated, combining the detection head and the adaptive spatial feature fusion module to make full use of feature information of different scales.
It significantly improves the accuracy and robustness of insulator defect detection, improves the model's detection ability of small targets and special angles, and enhances the adaptability to complex backgrounds.
Smart Images

Figure CN119671962A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer vision target detection, and in particular to an insulator defect detection method based on improved YOLOv5. Background Art
[0002] Insulator status detection and safety protection play a vital role in ensuring the normal operation of transmission lines. In order to improve the detection efficiency of insulators, drone inspection has replaced manual inspection and become the mainstream inspection method. Due to the large number of pictures collected by drones and the complex background in the images, there are great differences in the size of insulators. If manual interpretation is used, it is very likely to cause false detection and missed detection. The relevant detection algorithms can be roughly divided into two categories: traditional image processing methods and deep learning methods. Although insulators can be identified based on traditional image processing detection methods, their generalization and robustness are poor, and the recognition accuracy is also low; methods based on deep learning can improve detection accuracy or accurately locate defects, but the model is relatively complex and it is difficult to meet the speed and accuracy requirements at the same time.
[0003] With the rapid development of computer graphics processing technology, insulator detection methods based on visual images have made significant progress. The core of these methods is to extract key features from images and then detect and classify insulators. Deep learning, as a technology that imitates the working principle of the human brain, has shown superior performance in this field with its powerful feature extraction capabilities. Among them, the YOLO (You Only Look Once) series of algorithms, as a representative of real-time target detection, are widely used in the detection and classification of insulators.
[0004] YOLOv2 is an important version in the YOLO series. It significantly improves the detection performance by introducing a series of improvements, such as batch normalization, high-resolution classifiers, and anchor boxes. However, due to the limitation of its fixed grid size, YOLOv2 still faces certain difficulties in detecting small objects. This is mainly because small objects occupy fewer pixels in the image and are difficult to be effectively captured by a fixed-size grid.
[0005] To overcome this limitation, YOLOv3 was born. YOLOv3 significantly improves the accuracy in the field of insulator target detection by introducing variable network size and aspect ratio features, as well as multi-scale prediction. These improvements enable YOLOv3 to better adapt to insulators of different sizes and shapes, thereby improving detection accuracy. However, YOLOv3 also has certain limitations, namely that its weights cannot be learned independently. This means that during the training process, weights at different levels may interfere with each other, affecting the final detection effect.
[0006] To further improve the detection performance, YOLOv4 has made a number of innovations. It implements multiple detection heads and anchor box clustering to enhance the overall detection performance. At the same time, YOLOv4 also replaces the backbone network with more advanced algorithms (such as CSPNet, etc.) to improve the efficiency of the insulator defect detection algorithm. These improvements have enabled YOLOv4 to achieve significant improvements in both detection speed and accuracy.
[0007] However, even with YOLOv5, the insulator defect detection algorithm still faces some challenges. YOLOv5 reduces network parameters and improves detection speed by introducing a new residual module. However, this sacrifices network accuracy to a certain extent. In complex backgrounds, YOLOv5 may find it difficult to effectively distinguish between target and background features, resulting in reduced recognition accuracy. This is mainly because interference factors in complex backgrounds (such as textures, colors, or shapes similar to the target) may cause the target to be occluded or confused with the background, thereby increasing the risk of false detection and missed detection.
[0008] In addition, the size, angle, and perspective of the target may also affect the detection effect. The algorithm may face greater challenges when dealing with small targets or special angles. This is because small targets occupy fewer pixels in the image, and special angles may cause the shape and texture of the target to change, thus increasing the difficulty of detection.
[0009] Finally, the contrast between the target and the background is also an important factor affecting the detection effect. When the contrast is low, the target becomes less obvious in the image, which also weakens the feature extraction ability of the YOLOv5 insulator defect detection algorithm. Therefore, in practical applications, we need to select appropriate algorithm parameters and preprocessing methods according to specific scenarios and requirements to improve the accuracy and robustness of detection.
[0010] In view of the complex background of power lines and the large differences in the scales of targets to be detected, insulator status detection urgently needs to develop an insulator defect detection method based on improved YOLOv5 to improve the accuracy and robustness of detection, effectively improve the accuracy and reliability of insulator status detection, and ensure the normal operation of transmission lines. Summary of the invention
[0011] The present invention aims to address the technical defects of the prior art and provide an insulator defect detection method based on improved YOLOv5. The method is improved based on the YOLOv5 algorithm. The ECA attention mechanism is introduced into the C3 module of the backbone network, and the features in the channel dimension are weightedly calculated to improve the feature extraction ability of the algorithm. The detection head of YOLOv5 is combined with the adaptive spatial feature fusion module, and the feature information of different scales is fully utilized to improve the detection accuracy of the algorithm, thereby improving the accuracy and robustness of the detection.
[0012] The present invention provides the following technical solution: an insulator defect detection method based on improved YOLOv5, the method comprising the following steps:
[0013] Step 1: Obtain insulator defect images, perform data preprocessing on the collected insulator defect images, and create a data set;
[0014] Step 2: Randomly divide the set into three parts: training set, test set and validation set according to the proportion;
[0015] Step 3: Reconstruct the improved YOLOv5 network;
[0016] Step 3-1: YOLOv5 includes a trunk, a neck, and a detection output. The trunk uses CSPDarknet as the trunk to extract features. The ECA attention mechanism is introduced in the C3 module of the trunk to perform weighted calculation on the features in the channel dimension.
[0017] Step 3-2: The neck adopts the feature pyramid structure of FPN and PAN to perform feature fusion;
[0018] Step 3-3: The detection head in the detection output is combined with the adaptive spatial feature fusion module to adaptively adjust the weights when fusion of feature maps of different scales;
[0019] Step 4: Use the data set in step 2 as the input of the improved YOLOv5 network in step 3 to perform network training;
[0020] Step 5: Input the image of the insulator to be tested into the improved YOLOv5 network model to obtain the detection results and target location information of the insulator and its defects.
[0021] Preferably, in step 1, the data preprocessing uses Mosaic and Mixup to perform joint image enhancement.
[0022] Preferably, in step 3-1, the feature map is input into the ECA attention mechanism and first undergoes a global average pooling operation, and then the correlation between channels is captured by a one-dimensional convolution with a convolution kernel size of k. The output of the one-dimensional convolution is converted into the attention weight corresponding to each feature channel through a Sigmoid activation function. Finally, the element of each channel in the input feature map is element-wise multiplied with the corresponding attention weight to obtain the feature map output by the ECA attention mechanism.
[0023] Preferably, the convolution kernel size k of the one-dimensional convolution in the ECA attention mechanism and the number of channels C of the feature map are calculated as shown in formula (1):
[0024]
[0025] ,In formula (1), C represents the number of channels of the feature map, γ and b are adjustable parameters, |t| odd represents the odd number closest to t.
[0026] Preferably, the adaptive spatial feature fusion formula in step 3-3 is expressed as formula (2):
[0027]
[0028] , in formula (2), Represents the fusion feature y l The eigenvector at position (i,j), and Represents the eigenvectors and The weights in adaptive fusion are calculated as shown in equations (3), (4) and (5) respectively:
[0029]
[0030]
[0031] In the formula, and and parameter and Obtained through adaptive learning.
[0032] Preferably, the Mosaic and Mixup are used for joint image enhancement, and the calculation method is as shown in formula (6) and formula (7):
[0033] mix_batch x =λ×batch x1 +(1-λ)×batch x2 (6)
[0034] min_batch y =λ×batch y1 +(1-λ)×batch y2 (7)
[0035] , where batch x1 is a batch sample, batch y1 is the label corresponding to one batch of samples; is the label corresponding to another batch y2 The samples of a batch are the labels corresponding to the samples of another batch; λ is the parameter, which is the mixing coefficient calculated by Beta distribution, and its calculation formula is formula (8):
[0036] λ=B(α,β) (8)
[0037] , where α is the proportion of data enhanced by the Mosaic method, and β is the proportion of data enhanced by the Mixup method.
[0038] Preferably, the feature maps output by the three levels in the neck network in step 3-2 have different sizes and numbers of channels, which are 1 / 8, 1 / 16 and 1 / 32 of the original image, respectively. The shapes of the feature maps are adjusted through upsampling and downsampling operations to ensure that they have the same size and number of channels, so that weighted fusion can be performed in the adaptive fusion step.
[0039] Preferably, upsampling: first use 1×1 convolution to adjust the number of channels of the feature map, and then adjust the size through the interpolation algorithm, the calculation formula is formula (9):
[0040] F up =Interp(Conv 1×1 (Fi),H target ,W target ) (9)
[0041] , where i is the level of the feature map, H target and W target is the size of the target feature map;
[0042] For 1 / 2 times downsampling: use 3×3 convolution with a stride of 2, and adjust the size and number of channels of the feature map at the same time. The calculation formula is as follows:
[0043]
[0044] , where i is the level of the feature map, Conv 3×3 Represents a 3×3 convolution operation with a stride of 2;
[0045] For 1 / 4 times downsampling: first perform pooling on the feature map, then perform a 3×3 convolution with a stride of 2, and adjust the size and number of channels of the feature map. The calculation formula is (11):
[0046]
[0047] , where i is the level of the feature map, Conv 3×3 Represents a 3×3 convolution operation with a step size of 2, and MaxPool represents a pooling operation;
[0048] After the feature map size and channel number are adjusted, adaptive fusion is performed, and the calculation formula is as follows:
[0049] F out=Sigmoid(w1·F1+w2·F2+w3·F3) (12)
[0050] , in formula (12), w i is the adaptive weight, F i is the adjusted feature map.
[0051] Preferably, in step 2, the setting ratio of the training set, test set and validation set is 8:1:1.
[0052] Preferably, the improved YOLOv5 network model after training adopts the accuracy performance index and the speed performance index to quantitatively evaluate the detection performance of the model, and the accuracy performance index adopts mAP, including mAP@0.5 and mAP@0.5:0.95, wherein the mAP calculation method is shown in formula (13):
[0053]
[0054] , where N is the number of categories of the detected target, AP is the average accuracy of category i, and the calculation method of AP is shown in formula (14):
[0055]
[0056] , in formula (14), P and R are used to represent the precision and recall rate of detection category i respectively. The calculation methods of P and R are shown in formula (15) and formula (16) respectively:
[0057]
[0058] ,In formula (15)(16), TP represents the number of positive examples correctly identified, FP represents the number of negative examples incorrectly identified as positive examples, and FN represents the number of positive examples incorrectly identified as negative examples;
[0059] The speed performance index adopts FPS, and the FPS calculation method is shown in formula (17):
[0060] FPS=N / T (17)
[0061] , where N represents the total number of frames and T represents the total time.
[0062] Compared with the prior art, the present invention has the following beneficial effects:
[0063] In the above technical solution, an insulator defect detection method based on improved YOLOv5 is provided, the method comprising the following steps:
[0064] Step 1: Obtain insulator defect images, perform data preprocessing on the collected insulator defect images, and create a data set;
[0065] Step 2: Randomly divide the set into three parts: training set, test set and validation set according to the proportion;
[0066] Step 3: Reconstruct the improved YOLOv5 network;
[0067] Step 3-1: YOLOv5 includes a trunk, a neck, and a detection output. The trunk uses CSPDarknet as the trunk to extract features. The ECA attention mechanism is introduced in the C3 module of the trunk to perform weighted calculation on the features in the channel dimension.
[0068] Step 3-2: The neck adopts the feature pyramid structure of FPN and PAN to perform feature fusion;
[0069] Step 3-3: The detection head 7 in the detection output is combined with the adaptive spatial feature fusion module to adaptively adjust the weights when fusion of feature maps of different scales;
[0070] Step 4: Use the data set in step 2 as the input of the improved YOLOv5 network in step 3 to perform network training;
[0071] Step 5: Input the image of the insulator to be tested into the improved YOLOv5 network model to obtain the detection results and target location information of the insulator and its defects;
[0072] The present invention discloses an insulator defect detection method based on improved YOLOv5, which significantly improves the accuracy and robustness of insulator defect detection through a series of innovative improvements;
[0073] 1. Improvement of feature extraction capabilities:
[0074] The Efficient Channel Attention (ECA) mechanism is introduced in the backbone network of YOLOv5, especially in the C3 module. This mechanism performs weighted calculation on the features in the channel dimension, so that the model can pay more attention to the feature information that is more critical to the detection task. This weighted calculation not only enhances the model's sensitivity to important features, but also suppresses the influence of redundant or noisy information, thereby significantly improving the quality of feature extraction.
[0075] 2. Optimization of feature fusion:
[0076] The neck network uses a feature pyramid structure that combines FPN (Feature Pyramid Network) and PAN (Path Aggregation Network). This structure can effectively fuse feature information of different scales, allowing the model to capture global and local feature details at the same time, which is particularly important for insulator defect detection, because defects may appear in different parts of the insulator, with different sizes and shapes. By optimizing feature fusion, the model can more accurately locate and identify these defects.
[0077] 3. Improvement of detection accuracy:
[0078] This method combines the detection head of YOLOv5 with an adaptive spatial feature fusion module. This module can adaptively adjust the weights during fusion according to the characteristics of feature maps of different scales, thereby making full use of feature information of different scales. This adaptive adjustment not only improves the model's sensitivity to changes in target scale and position, but also enhances the model's adaptability to complex backgrounds. Therefore, this method has achieved significant improvements in detection accuracy, especially when dealing with small targets or insulator defects at special angles.
[0079] 4. Improved accuracy and robustness:
[0080] Through the above improvements, the method has shown higher accuracy and robustness in the insulator defect detection task. In terms of accuracy, the model can more accurately identify the location and type of insulators and their defects; in terms of robustness, the model is more adaptable to interference factors such as illumination changes, occlusion, and noise, and can maintain stable detection performance in various complex scenarios.
[0081] 5. Improvement of practical application value:
[0082] This method not only improves the accuracy and robustness of insulator defect detection, but also has important practical application value. For example, in power inspection, this method can help inspectors quickly and accurately find defects on insulators, so that they can take timely measures to repair or replace them to ensure the safe and stable operation of the power system. In addition, this method can also provide useful reference and reference for other similar target detection tasks.
[0083] In summary, the insulator defect detection method based on improved YOLOv5 has achieved significant improvements in feature extraction, feature fusion, detection accuracy, accuracy and robustness. It can more accurately locate and identify detection targets, and further improve the detection performance of transmission line insulator defects in complex algorithm environments. It has important practical application value and promotion significance. BRIEF DESCRIPTION OF THE DRAWINGS
[0084] Figure 1 is an algorithm structure diagram of an embodiment of the present invention;
[0085] Figure 2 for Figure 1 The C3 module is embedded in the ECA attention mechanism structure diagram;
[0086] Figure 3 This is the structure diagram of the ECA attention mechanism;
[0087] Figure 4 The structural diagram of the detection head combined with the adaptive spatial feature fusion module. DETAILED DESCRIPTION
[0088] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. All other embodiments obtained by ordinary technicians in the field without making creative work based on the embodiments of the present invention shall fall within the scope of protection of the present invention.
[0089] like Figures 1 to 4 As shown, it shows a specific embodiment of the present invention:
[0090] The present invention is improved based on the YOLOv5 algorithm, which has three main beneficial effects:
[0091] First, the present invention uses Mosaic+Mixup to perform data enhancement, increase data diversity, and improve the robustness and generalization ability of the algorithm;
[0092] Second, the present invention is based on the improvement of the YOLOv5 algorithm. By introducing the ECA attention mechanism in the C3 module of the backbone network, the features in the channel dimension are weighted to improve the feature extraction ability of the algorithm.
[0093] Third, the present invention combines the detection head of YOLOv5 with the ASFF module to make full use of feature information of different scales to improve the detection accuracy of the model algorithm.
[0094] Embodiment 1:
[0095] An insulator defect detection method based on improved YOLOv5 includes the following steps:
[0096] Step 1: Obtain insulator defect images, perform data preprocessing on the collected insulator defect images, and create a data set;
[0097] Step 2: Randomly divide the training set, test set, and validation set into three parts according to the ratio; divide the training set, test set, and validation set into three parts according to the ratio of 8:1:1;
[0098] Step 3: Reconstruct the improved YOLOv5 network;
[0099] Step 3-1: YOLOv5 includes a trunk, a neck and a detection output. The trunk uses CSPDarknet as the trunk to extract features. The ECA attention mechanism is introduced in the C3 module of the trunk to perform weighted calculation on the features in the channel dimension. The algorithm is based on the YOLOv5 algorithm. The improved YOLOv5 insulator defect detection algorithm performs weighted calculation on the features in the channel dimension to improve the feature extraction capability of the algorithm. The C3 module in the YOLOv5 algorithm trunk network introduces an effective channel attention mechanism (ECA). The improved YOLOv5 insulator defect detection algorithm makes full use of feature information of different scales to improve the detection accuracy of the algorithm.
[0100] Step 3-2: The neck adopts the feature pyramid structure of FPN and PAN to perform feature fusion;
[0101] Step 3-3: The detection head in the detection output is combined with the adaptive spatial feature fusion module to adaptively adjust the weights when fusion of feature maps of different scales;
[0102] Step 4: Use the data set in step 2 as the input of the improved YOLOv5 network in step 3 to perform network training; initialize the parameters of the improved YOLOv5 insulator defect detection algorithm, adjust the input image size to 640×640, set the number of training times to 300, the weight decay coefficient to 0.0005, the initial learning rate to 0.01, and the momentum factor to 0.937, and then use the pre-divided training set and validation set to train and verify the network algorithm; put the divided training set into the improved target detection algorithm for training to obtain the improved algorithm, and conduct ablation experiments on each module of the algorithm based on the algorithm parameter indicators, and conduct comparative experiments with SSD, Faster-RCNN, YOLOv4, YOLOv5n and YOLOv5s algorithms;
[0103] Step 5: Input the image of the insulator to be tested into the improved YOLOv5 network model to obtain the detection results and target location information of the insulator and its defects.
[0104] As a further solution of the present invention, the data enhancement in step 1 is a combined effect of Mosaic and Mixup image enhancement methods, specifically including:
[0105] Mosaic method randomly selects 4 pictures in the training set, stitches them together, and then randomly takes a 640×640 area in the picture as the generated new image. The new image and the original image constitute the data set;
[0106] In the Mixup method, two images are randomly selected from two different batches of training sets, and new images are generated as parameters;
[0107] Mosaic+Mixup hybrid enhancement method, its principle formula is:
[0108] mix_batch x =λ×batch x1 +(1-λ)×batch x2 (6)
[0109] mix_batch y =λ×batch y1 +(1-λ)×batch y2 (7)
[0110] Among them, batch x1 is a batch sample, batch y1 is the label corresponding to one batch of samples; is the label corresponding to another batch y2 The samples of a batch are the labels corresponding to the samples of another batch; λ is the parameter and the mixing coefficient calculated by Beta distribution, and its formula is:
[0111] λ=B*α,β) (8)
[0112] As a further solution of the present invention, the data preprocessing method in step 2 is: formatting the acquired data set to obtain a data set that meets the requirements of the improved YOLOv5 insulator defect detection algorithm, and then dividing the data set that meets the requirements into a training set and a verification set.
[0113] As a further solution of the present invention, the improved YOLOv5 insulator defect detection algorithm described in step 3 performs weighted calculation on the features in the channel dimension to improve the feature extraction capability of the algorithm. On the basis of the YOLOv5 algorithm, the ECA attention mechanism is first embedded in the C3 module in the backbone network of the YOLOv5 algorithm, and the feature map is input into the ECA attention mechanism and firstly undergoes a global average pooling operation, and then the correlation between channels is captured by a one-dimensional convolution with a convolution kernel size of k. The output of the one-dimensional convolution is converted into the attention weight corresponding to each feature channel by a Sigmoid activation function, and finally, the element of each channel in the input feature map is element-wise multiplied with the corresponding attention weight to obtain the feature map output by the ECA attention mechanism.
[0114] As a further solution of the present invention, in order to enhance the coverage of channel information, the above-mentioned ECA attention mechanism has a nonlinear mapping relationship between the convolution kernel size k of the one-dimensional convolution and the number of channels C of the feature map, and its calculation method is shown in formula (4).
[0115]
[0116] Where C represents the number of channels of the feature map, γ and b are adjustable parameters, and |t|odd represents the odd number closest to t.
[0117] In the above technical solution, the embedded ECA module can better capture features of different scales and levels, effectively enhance the interaction and fusion of features of different layers in the C3 module, and improve the quality of the feature map. This enables the improved YOLOv5 insulator defect detection algorithm to extract richer contextual information when dealing with complex scenes in the insulator detection target field, and automatically focus on more important features, thereby improving detection accuracy and robustness, thereby improving the accuracy of target detection.
[0118] As a further solution of the present invention, the improved YOLOv5 insulator defect detection algorithm described in step 3 adds a structure combining a feature pyramid network (FPN) and a path aggregation network (PAN) to the YOLOv5 algorithm to achieve feature fusion. In this process, when a feature map matches the target, feature map information at other levels will be ignored, which will lead to inconsistencies between features of different scales. Therefore, the present invention combines the detection head with an adaptive spatial feature fusion (ASFF) module to enhance the feature fusion capability of the algorithm.
[0119] Specifically, the feature maps output by the three layers in the neck network of the YOLOv5 algorithm have different sizes and channels, which are 1 / 8, 1 / 16 and 1 / 32 of the original image respectively. The shapes of the feature maps need to be adjusted through upsampling and downsampling operations to ensure that they have the same size and number of channels, so that they can be weighted fused in the adaptive fusion step. For the upsampling operation, the number of channels of the feature map is first adjusted using a 1×1 convolution, and then the size of the feature map is adjusted through an interpolation algorithm. For the 1 / 2 times downsampling operation, a 3×3 convolution with a stride of 2 is used to adjust the size and number of channels of the feature map at the same time. For the 1 / 4 times downsampling, the feature map is first pooled, and then the size and number of channels of the feature map are adjusted simultaneously through a 3×3 convolution with a stride of 2. After the feature scaling step, the feature maps have the same size and number of channels and are then adaptively fused. This process can be expressed by formulas (5 to 8).
[0120] For upsampling operations, we first use a 1×1 convolution to adjust the number of channels, and then use an interpolation algorithm to adjust the size:
[0121] F up =Interp(Conv 1×1 (Fi),H target ,W target ) (9)
[0122] In the formula, i is the level of the feature map, H target and W target is the target feature map size.
[0123] For downsampling by a factor of 1 / 2, a 3×3 convolution with a stride of 2 is used:
[0124]
[0125] For 1 / 4 times downsampling, first perform a pooling operation, then a 3×3 convolution with a stride of 2:
[0126]
[0127] After the feature map size and number of channels are adjusted, adaptive fusion is performed:
[0128] F out =Sigmoid(w1·F1+w2·F2+w3·F3) (12)
[0129] In the formula, w i is the adaptive weight, F i is the adjusted feature map.
[0130] Specifically, remember x l is the feature map output by the lth layer in the neck network, x n→l The feature map x representing the output of layer n in the neck network n After feature scaling steps, it is adjusted to x l The feature map when the shape is the same, is the feature map x n→l The feature vector at position (i, j) is calculated by the formula of the l-th layer feature fusion ASFF-l as shown in formula (9).
[0131]
[0132] In the formula, Represents the fusion feature y l The eigenvector at position (i,j), and Represents the eigenvectors and The weights in adaptive fusion are calculated as shown in equations (10), (11) and (12).
[0133]
[0134] In the formula, and and parameter and Obtained through adaptive learning.
[0135] Embodiment 2:
[0136] An insulator defect detection method based on improved YOLOv5 includes the following steps:
[0137] Step 1. Data acquisition: In this embodiment, the original data set uses the "China Transmission Line Insulator String Dataset". The insulator defect images of this data set are provided by the State Grid Corporation of China. The data set is produced by WANG Zi-Hao and contains 1442 transmission line insulator defect images.
[0138] Step 2. Preprocess the data set and use the Mosaic and Mixup image enhancement methods to expand the data set to 3521 images. Divide it into three parts according to the ratio of 8:1:1: 2817 training sets, 352 test sets, and 352 validation sets, which together form the data basis of this experiment.
[0139] Step 3. Improve the original YOLOv5 algorithm and combine it with the Figure 1 Description: The following improvements are mainly made:
[0140] (1) The present invention introduces the ECA attention mechanism to reduce the interference of irrelevant features. On the basis of the YOLOv5 algorithm, the ECA attention mechanism is firstly embedded in the C3 module in the backbone network of the YOLOv5 algorithm, as shown in the attached figure. Figure 2 As shown in the figure, the algorithm improves the feature extraction ability of the detection target. The feature map is input to the ECA attention mechanism and first undergoes a global average pooling operation. Then, the correlation between channels is captured by a one-dimensional convolution with a convolution kernel size of k. The output of the one-dimensional convolution is converted into the attention weight corresponding to each feature channel by the Sigmoid activation function. Finally, the element of each channel in the input feature map is multiplied with the corresponding attention weight to obtain the feature map output by the ECA attention mechanism, as shown in the figure. Figure 3 In order to enhance the coverage of channel information, the convolution kernel size k of the one-dimensional convolution in the ECA attention mechanism has a nonlinear mapping relationship with the number of channels C of the feature map.
[0141]
[0142] In the formula, C represents the number of channels of the feature map, γ and b are adjustable parameters, |t| odd represents the odd number closest to t.
[0143] (2) The present invention introduces the combination of the detection head and the adaptive spatial feature fusion (ASFF) module, and makes full use of the feature information of different scales to improve the detection accuracy of the algorithm by adaptively adjusting the weights when fusing feature maps of different scales. The improved YOLOv5 insulator defect detection algorithm adds a structure combining feature pyramid network (FPN) and path aggregation network (PAN) to the YOLOv5 algorithm to realize feature fusion. In this process, when a feature map matches the target, the feature map information of other levels will be ignored, which will lead to inconsistency between features of different scales. The present invention combines the detection head with the adaptive spatial feature fusion (ASFF) module, as shown in the attached figure. Figure 4 As shown, it is used to enhance the feature fusion capability of the algorithm. The feature maps output by the three layers in the neck network of the YOLOv5 algorithm have different sizes and channels, and their sizes are 1 / 8, 1 / 16 and 1 / 32 of the original image, respectively. The shape of the feature map needs to be adjusted through upsampling and downsampling operations to ensure that they have the same size and number of channels, so that they can be weighted fused in the adaptive fusion step. For the upsampling operation, the number of channels of the feature map is first adjusted using a 1×1 convolution, and then the size of the feature map is adjusted through an interpolation algorithm. For the 1 / 2 times downsampling operation, a 3×3 convolution with a stride of 2 is used to adjust the size and number of channels of the feature map at the same time. For the 1 / 4 times downsampling, the feature map is first pooled, and then the size and number of channels of the feature map are adjusted simultaneously through a 3×3 convolution with a stride of 2. After the feature scaling step, the feature map has the same size and number of channels and then adaptively fused. This process can be expressed by formulas (2 to 9). Denote x l is the feature map output by the lth layer in the neck network, x n→l The feature map x representing the output of layer n in the neck network n After feature scaling steps, it is adjusted to x l The feature map when the shape is the same, is the feature map x n→l The feature vector at position (i,j),
[0144] F up =Interp(Conv 1×1 (Fi),H target ,W target ) (9)
[0145]
[0146] F out =Sigmoid(w1·F1+w2·F2+w3·F3) (12)
[0147]
[0148] In formula (9), i is the level of feature map, Conv 1×1 represents a 1×1 convolution operation, H target and is W target Target size.
[0149] In formula (10), i is the level of the feature map, Conv 3×3 Represents a 3×3 convolution operation with a stride of 2.
[0150] In formula (11), i is the level of the feature map, Conv 3×3 Represents a 3×3 convolution operation with a step size of 2, and MaxPool represents a pooling operation.
[0151] In formula (12), w i is the adaptive weight, F i is the adjusted feature map.
[0152] In formula (2), x l is the feature map output by the lth layer in the neck network, x n→l The feature map x representing the output of layer n in the neck network n After feature scaling steps, it is adjusted to x l The feature map when the shape is the same, is the feature map x n→l The eigenvector at position (i,j), Represents the fusion feature y l The eigenvector at position (i,j), and Represents the eigenvectors and Weights in adaptive fusion.
[0153] In formulas (3), (4) and (5), and and parameter and Obtained through adaptive learning.
[0154] Specifically, in the backbone network, the image to be detected is first taken as input, with an image size of 640×640 and a channel number of 3;
[0155] The first layer of CBS module has 64 channels, a convolution kernel size of 3×3, and a step size of 1. It performs convolution, normalization, and activation operations on the input image, and the image resolution is 640×640;
[0156] The second layer of CBS module has 64 channels, a convolution kernel size of 3×3, and a step size of 2. It continues to perform convolution, normalization, and activation operations on the feature map. The number of channels becomes 128, and the feature map is reduced to half of the original size.
[0157] The third layer C3 module has 128 channels, a convolution kernel size of 3×3, a stride of 2, and the number of channels and feature map size remain unchanged.
[0158] The fourth layer of CBS module has 128 channels, a convolution kernel size of 3×3, and a step size of 2. It continues to perform convolution, normalization, and activation operations on the feature map. The number of channels becomes 256, and the feature map is reduced to half of the original size.
[0159] The fifth layer C3 module has 128 channels, a convolution kernel size of 3×3, a stride of 2, and the number of channels and feature map size remain unchanged.
[0160] The sixth layer of CBS module has 256 channels, a convolution kernel size of 3×3, and a step size of 2. It continues to perform convolution, normalization, and activation operations on the feature map. The number of channels becomes 512, and the feature map is reduced to half of the original size.
[0161] The seventh layer C3 module has 512 channels, a convolution kernel size of 3×3, a stride of 2, and the number of channels and feature map size remain unchanged.
[0162] The eighth layer of CBS module has 512 channels, a convolution kernel size of 3×3, and a step size of 2. It continues to perform convolution, normalization, and activation operations on the feature map. The number of channels remains unchanged, and the feature map is reduced to half of the original size.
[0163] The ninth layer C3 module has 512 channels, a 3×3 convolution kernel, a stride of 2, 1024 channels, and the size of the feature map remains unchanged.
[0164] The tenth layer CBS module has 1024 channels, a convolution kernel size of 3×3, and a step size of 2. It continues to perform convolution, normalization, and activation operations on the feature map. The number of channels and the size of the feature map remain unchanged.
[0165] The eleventh layer Upsample module has 1024 channels, a convolution kernel size of 3×3, and a step size of 2. It performs an upsampling operation on the feature map, with the number of channels unchanged and the feature map expanded to twice its original size.
[0166] The twelfth layer Concat module has 1024 channels and performs concatenation on the feature maps. The size of the feature maps remains unchanged, but the number of channels becomes 1536.
[0167] The thirteenth layer C3 module has 1536 channels, a convolution kernel size of 3×3, a stride of 2, and the number of channels and feature map size remain unchanged;
[0168] The fourteenth layer of CBS module has 1536 channels, a convolution kernel size of 3×3, and a step size of 2. It continues to perform convolution, normalization, and activation operations on the feature map. The number of channels becomes 512, and the size of the feature map remains unchanged.
[0169] The fifteenth layer Upsample module has 512 channels, a convolution kernel size of 3×3, and a step size of 2. It performs an upsampling operation on the feature map, with the number of channels unchanged and the feature map expanded to twice its original size.
[0170] The sixteenth layer Concat module has 512 channels and performs concatenation on the feature maps. The size of the feature maps remains unchanged, but the number of channels becomes 768.
[0171] The seventeenth layer C3 module has 1536 channels, a convolution kernel size of 3×3, a stride of 2, a channel number of 256, and a feature map size that remains unchanged;
[0172] The eighteenth layer of CBS module has 256 channels, a convolution kernel size of 3×3, and a step size of 2. It continues to perform convolution, normalization, and activation operations on the feature map. The number of channels remains unchanged, and the feature map is reduced to half of the original size.
[0173] The nineteenth layer Concat module has 256 channels and performs concatenation on the feature maps. The size of the feature maps remains unchanged, but the number of channels becomes 768.
[0174] The 20th layer C3 module has 768 channels, a convolution kernel size of 3×3, a stride of 2, a channel number of 512, and a feature map size that remains unchanged;
[0175] The 21st layer CBS module has 512 channels, a 3×3 convolution kernel, and a step size of 2. It continues to perform convolution, normalization, and activation operations on the feature map. The number of channels remains unchanged, and the feature map is reduced to half of the original size.
[0176] The twenty-second layer Concat module has 512 channels and performs concatenation on the feature maps. The size of the feature maps remains unchanged, but the number of channels becomes 1536.
[0177] The 23rd layer C3 module has 1536 channels, a convolution kernel size of 3×3, a stride of 2, a channel number of 1024, and a feature map size that remains unchanged.
[0178] In the detection network, the feature maps output by the Concat modules of the 17th, 20th, and 23rd layers are respectively input into three detection heads combined with the ASFF modules.
[0179] Furthermore, in order to prove the effectiveness of the technical solution of the present invention, the effects achieved by the present invention are described in detail below in combination with the ablation experiment results and the accompanying drawings of image detection effects.
[0180] This study uses precision performance indicators and speed performance indicators to quantitatively evaluate the detection performance of the model. The precision performance indicator uses mAP, which specifically includes mAP@0.5 and mAP@0.5:0.95. The difference between the two lies in the different IoU thresholds. Among them, mAP@0.5 represents the mAP value when the IoU threshold is 0.5, and mAP@0.5:0.95 represents the mAP value calculated using the IoU threshold from 0.5 to 0.95. The speed performance indicator uses FPS, which is used to indicate the number of images that the model can detect per second. Among them, the mAP calculation method is shown in formula (13).
[0181]
[0182] Where N is the number of categories of detected targets, AP is the average accuracy of category i, and the calculation method of AP is shown in formula (14).
[0183]
[0184] In the formula, P and R are used to represent the accuracy (Precision) and recall (Recall) of the detection category i respectively. The calculation methods of P and R are shown in formula (15) and formula (16) respectively.
[0185]
[0186] In the formula, TP represents the number of positive examples correctly identified, FP represents the number of negative examples mistakenly identified as positive examples, and FN represents the number of positive examples mistakenly identified as negative examples.
[0187] In order to test the effect of each module on the algorithm improvement, the present invention conducted the following ablation experiment. The ablation experiment is used to explore the impact of different improvement methods on the model detection performance, which has important guiding significance for the design and improvement of the model. In order to verify the effectiveness of the improved method of this study, an ablation experiment was carried out. The same parameter configuration was used during the experiment. The ablation experiment results are shown in Table 1:
[0188] Table 1:
[0189]
[0190] According to the experimental data in Table 1, the improved model 1 introduces the ECA attention mechanism in the C3 module of the YOLOv5 backbone network. Compared with the original model, and are improved by 1.1% and 0.9% respectively, indicating that the ECA attention mechanism can effectively focus on important channel features and improve the feature extraction ability of the model. The improved model 2 adds the ASFF module to the original YOLOv5 model, and are improved by 1.3% and 0.8% respectively. It shows that the ASFF module can effectively process feature information from different scales through adaptive fusion of feature maps, which helps to improve the model's recognition ability for detection targets. The improved YOLOv5 model proposed in this study has the most obvious improvement in various indicators. Compared with the original YOLOv5 model, it has increased by 2.2% on and 1.9% on.
[0191] Based on the above analysis, it is proved that the combination of various improvements has an optimization effect on the model detection accuracy. At the same time, compared with the original YOLOv5 model, the improved YOLOv5 model has a more obvious improvement in detection accuracy.
[0192] In order to further verify the effect of the improved YOLOv5 model in this study on insulator defect detection, comparative experiments were carried out on the same data set with the current mainstream target detection models SSD, Faster R-CNN, YOLOv4, YOLOv5n and YOLOv5s. The experimental results are shown in Table 2:
[0193] Table 2:
[0194]
[0195] The analysis of the experimental results in Table 2 shows that compared with other mainstream target detection models, the improved YOLOv5 model proposed in this study has the best performance in and . Among them, compared with SSD, Faster R-CNN and YOLOv4 models, the detection performance advantage of the improved YOLOv5 model is obviously reflected in the fact that all performance indicators are better than the above models. As the most lightweight target detection model in the YOLOv5 series, YOLOv5n has the highest detection speed, but it loses a large amount of detection accuracy, which is not conducive to performing insulator defect detection tasks in complex environments. Compared with the original YOLOv5, the detection accuracy of the improved YOLOv5 model in this study is significantly improved, which is 2.2% higher in and 1.9% higher in, and the FPS reaches 45.7, indicating that the model still has a high detection speed and has the ability to detect insulator defects in real time. Based on the above analysis, it can be seen that the improved YOLOv5 model proposed in this study has obvious advantages in detection accuracy, and the detection speed meets the requirements of practical applications, and has the best comprehensive effect compared with other target detection models.
[0196] The preferred embodiments of the present invention are described in detail above in conjunction with the accompanying drawings, but the present invention is not limited to the above embodiments. Various changes can be made within the knowledge scope of ordinary technicians in the field without departing from the purpose of the present invention. These changes involve related technologies well known to those skilled in the art, which all fall within the scope of protection of the patent of the present invention.
[0197] Many other changes and modifications may be made without departing from the concept and scope of the present invention.It should be understood that the present invention is not limited to the specific embodiments, and the scope of the present invention is defined by the appended claims.
Claims
1. An insulator defect detection method based on improved YOLOv5, characterized in that: The method comprises the following steps: Step 1: Obtain insulator defect images, perform data preprocessing on the collected insulator defect images, and create a data set; Step 2: Randomly divide the set into three parts: training set, test set and validation set according to the proportion; Step 3: Reconstruct the improved YOLOv5 network; Step 3-1: YOLOv5 includes a trunk, a neck, and a detection output. The trunk uses CSPDarknet as the trunk to extract features. The ECA attention mechanism is introduced in the C3 module of the trunk to perform weighted calculation on the features in the channel dimension. Step 3-2: The neck adopts the feature pyramid structure of FPN and PAN to perform feature fusion; Step 3-3: The detection head in the detection output is combined with the adaptive spatial feature fusion module to adaptively adjust the weights when fusion of feature maps of different scales; Step 4: Use the data set in step 2 as the input of the improved YOLOv5 network in step 3 to perform network training; Step 5: Input the image of the insulator to be tested into the improved YOLOv5 network model to obtain the detection results and target location information of the insulator and its defects.
2. The insulator defect detection method based on improved YOLOv5 according to claim 1 is characterized in that: In the step 1, the data preprocessing uses Mosaic and Mixup to perform joint image enhancement.
3. The insulator defect detection method based on improved YOLOv5 according to claim 2, characterized in that: In step 3-1, the feature map is input into the ECA attention mechanism and first undergoes a global average pooling operation. Then, the correlation between channels is captured by a one-dimensional convolution with a convolution kernel size of k. The output of the one-dimensional convolution is converted into the attention weight corresponding to each feature channel by a Sigmoid activation function. Finally, the element of each channel in the input feature map is element-wise multiplied with the corresponding attention weight to obtain the feature map output by the ECA attention mechanism.
4. The insulator defect detection method based on improved YOLOv5 according to claim 3 is characterized in that: The convolution kernel size k of the one-dimensional convolution in the ECA attention mechanism and the number of channels C of the feature map are calculated as shown in formula (1): , In formula (1), C represents the number of channels of the feature map, γ and b are adjustable parameters, and |t| odd represents the odd number closest to t.
5. The insulator defect detection method based on improved YOLOv5 according to any one of claims 1 to 4, characterized in that: The adaptive spatial feature fusion formula in step 3-3 is shown in formula (2): , In formula (2), Represents the fusion feature y l The eigenvector at position (i,j), and Represents the eigenvectors and The weights in adaptive fusion are calculated as shown in equations (3), (4) and (5) respectively: In the formula, and and parameter and Obtained through adaptive learning.
6. The insulator defect detection method based on improved YOLOv5 according to claim 5, characterized in that: The Mosaic and Mixup are used to perform joint image enhancement, and the calculation method is as shown in formula (6) and formula (7): mix - batch x =λ×batch x1 +(1-λ)×batch x2 (6) mix - batch y =λ×batch y1 +(1-λ)×batch y2 (7), Among them, batch x1 is a batch sample, batch y1 is the label corresponding to one batch of samples; is the label corresponding to another batch y2 The samples of a batch are the labels corresponding to the samples of another batch; λ is the parameter, which is the mixing coefficient calculated by Beta distribution, and its calculation formula is formula (8): λ=B(α,β) (8), In formula (8), α is the proportion of data enhanced by the Mosaic method, and β is the proportion of data enhanced by the Mixup method.
7. The insulator defect detection method based on improved YOLOv5 according to claim 6, characterized in that: The feature maps output by the three levels in the neck network in step 3-2 have different sizes and numbers of channels, which are 1 / 8, 1 / 16 and 1 / 32 of the original image, respectively. The shapes of the feature maps are adjusted through upsampling and downsampling operations to ensure that they have the same size and number of channels, so that weighted fusion can be performed in the adaptive fusion step.
8. The insulator defect detection method based on improved YOLOv5 according to claim 7, characterized in that: Upsampling: First, use 1×1 convolution to adjust the number of channels of the feature map, and then adjust the size through the interpolation algorithm. The calculation formula is as follows: F up =Interp(Conv 1×1 (Fi),H target ,W target ) (9), In formula (9), i is the level of the feature map, H target and W target is the size of the target feature map; For 1 / 2 times downsampling: use 3×3 convolution with a stride of 2, and adjust the size and number of channels of the feature map at the same time. The calculation formula is as follows: , In formula (10), i is the level of the feature map, Conv 3×3 Represents a 3×3 convolution operation with a stride of 2; For 1 / 4 times downsampling: first perform pooling on the feature map, then perform a 3×3 convolution with a stride of 2, and adjust the size and number of channels of the feature map. The calculation formula is (11): , In formula (11), i is the level of the feature map, Conv 3×3 Represents a 3×3 convolution operation with a step size of 2, and MaxPool represents a pooling operation; After the feature map size and channel number are adjusted, adaptive fusion is performed, and the calculation formula is as follows: <h2 style=";text-align:left;direction:ltr">F<h2 style=";text-align:left;direction:ltr"> out <h2 style=";text-align:left;direction:ltr"> Sigmoid(w1·F1+w2·F2+w3·F3) (12) In formula (12), w i is the adaptive weight, F i is the adjusted feature map.
9. The insulator defect detection method based on improved YOLOv5 according to claim 8, characterized in that: The ratio of the training set, test set and validation set in step 2 is 8:1:
1.
10. The insulator defect detection method based on improved YOLOv5 according to claim 1, characterized in that: The improved YOLOv5 network model after training is quantitatively evaluated on the detection performance of the model using the accuracy performance index and the speed performance index. The accuracy performance index uses mAP, including mAP@0.5 and mAP@0.5:0.
95. The mAP calculation method is shown in formula (13): , In formula (13), N is the number of categories of detected targets, AP is the average accuracy of category i, and the calculation method of AP is shown in formula (14): , In formula (14), P and R are used to represent the precision and recall of the detection category i, respectively. The calculation methods of P and R are shown in formula (15) and formula (16), respectively: , In formulas (15) and (16), TP represents the number of positive examples correctly identified, FP represents the number of negative examples incorrectly identified as positive examples, and FN represents the number of positive examples incorrectly identified as negative examples. The speed performance index adopts FPS, and the FPS calculation method is shown in formula (17): FPS=N / T (17), In formula (17), N represents the total number of frames and T represents the total time.
Citation Information
Cited By
AL-YOLO-based insulator defect detection method and system
CN120726048A
Building surface defect detection method and system based on improved YOLOv8
CN121481958A
Wind power blade defect detection method and equipment based on improved YOLO11n
CN121526959A
Wind power blade defect detection method and device based on improved YOLO11n
CN121526959B
Improved YOLOv11s-based bimodal defect intelligent detection method for high-speed rail power transmission line
CN121526997A