Frontiers in Computing and Intelligent Systems ISSN: 2832-6024 | Vol. 3, No. 2, 2023 44 Insulator defect detection algorithm based on improved YOLOv5 Xin Lian1 *, Dewen Wang2 1 School of Control and Computer Engineering, North China Electric Power University, Baoding 071003, China 2 Engineering Research Center of Intelligent Computing for Complex Energy Systems, Ministry of Education, Baoding 071003, China * Corresponding author: Xin Lian Abstract: Aiming at the problems such as small target scale, complex background, difficult detection, false detection and leakage detection of aerial insulators in transmission lines, this paper proposes an insulator defect detection algorithm based on improved YOLOv5. Firstly, CBAM attention module is added to the backbone network of YOLOv5 to improve the feature extraction capability of insulator pictures. Secondly, in the feature extraction part, PANet structure is replaced by BiFPN structure to make full use of the underlying feature information. Finally, the improved K-means algorithm is used to determine the prior frame and improve the defect detection accuracy of the insulator. Experimental results show that this method can improve the identification accuracy of insulator defect detection in transmission lines. Keywords: YOLOv5; A small goal; An insulator; Defect detection; BiFPN; CBAM attention mechanism; K means++ algorithm. 1. Introduction Insulator is a special insulating control in the power system. It is responsible for fixing the current-carrying conductor in the overhead transmission line to prevent the current from returning to the ground, and it is an essential equipment in the power system [1]. Insulator power failure will directly threaten the safety and stability of the line. According to incomplete statistics, insulator failure accounts for more than 50% of power equipment failures [2]. In order to ensure the safety of power grid, insulator fault detection has become the primary task of power system maintenance. With the development of deep learning, various object detection algorithms have been proposed. The research on insulator target detection makes a great contribution to the location detection of aerial insulator in power inspection. On this basis, it is necessary to further classify and identify the state of insulators. At present, scholars at home and abroad have also made some researches on the defect detection of insulators. The traditional defect identification methods still use graph segmentation and machine learning, etc. Literature [3] preprocessed insulators, converted RGB values into brightness space, and avoided the impact of illumination on images. Then OTSU algorithm was used to segment and morphological method was used to analyze the defects The segmented image is denoised. Finally, the number of pixels on the insulator string is determined to determine whether there are self-explosion and other damage defects. Traditional methods mainly focus on image segmentation, and the algorithm is complex. The realization of insulator segmentation algorithm in different scenes is different, and it is difficult to meet the defect detection of a large number of aerial photography insulators with complex background. The convolutional neural network does not need to do too much data preprocessing, but extracts the features of the input image as a whole, and autonomously learns the features of the image to realize defect detection. In literature [4], SSD model was used to detect the state of insulators, DenseNet was introduced as a feature extraction network to enhance the classification ability of the model, and data enhancement was used to solve the problem of sparse data and improve the accuracy of the model. In literature [5], random forest algorithm is used to segment insulators for target identification, and then convolutional neural network is used to judge whether there are defects on insulators. Finally, Faster R-CNN network is used to locate the location of defects on insulators. In literature [6], Faster R CNN algorithm was used in the detection of UAV power line inspection image parts, and the detection effect of power parts was better, but it could not meet the real-time requirements. Literature [7] proposes an aerial insulator detection method based on U-net deep network, which is an effective insulator detection method. However, the background of insulator image is relatively simple, so it cannot be accurately detected under complex background. Literature [8] uses the Random Sample Consensus, RANSAC) designed the missing insulator detection algorithm and combined with the Single Shot MultiBox Detector (SSD) algorithm to locate the missing insulators in the picture, but the method of fitting the line to detect defects had poor anti-interference ability. Through research and investigation, there have been many researches on deep learning in the field of insulator detection, which provides new ideas for power inspection. Moreover, insulator defect detection has become the main trend of deep learning in power inspection research, which has advantages over traditional detection methods in terms of detection accuracy, speed and generalization ability of model application. However, at present, there is still a great room for improvement in the research of insulator defect detection in power inspection. There are few public data sets, and most of the data sets used in research experiments are difficult to meet the actual needs. The number of layers in the feature extraction network is too few, and the features extracted from the insulator image with complex background are fuzzy. The defect size is smaller than the insulator size target, and the method for improving the defect detection accuracy of small target is single. Therefore, an insulator defect detection algorithm based on 45 improved YOLOv5 is proposed in this paper in view of the small target scale, complex background, difficult detection, false detection and leakage detection of aerial insulators in transmission lines. Firstly, CBAM attention module is added to the backbone network of YOLOv5 to improve the feature extraction capability of insulator pictures. Secondly, in the feature extraction part, PANet structure is replaced by BiFPN structure to make full use of the underlying feature information. Finally, the improved K-means algorithm is used to determine the prior frame, so as to improve the stability of the generated prior frame and the detection accuracy of insulator defects. 2. Principle of Yolov5 algorithm YOLOv5 has four network models of different sizes, s, m, l and x, among which YOLOv5s is the smallest, and other models are the product of increasing network depth and width on its basis. Although its detection performance is constantly enhanced, the size of the model is getting bigger and the detection speed is getting slower and slower. The YOLOv5s was chosen as the base model in order to make the model lightweight and easier to port to embedded devices. There are many YOLOv5 versions, this article uses version 5.0, and the activation function has changed from the LeakyReLU and Hardswish unity of the early days to the SiLU activation function. In addition, the C3 module is adopted to replace the original BottleneckCSP module. The C3 module eliminates one convolutional layer in BottleneckCSP compared to bottleneckCsp module, which improves the overall model size and reasoning speed. Although the accuracy is decreased by 0.8% compared with the 3.0 version, compared with the speed improvement, this accuracy loss is still acceptable. This experiment is an improvement based on the 5.0 version model. The model of YOLOv5 is mainly composed of Backbone and Head. Backbone, as the feature extraction module, mainly consists of Focus, C3 and SPP modules, while the Head part mainly includes Neck and Detect modules for extracting fusion features. Its network model is shown in Figure 1. The Backbone consists of three modules. Figure 1. YOLOv5 network structure 1)Focus module. This is the unique structure of YOLOv5. Its main idea is to cut the input image through slicing operation, periodically extract pixels from the high resolution image and reconstruct them into the low resolution image, that is, stack the four adjacent positions of the image. By gathering w and h dimension information into c channel space, the receptive field of each point is improved while the computation is reduced, avoiding the loss of original information. 2)Cross Stage Partial network (CSP) module. The feature map of the base layer is divided into two parts and then combined with the cross-stage hierarchical structure to achieve a richer gradient combination. The author of YOLOv5 also uses this structure for reference. However, compared with YOLOv4, which only uses CSP structure in the Backbone, the author of v5 designs two CSP structures, respectively for the backbone and neck. Later, the author improves this structure by removing a convolutional layer in the bottleneck structure and changing it into C3 mode Block. 3)Spatial Pyramid Pooling network (SPP) module. This module is based on the SPPNet proposed by He Keming in 2014, also known as the spatial pyramid pooling network. By means of maximum pooling k=(1x1, 5x5, 9x9, 13x13), feature maps of different scales are splicing to realize the fusion of features of different scales, thus improving the sensitivity field and extracting important features. In the Head part, Y0LOv5 uses the structure of the feature pyramid FPN+PAN. The FPN layer transmits and integrates the feature information of the upper layer and the lower layer through up-sampling, while the PAN layer splice the feature of the lower layer with the feature of the upper layer, so that the feature of the lower layer with high resolution is transmitted to the upper layer. Based on the structure of FPN+PAN, the feature aggregation of different detection layers from different trunk layers can effectively solve the multi-scale problem. 3. Improved YOLOv5 model 3.1. Integrate CBAM attention module CBAM is a lightweight attention module that is simple and effective, can be directly integrated into the CNN architecture, and can be trained end-to-end. Given a feature map, CBAM deduces the attention map along two independent dimensions, channel and space, and then multiplies the attention map with the input feature map for adaptive feature refinement. The structure of CBAM module is shown in Figure 2. In literature [9], CBAM module is integrated into different models of different data sets and different classification tasks, and the model performance is greatly improved, which proves the effectiveness of CBAM module. Figure 2. CBAM attention module The target size of insulator defect is small, the features are few and not obvious. Adding CBAM attention module to the backbone network can enhance the network's ability to extract the target features, and directly improve the feature fusion of the neck network. In the detection task, the CBAM attention module can help the model effectively extract the attention area and improve the detection performance. 3.2. Weighted bidirectional feature pyramid network BiFPN [10] network is an efficient multi-scale feature fusion method integrating bidirectional cross connection and weighted fusion. Since FPN[11] was proposed, FPN has been widely used in multi-scale feature fusion. In recent years, more multi-scale feature fusion network structures, such as PANet [l2], M2det[13] and NAS-FPN[14], have been proposed by researchers. However, when input features of different levels are fused, most work summarizes them indiscriminately. However, these different input features have different resolutions and have different contributions to the 46 fused output features. To this end, literature [15] proposes a simple but efficient weighted bidirectional feature pyramid network (BiFPN), which introduces a learning weight factor to represent the importance of different input features, while repeatedly applying top-down and bottom-up multi-scale feature fusion. In order to make full use of the underlying characteristics of the target, this paper improved the neck network and replaced the original PANet network with BiFPN network to improve the detection accuracy. Its structure is shown in Figure 3. Although PANet in YOLOv5 achieved good multi- scale feature fusion results through top-down and bottom-up path aggregation, it required a large amount of computation, and the input features in the bottom-up feature fusion stage did not contain the original output features generated by the backbone network. BiFPN uses cross-connection to remove nodes that contribute little to feature fusion in PANet, and adds a skip connection between input nodes and output nodes at the same scale, which fuses more features without increasing the cost. On the same feature scale, each bidirectional path is regarded as a feature network layer, and the same layer is repeatedly used to achieve a higher level of feature fusion. Figure 3. Improved neck network 3.3. Improved distance standard K-means algorithm Using K-means algorithm to determine prior box has become an indispensable step of target detection. The K- means algorithm provided by YOLOv5 can cluster new prior boxes on its own data set, but it takes the Euclidean distance between sample boxes as the distance measurement, which will lead to a larger proportion of prior boxes when calculating losses. However, the purpose of clustering is to make the prior box and the adjacent real box have larger IOU values. The following two cases obviously have the same IOU values, so the ratio should be the same in loss calculation. The improved calculation formula is as follows: 𝑑 = 1 βˆ’ πΌπ‘‚π‘ˆ(π‘π‘œπ‘₯, π‘π‘’π‘›π‘‘π‘Ÿπ‘œπ‘–π‘‘) The average IOU of prior boxes obtained by the improved K-means algorithm is 85.68%, 3.1% higher than that before the improvement. Nine prior boxes are obtained by using the improved K-means algorithm, which respectively correspond to the feature maps of different scales. 4. Results and discussion 4.1. Experimental environment and data set Experimental environment: The operating system used in the experiment was Windows10, the GPU model was Tesla V100-PCIE 32GB, and the CPU model was Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz. All models are based on Pytorch 1.8 and use Cuda 10.1 to accelerate the GPU. Data set: As there are few insulator data sets disclosed in the current power inspection, in order to better achieve the purpose of the experiment, this paper collected and sorted out the existing insulator data, and finally summarized a total of 848 insulator pictures, including 600 normal insulator images and 248 defective insulators. Labelimg image annotation tool is used to label all images. The insulator is labeled as insulator and the defect position is labeled as defect. In order to improve the generalization ability of the network model, the data set was divided by 4/6, with the training set accounting for 40%, the test set accounting for 60%, and the positive and negative samples accounting for 50% respectively in the training set and the test set. 4.2. Analysis of experimental results Experimental environment: The operating system used in the experiment was Windows10, the GPU model was Tesla V100-PCIE 32GB, and the CPU model was Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz. All models are based on Pytorch 1.8 and use Cuda 10.1 to accelerate the GPU. In order to realize the optimal performance of the model, SGD(Stochastic Gradient Descent) and Adam (adaptive moment estimation) optimizers are used for comparison. The results of different optimizers are shown in Table 1. Table 1. Experimental data of sensor measurement accuracy Network Model SGD Adam mAP @0.5 mAP@0. 5:0.95 mAP@ 0.5 mAP@0.5: 0.95 YOLOv5 0.953 0.854 0.947 0.846 Improved YOLOv5 0.972 0.95 0.969 0.93 It can be seen from Table 1 that the average accuracy of using SGD optimizer is generally higher than Adan. Therefore, SGD is selected as the optimizer by default in the subsequent experiment for continuous network training. The changes of various parameter indexes of the improved YOLOv5 model along with the training cycle are shown in Figure 4. As can be seen from Figure 4, with the continuous training of the model, the position loss and category loss of the training set continue to decline. After 50 training cycles, the position loss of the verification set tends to be stable at about 0.01, the confidence loss is stable at about 0.005, the class loss is close to 0.0005, and the accuracy and recall rate of the model detection are stable at about 0.98. Figure 4. Paramter index of improved YOLOv5 In order to check the performance of the model before and after improvement, different models were used for testing, 47 and the results were shown in Table 2. As can be seen from Table 2, the improved insulator detection network model greatly improves the speed on the basis of ensuring the accuracy, and can meet the task requirements of UAV power inspection. The improved network model can locate the insulator and defect positions accurately. It is a feasible insulator defect detection algorithm, in which the insulator positions are mapped by insulator and defect positions by defect. The detection effect before and after improvement is shown in Figure 5. Table 2. Contrast experiment Network Model Precision Recall mAP@0.5 YOLOv3 0.932 0.948 0.938 YOLOv5 0.945 0.944 0.953 Improved YOLOv5 0.985 0.981 0.97 (a) Before improvement (b) After improvement Figure 5. Image of YOLOv5 test before and after improvement 5. Conclusion In this paper, an improved YOLOv5 insulator defect detection algorithm is proposed to solve the problems of small target scale, complex background, difficult detection, false detection and leakage detection of aerial insulators in transmission lines. Firstly, CBAM attention module is added to the backbone network of YOLOv5 to improve the feature extraction capability of insulator pictures. Secondly, in the feature extraction part, PANet structure is replaced by BiFPN structure to make full use of the underlying feature information. Finally, the improved K-means algorithm is used to determine the prior frame, so as to improve the stability of the generated prior frame and the detection accuracy of insulator defects. A large number of experiments have proved the effectiveness of the proposed method. References [1] Gao Youhua, Wang Caiyun, Liu Xiaoming, et al. Analysis of electric field of basin-type insulator existing metal particles and its influence on surface flashover [J]. New Technology of Electrical Engineering,2015,34(8) :56-61. [2] Huang Ruiying, HUANG Daochun, Zhou Jun, et al. Research on bird damage risk region of 400kV DC transmission line [J]. New Technology of Electrical Engineering, 2017, 36(2): 68-73. [3] Chen Wenhao, Yao Lina, Li Fengzhe. Insulator Defect Detection and Location in UAV Power Grid Inspection [J]. Computer Applications, 2019,39(S1); 210-214. [4] Tan Jicheng. Automatic Insulator Detection for Power Line Using Aerial Images Powered by Convolutional Neural Networks[J]. Journal of Physics: Conference Series, 2021, 1748(4). [5] Fan P, Shen H M, Zhao C, Wei Z, Yao J G. ZhouZ Q. FuR, Hu Q. Defect Identification Detection Research for Insulator of Transmission Lines Based on Deep Learning[J]. Journal of Physics: ConferenceSeries,2021,1828(1). [6] Wang Wanguo, Tian Bing, Liu Yue, et al. Research on power component recognition of UAV inspection image based on RCNN [] Journal of Geo-Information Science, 2017, 19(2) : 256-263. [7] Chen Jingwen, Zhou Xin, Zhang Rong, et al. Aerial photo insulator detection based on U-net network [J]. Journal of Shaanxi University of Science and Technology, 2018, 36(4): 153-157. [8] Du Fenglin. Application of Object Detection Algorithm Based on Deep Learning [D]. Hefei: Anhui University,2018. [9] Woo S, Park J, Lee JY, et al. CBAM: Convolutional block attention module. Proceedings of the 15th European Conference on Computer Vision. Munich: Springer, 2018.3-19. [10] Tan MX, Pang RM, Le QV. Efficient Det: Scalable and efficient object detection. 2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). Seattle: IEEE, 2020. 10778-10787. [11] Lin TY, Dollar P, Girshick R, et al. Feature pyramid networks for object detection. 2017 IEEE Conference on Computer Vision and Pattern Recognition (CVPR). Honolulu: IEEE, 2017.936- 944. [12] Liu S, Qi L, Qin HF, et al. Path aggregation network for instance segmentation. 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition. Salt Lake City: IEEE, 2018. 8759- -8768. [13] Zhao QJ, Sheng T, Wang YT, et al. M2Det: A single-shot object detector based on multi-level feature pyramid network. Proceedings of the 33rd AAAI Conference on Artificial. Intelligence. Honolulu: AAAI, 2019.9259- 9266. [14] Ghiasi G, Lin TY, Le QV. NAS-FPN: Learning scalable feature pyramid architecture for object detection. 2019 IEEE/CVF Conference on Computer V ision and Pattern Recognition. Long Beach: IEEE, 2019.7029-7038. Bai HY, Wen S, Chan SHG. Crowd counting on images with scale variation and isolated clusters. 2019 IEEE/CVF International Conference on Computer Vision Workshop (ICCVW). Seoul: IEEE, 2019. 18- -27.