Insulator defect detection method based on improved YOLOv7
By improving the YOLOv7 algorithm and the SIoU-NMS non-maximum suppression algorithm, combined with the CoordAtt attention mechanism, the accuracy and efficiency problems of insulator fault detection during substation inspection are solved, and high-precision small-objective detection is achieved.
Patent Information
- Application Number
- CN202211116278.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-14
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2042-09-14
AI Technical Summary
In the inspection of substations, in the complex background, the insulator failure target is small and difficult to be accurately detected, resulting in low detection efficiency and high cost.
The improved YOLOv7 algorithm is adopted, combined with the SIoU-NMS non-maximum suppression algorithm and the CoordAtt attention mechanism, and through preprocessing and loss function optimization, an anchor box suitable for insulator defect detection is generated to improve detection accuracy.
The precise detection of insulator defects in complex backgrounds is achieved, and missed detection and missed detection is reduced, and the detection accuracy rate reaches 95.1%.
Smart Images

Figure CN115731164B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an insulator defect detection method based on an improved YOLOv7, and belongs to the technical field of insulator defect detection. Background Art
[0002] With the development of my country's large-capacity, high-voltage transmission systems, substations are playing an increasingly important role in the entire power system. Insulators, the primary identification target for substation fault detection, are prone to damage and flashover in the complex and harsh environments of substations. These can easily interrupt power supply to transmission lines, significantly impacting the safe use of electricity by residents and posing a significant threat to the stable operation of the power system. Therefore, detecting insulator defects is a top priority for power grid maintenance.
[0003] Traditional insulator defect detection methods primarily rely on helicopter-based inspections, field surveys, or analysis of images captured by robots or drones using traditional detection algorithms. However, given the complex structure of my country's power transmission lines, the use of traditional detection methods results in significant waste of financial and material resources and is inefficient. In recent years, with the advancement of neural network theory and improvements in computer performance, insulator defect detection methods based on deep learning have become mainstream and are widely used in practical engineering applications.
[0004] At present, target detection based on deep learning can overcome shortcomings such as low detection accuracy, susceptibility to environmental interference, and weak generalization ability. Target detection algorithms based on deep learning can be divided into two types: one is a multi-stage method, representative algorithms include R-CNN and FastR-CNN, and the other is a single-stage detection algorithm, typical algorithms include SSD and YOLO series. Compared with traditional methods, the insulator recognition method based on SSD (single shot multibox detector) and a two-stage fine-tuning strategy cannot achieve end-to-end detection. The Faster RCNN algorithm realizes end-to-end insulator defect detection, but its model has a large amount of computation and slow detection speed. Some of the algorithms proposed now are still unable to effectively complete the task of accurately detecting small targets such as insulator defects in complex backgrounds. In 2022, the YOLOv7 algorithm was born. The detection speed and accuracy of this algorithm exceeded all known target detectors. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to overcome the defects of the existing substation inspection robot in the image with complex background and small insulator fault targets that are difficult to be accurately detected, and provide an insulator defect detection method based on improved YOLOv7.
[0006] To achieve the above object, the present invention provides an insulator defect detection method based on an improved YOLOv7, comprising:
[0007] Input the image to be recognized into the pre-trained network model;
[0008] Based on the pre-acquired prediction frame, the network model outputs multiple preliminary prediction frames of the image to be identified with the same size as the prediction frame;
[0009] The SIoU-NMS improved non-maximum suppression algorithm is used to filter the preliminary prediction box output of the image to be identified to obtain the final prediction box;
[0010] Based on the final prediction box, the defect type of the image to be identified is obtained.
[0011] Prior to pre-training, the network model is obtained by the following steps:
[0012] Obtain a training set, which includes image samples and target ground truth frames of the image samples;
[0013] Preprocess the target ground truth box of the image sample to obtain multiple anchor boxes of fixed size;
[0014] Build a network model, input image samples and fixed-size anchor boxes into the network model, and the network model divides the image samples into multiple grids;
[0015] Based on the fixed-size anchor box, multiple fixed-size prediction boxes are generated with each grid as the center;
[0016] The total loss function is used to calculate the gap between the target real box of the image sample and the fixed-size prediction box, and the network parameters, position and size of the prediction box of the network model are iteratively updated;
[0017] If the total loss function converges to a constant value, where the constant value means that the loss function value fluctuates around a certain stable value and no longer fluctuates greatly, the model stops iterating and outputs the final network model.
[0018] First, get the prediction box in advance, which is achieved by the following steps:
[0019] The prediction box with the highest accuracy obtained by the network model during training is selected as the pre-acquired prediction box.
[0020] Preferably, the network architecture of the constructed network model includes an Input module, a Backbone module, a Neck module and a Head module, and the Input module, the Backbone module, the Neck module and the Head module are connected in sequence;
[0021] The Backbone module includes the first CBS module, the second CBS module, the third CBS module, the fourth CBS module, the gnConv module, the first ELAN module, the second ELAN module, the third ELAN module, the fourth ELAN module, the first MP1 module, the second MP1 module, the third MP1 module and the CoordAtt module.
[0022] The first CBS module, the second CBS module, the third CBS module, the gnConv module, the fourth CBS module, the first ELAN module, the first MP1 module, the second ELAN module, the second MP1 module, the third ELAN module, the third MP1 module, the fourth ELAN module and the CoordAtt module are connected in sequence;
[0023] The first CBS module, the second CBS module, the third CBS module and the fourth CBS module are all CBS modules, the first ELAN module, the second ELAN module, the third ELAN module and the fourth ELAN module are all ELAN modules, and the first MP1 module, the second MP1 module and the third MP1 module are all MP1 modules;
[0024] The gnConv module adopts recursive gated convolution, and the CoordAtt module adopts the CoordAtt attention mechanism.
[0025] First, the expression of the total loss function is:
[0026] L=W1×L box +W2×L cls +W3×L obj
[0027]
[0028] L cls =-ζ t (1-p t ) δ log(p t ),
[0029]
[0030]
[0031] Where L is the total loss, L box is the boundary regression loss, L obj is the target confidence loss, W1 is the weight of boundary regression loss in the total loss, W2 is the weight of focal loss classification loss in the total loss, W3 is the weight of target confidence loss in the total loss, IoU is intersection over union loss, Ω is shape loss, and △ is distance loss;
[0032] L cls is the focal loss classification loss, ζ t is the positive and negative sample weight parameter, p t is the probability of belonging to positive and negative samples, δ is an adjustable aggregation parameter, p is the probability that the network model predicts that the image sample belongs to the foreground, Y = 1 represents the foreground of the image sample, Y = -1 represents the background of the image sample, and ζ is the weight parameter.
[0033] First, the expression of the intersection-over-union loss is:
[0034]
[0035] In the formula, A is the real box, B is the predicted box, and IoU is the intersection-over-union loss;
[0036] The expression of shape loss is:
[0037]
[0038] Where Ω is the shape loss, w is the width of the prediction box, and w gt is the width of the real frame, max(w,w gt ) for w and w gt The maximum value, h is the height of the prediction box, h gt is the height of the real frame, max(h, h gt ) for h and h gt The maximum value, θ is an adjustable variable;
[0039] The expression of distance loss is:
[0040]
[0041]
[0042]
[0043]
[0044]
[0045] Where α is the angle between the line connecting the center of the real frame to the center of the predicted frame and the X-axis, σ is the distance between the center of the real frame and the center of the predicted frame, x is the sine value of α, and C w1 is the width of the minimum bounding rectangle of the real box and the predicted box, C h1 is the height of the minimum bounding rectangle of the real box and the predicted box, C w C is the width of the rectangle constructed with the line connecting the center of the real box to the center of the predicted box as the diagonal line, hIt is the height of the rectangle constructed with the line connecting the center point of the real box to the center point of the predicted box as the diagonal line, is the horizontal coordinate value of the center point of the real frame, b cx is the horizontal coordinate value of the center point of the prediction box, is the vertical coordinate value of the center point of the real frame, b cy is the vertical coordinate value of the center point of the prediction box, ∧ is the angle loss, and △ is the distance loss;
[0046] If the angle of α is greater than 45°, then α is replaced by β, β = 90° - α.
[0047] Prioritize preprocessing the target ground truth boxes of the image samples to obtain multiple anchor boxes of fixed sizes, which is achieved by the following steps:
[0048] Use the K-means clustering algorithm to cluster the target ground truth boxes of the image samples and obtain multiple anchor boxes of fixed size. Prioritize using the SIoU-NMS improved non-maximum suppression algorithm to filter the preliminary prediction box output of the image to be identified to obtain the final prediction box, which is achieved through the following steps:
[0049] Step 1: Set the confidence threshold and SIoU threshold;
[0050] Step 2: Calculate the confidence of all preliminary prediction boxes output by the network model, put the preliminary prediction boxes with confidence higher than the confidence threshold into the candidate list, and sort the preliminary prediction boxes in the candidate list in descending order from high to low according to confidence;
[0051] Step 3: Take the preliminary prediction box with the highest confidence from the candidate list, save it to the output list, and delete the preliminary prediction box from the candidate list;
[0052] Step 4: Calculate the intersection-over-union (SIoU) loss between the highest confidence preliminary prediction box obtained in the previous step and all other preliminary prediction boxes in the candidate list, and remove the preliminary prediction boxes whose SIoU loss is higher than the set SIoU threshold from the candidate list;
[0053] Step 5: Repeat steps 3 and 4 until the candidate list is empty;
[0054] Step 6: Use the preliminary prediction box in the output list as the final prediction box.
[0055] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the above methods when executing the program.
[0056] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of any of the above methods.
[0057] The beneficial effects achieved by the present invention are:
[0058] The present invention collects images to establish a data set, uses data cleaning and data enhancement to expand the data set, and uses a mean clustering algorithm to cluster the marked boxes in the data set to generate anchor boxes suitable for insulator defect target detection.
[0059] Secondly, the network model continuously iteratively corrects the anchor frames, outputting predicted frames that are close to the ground-truth frames. The CoordAtt attention mechanism is introduced in the backbone of the network model, enabling the network to enhance effective features and weaken useless features in the channel and spatial domains during feature extraction. Recursive gated convolution (gnConv) is added to the backbone of the network model to improve the network's long-range attention and reduce gradient diffusion.
[0060] The loss function was then optimized to address the issue of missed detection of occluded insulators. The SIoU loss function and focal loss function were used to calculate the bounding box regression loss and classification loss, respectively. Furthermore, the SIoU-NMS algorithm was proposed to improve non-maximum suppression to reduce the over-detection of defective objects and optimize the overall model performance. Finally, the improved model was trained and validated to obtain the optimal detection network. Experimental results demonstrate that the improved algorithm achieves an average accuracy of 95.1%, enabling accurate detection of small objects such as insulator defects and reducing missed and false detections. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 It is a flow chart of the training network model of the present invention;
[0062] Figure 2 This is the framework diagram of the CoordAtt attention mechanism in the present invention;
[0063] Figure 3 Schematic diagram of SIoU loss function calculation in the present invention;
[0064] Figure 4 Schematic diagram of the intersection-to-connection ratio loss in the present invention;
[0065] Figure 5 Flowchart of the SIoU-NMS improved non-maximum suppression algorithm in the present invention;
[0066] Figure 6 It is a structural diagram of the network model of the present invention;
[0067] Figure 7 is a schematic diagram of the ground-truth box of the image sample;
[0068] Figure 8 It is a schematic diagram of the predicted box of the image sample;
[0069] Figure 9 It is the feature map of each layer of the network model;
[0070] Figure 10 Visual heat map output for the network model;
[0071] Figure 11 This is a comparison chart of the accuracy before and after the network model improvement;
[0072] Figure 12 Comparison chart of recall rates before and after network model improvement;
[0073] Figure 13 This is a comparison chart of mAP_0.5 before and after network model improvement;
[0074] Figure 14 This is the PR curve before the network model is improved;
[0075] Figure 15 This is the PR curve chart after the network model is improved;
[0076] Figure 16 This is a schematic diagram of the network model before improvement;
[0077] Figure 17 This is a schematic diagram of the detection after the network model is improved;
[0078] Figure 18 This is a schematic diagram of the network model before improvement;
[0079] Figure 19 This is a schematic diagram of the detection after the network model is improved;
[0080] Figure 20 This is a schematic diagram of the network model before improvement;
[0081] Figure 21 This is a schematic diagram of the detection after the network model is improved;
[0082] Figure 22 This is a schematic diagram of the network model before improvement;
[0083] Figure 23 This is a schematic diagram of the detection after the network model is improved. DETAILED DESCRIPTION
[0084] The following examples are only used to more clearly illustrate the technical solutions of the present invention and are not intended to limit the scope of protection of the present invention.
[0085] Example 1
[0086] The present invention provides an insulator defect detection method based on an improved YOLOv7, comprising:
[0087] Input the image to be recognized into the pre-trained network model;
[0088] Based on the pre-acquired prediction frame, the network model outputs multiple preliminary prediction frames of the image to be identified with the same size as the prediction frame;
[0089] The SIoU-NMS improved non-maximum suppression algorithm is used to filter the preliminary prediction box output of the image to be identified to obtain the final prediction box;
[0090] Based on the final prediction box, the defect type of the image to be identified is obtained.
[0091] Furthermore, in this embodiment, the network model is pre-trained and obtained by the following steps:
[0092] Obtain a training set, which includes image samples and target ground truth frames of the image samples;
[0093] Preprocess the target ground truth box of the image sample to obtain 9 anchor boxes of fixed size;
[0094] Build a network model, input image samples and fixed-size anchor boxes into the network model, and the network model divides the image samples into multiple grids;
[0095] Based on the fixed-size anchor box, multiple fixed-size prediction boxes are generated with each grid as the center;
[0096] The total loss function is used to calculate the gap between the target real box of the image sample and the fixed-size prediction box, and the network parameters, position and size of the prediction box of the network model are iteratively updated;
[0097] If the total loss function converges to a constant value, where the constant value means that the loss function value fluctuates around a certain stable value and no longer fluctuates greatly, the model stops iterating and outputs the final network model.
[0098] Furthermore, in this embodiment, the prediction frame is obtained in advance, which is achieved by the following steps:
[0099] The prediction box with the highest accuracy obtained by the network model during training is selected as the pre-acquired prediction box.
[0100] Furthermore, the network architecture of the network model constructed in this embodiment includes an Input module, a Backbone module, a Neck module, and a Head module, and the Input module, the Backbone module, the Neck module, and the Head module are connected in sequence;
[0101] The Backbone module includes the first CBS module, the second CBS module, the third CBS module, the fourth CBS module, the gnConv module, the first ELAN module, the second ELAN module, the third ELAN module, the fourth ELAN module, the first MP1 module, the second MP1 module, the third MP1 module and the CoordAtt module.
[0102] The first CBS module, the second CBS module, the third CBS module, the gnConv module, the fourth CBS module, the first ELAN module, the first MP1 module, the second ELAN module, the second MP1 module, the third ELAN module, the third MP1 module, the fourth ELAN module and the CoordAtt module are connected in sequence;
[0103] The first CBS module, the second CBS module, the third CBS module and the fourth CBS module are all CBS modules, the first ELAN module, the second ELAN module, the third ELAN module and the fourth ELAN module are all ELAN modules, and the first MP1 module, the second MP1 module and the third MP1 module are all MP1 modules;
[0104] The gnConv module adopts recursive gated convolution, and the CoordAtt module adopts the CoordAtt attention mechanism.
[0105] Furthermore, the expression of the total loss function in this embodiment is:
[0106] L=W1×L box +W2×L cls +W3×L obj
[0107]
[0108] L cls =-ζ t (1-p t ) δ log(p t ),
[0109]
[0110] Where L is the total loss, L box is the boundary regression loss, L obj is the target confidence loss, W1 is the weight of boundary regression loss in the total loss, W2 is the weight of focal loss classification loss in the total loss, W3 is the weight of target confidence loss in the total loss, IoU is intersection over union loss, Ω is shape loss, and △ is distance loss;
[0111] L clsis the focal loss classification loss, ζ t is the positive and negative sample weight parameter, p t is the probability of belonging to positive and negative samples, δ is an adjustable aggregation parameter, p is the probability that the network model predicts that the image sample belongs to the foreground, Y = 1 represents the foreground of the image sample, Y = -1 represents the background of the image sample, and ζ is the weight parameter.
[0112] Furthermore, in this embodiment, the expression of the intersection-over-union loss is:
[0113]
[0114] In the formula, A is the real box, B is the predicted box, and IoU is the intersection-over-union loss;
[0115] The expression of shape loss is:
[0116]
[0117] Where Ω is the shape loss, w is the width of the prediction box, and w gt is the width of the real frame, max(w,w gt ) for w and w gt The maximum value, h is the length of the prediction box, h gt is the length of the real frame, max(h, h gt ) for h and h gt The maximum value, ω w It is the ratio of the absolute value of the difference between the width of the real box and the predicted box to the maximum value of the width of the real box and the predicted box, ω h It is the ratio of the absolute value of the difference between the height of the real box and the predicted box to the maximum value of the height of the real box and the predicted box. θ is an adjustable variable.
[0118] The expression of distance loss is:
[0119]
[0120]
[0121]
[0122]
[0123]
[0124] Where α is the angle between the line connecting the center of the real frame to the center of the predicted frame and the X-axis, σ is the distance between the center of the real frame and the center of the predicted frame, x is the sine value of α, and C w1 is the width of the minimum bounding rectangle of the real box and the predicted box, C h1 is the height of the minimum bounding rectangle of the real box and the predicted box, Cw C is the width of the rectangle constructed with the line connecting the center of the real box to the center of the predicted box as the diagonal line, h It is the height of the rectangle constructed with the line connecting the center point of the real box to the center point of the predicted box as the diagonal line, is the horizontal coordinate value of the center point of the real frame, b cx is the horizontal coordinate value of the center point of the prediction box, is the vertical coordinate value of the center point of the real frame, b cy is the vertical coordinate value of the center point of the prediction box, ∧ is the angle loss, and △ is the distance loss;
[0125] If the angle of α is greater than 45°, then α is replaced by β, β = 90° - α.
[0126] Furthermore, in this embodiment, the target ground truth boxes of the image samples are preprocessed to obtain multiple anchor boxes of fixed sizes, which is achieved by the following steps:
[0127] The K-means clustering algorithm is used to cluster the target ground truth boxes of the image samples to obtain 9 anchor boxes of fixed size. Furthermore, in this embodiment, the SIoU-NMS improved non-maximum suppression algorithm is used to filter the preliminary prediction boxes output by the image to be identified to obtain the final prediction box, which is achieved through the following steps:
[0128] Step 1: Set the confidence threshold and SIoU threshold;
[0129] Step 2: Calculate the confidence of all preliminary prediction boxes output by the network model, put the preliminary prediction boxes with confidence higher than the confidence threshold into the candidate list, and sort the preliminary prediction boxes in the candidate list in descending order from high to low according to confidence;
[0130] Step 3: Take the preliminary prediction box with the highest confidence from the candidate list, save it to the output list, and delete the preliminary prediction box from the candidate list;
[0131] Step 4: Calculate the intersection-over-union (SIoU) loss between the highest confidence preliminary prediction box obtained in the previous step and all other preliminary prediction boxes in the candidate list, and remove the preliminary prediction boxes whose SIoU loss is higher than the set SIoU threshold from the candidate list;
[0132] Step 5: Repeat steps 3 and 4 until the candidate list is empty;
[0133] Step 6: Use the preliminary prediction box in the output list as the final prediction box.
[0134] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the above methods when executing the program.
[0135] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of any of the above methods.
[0136] The prediction box is the sum of all boxes generated for each grid. After the image sample is divided into small grids, if there is a target detection object in a grid, 9 prediction boxes of different sizes will be generated with the grid as the center. During training, these 9 prediction boxes are adjusted. When the network model training is completed, the group of 9 prediction boxes with the highest accuracy will be saved. This is the prediction box obtained in the training phase.
[0137] After the image samples are input into the network model for processing, feature maps of three sizes (80*80, 40*40, and 20*20) are obtained. The prediction box is then generated in the corresponding feature map. The network model adjusts the position and size of the prediction box according to the loss function. When the network model training is completed, the anchor box parameters with the highest model accuracy are saved as the pre-acquired prediction box.
[0138] Example 2
[0139] Step 1: Construct an insulator dataset based on public and online insulator image samples:
[0140] First, data cleaning is performed on the collected insulator image samples. Data cleaning involves filtering and removing duplicate and redundant data from the image sample data, completing missing parts, and correcting or deleting incorrect data.
[0141] We then used the Labelme tool to annotate the insulator image samples in the dataset. The annotation types were categorized into three types: pollution-flashover, broken, and insulator. Each insulator image sample was outlined with a rectangular frame. After each image was annotated, a corresponding JSON file was generated. Because the network model dataset was in VOC format, we also needed to convert the label JSON file into an XML file to create the insulator dataset in the VOC format.
[0142] The above operations are completed to form the insulator image dataset;
[0143] Step 2: Divide the insulator dataset into training set, validation set, and test set:
[0144] In this example, the insulator dataset contains a total of 1,600 insulator image samples. The dataset is divided into 1,120 images as a training set, 320 images as a validation set, and 160 images as a test set in a ratio of 7:2:1.
[0145] Step 3: Construct an improved YOLOv7 convolutional neural network:
[0146] Step 3-1: Improvement of network backbone:
[0147] The network model uses an improved YOLOv7 backbone network. The CoordAtt module is added to the backbone network and added to the end of the original model's backbone structure. The CoordAtt module is implemented based on the CoordAtt attention mechanism.
[0148] Attention mechanisms can generally be divided into three categories: channel attention mechanism, spatial attention mechanism, and the combination of the two. Traditional attention mechanism modules such as SE (Squeeze-and-Excitation attention) and CBAM
[0149] The Convolutional Block Attention Module (CBAT) suffers from the tendency to lose spatial information when modeling inter-channel relationships. Other attention modules that don't suffer from this issue also work well, but they have too many parameters and are not suitable for deployment.
[0150] The CoordAtt attention mechanism can not only capture cross-channel information, but also capture direction-aware and position-aware information, which can help the model more accurately locate and identify targets of interest; secondly, the coordinateattention module is flexible and lightweight and can be added to multiple locations in the existing model.
[0151] Based on the CoordAtt attention mechanism, a CoordAtt module is constructed. A CoordAtt module can be regarded as a computing unit used to enhance the feature representation capability. Any intermediate tensor X = [x1, x2, ..., x n ]∈R C×H×W As input, it outputs an output Y=[y1, y2, ..., y n ], where n represents the number of tensors, C represents the channel, H represents the height, W represents the width, and R represents the number field.
[0152] The CoordAtt attention mechanism framework is as follows Figure 2As shown, global average pooling is first performed along the horizontal X and vertical Y directions. This average pooling preserves long-range dependencies in these two directions for channel attention. Convolution is then performed to combine these two components, effectively interacting with information in both directions. After BN and nonlinear activation, the feature map is split into two parts, each of which undergoes convolution and a Sigmoid activation function, effectively focusing on both the horizontal and vertical directions. The two feature maps output by the two Sigmoid activation functions accurately locate the row and column of the target object.
[0153] A recursive gated convolution module is introduced into the network model. The recursive gated convolution module is implemented based on recursive gated convolution (gnConv);
[0154] gnConv is built with standard convolution, linear mapping, and element-wise multiplication, but with input-adaptive spatial mixing similar to self-attention.
[0155] In the YOLOv7 backbone network, standard convolution operations are mainly used to complete image feature extraction. The improved network in this paper adds recursive gated convolution to the backbone part to improve the network's long-range attention and reduce gradient diffusion.
[0156] Its main structure is not much different from the standard CNN, except that a gating mechanism is introduced in the convolutional layer. The input is convolved to double the number of input channels, and then the feature map is split into two parts. One part is subjected to depthwise separable convolution DWConv and then split into three parts. The other part is multiplied with each part split by the depthwise separable convolution in sequence, that is, the output of a convolution layer without a nonlinear function is multiplied by the output of a convolution layer with a nonlinear activation function. Step 3-2: Optimize the loss function and prediction box screening method:
[0157] The optimized loss function includes regression and classification loss functions. The SIoU regression loss function replaces the traditional CIoU loss function, and the focal loss classification loss function replaces the traditional standard cross entropy loss function:
[0158] 1. SIoU regression loss function replaces the traditional CIoU loss function
[0159] Traditional object detection loss functions (such as GIoU, CIoU, and DIoU) consider the distance, overlap area, and aspect ratio between the predicted and true boxes, but do not consider the direction of mismatch between the desired true box and the predicted box, resulting in slow convergence. However, the SIoU regression loss function takes into account the vector angle between the desired regressions and redefines the penalty metric.
[0160] The SIoU regression loss function not only considers the traditional penalty metrics of distance, shape, and Intersection over Union (IoU) for calculating the mismatch between the ground truth box in the image sample and the model's predicted box, but also considers the matching direction angle. This consideration can greatly accelerate the training convergence process by first moving the predicted box to the nearest axis (i.e., the X-axis or Y-axis) and then performing regression along that axis.
[0161] The SIoU regression loss function consists of four parts: angle cost, distance cost, shape cost, and intersection-over-union cost.
[0162] Angle loss is considered from the perspective of the real frame and the predicted frame of the two frames. Generally, in the early stage of training, the predicted frame and the real frame of the model do not intersect. Adding angle loss can speed up the distance calculation between the two frames and make the distance between the two frames converge quickly.
[0163] The angle loss is defined as follows:
[0164]
[0165]
[0166]
[0167]
[0168] Where, ^ is the angle loss value, C h is the intermediate quantity, α is Figure 3 The angle shown is σ, which is the intermediate value. is the horizontal coordinate value of the center point of the real frame, b cx is the horizontal coordinate value of the center point of the prediction box, is the vertical coordinate value of the center point of the real frame, b cy is the vertical coordinate value of the center point of the prediction box, for and b cy The maximum value, for and b cy Minimum value;
[0169] Where α is Figure 3 When the angle α is greater than 45°, the angle loss formula is calculated by replacing α with β, that is, the angle consideration is converted from the x-axis to the y-axis. h is the height difference between the center of the predicted box and the center of the ground truth box. σ is the distance from the center of the ground truth box to the center of the predicted box. is the coordinate value of the center point of the real frame, (b cx ,bcy ) is the coordinate value of the center point of the prediction box.
[0170] The distance loss is defined as follows:
[0171]
[0172] Where △ is the distance loss, ^ is the angle loss, C w1 is the width of the minimum bounding rectangle of the real box and the predicted box, C h1 is the height of the minimum bounding rectangle of the real box and the predicted box, C w C is the width of the rectangle constructed with the line connecting the center of the real box to the center of the predicted box as the diagonal line, h It is the height of the rectangle constructed with the line connecting the center point of the real box to the center point of the predicted box as the diagonal.
[0173] As can be seen from the formula, the model makes the center point of the predicted box parallel to the center point of the real box, and then continues to approach along the relevant axis. Taking the X axis as an example, when the two boxes are almost parallel, the α angle is very close to 0, and the angle loss is approximately equal to 0, so the contribution of the distance loss between the two boxes to the overall loss is reduced. However, when the α angle approaches 45°, the calculated angle between the two boxes is 1, and the proportion of the distance loss between the two boxes to the total loss increases. If α is less than or equal to During the loss convergence process, α will be minimized first, otherwise β will be minimized.
[0174] The shape loss is defined as follows:
[0175] The shape loss considers the length and width of the two boxes. The shape loss formula is as follows:
[0176]
[0177]
[0178] Where Ω is the shape loss value, ω w It is the ratio of the absolute value of the difference between the width of the real box and the predicted box to the maximum value of the two box widths, ω h It is the ratio of the absolute value of the difference between the height of the real box and the predicted box to the maximum value of the height of the two boxes, max(w,w gt ) for w and w gt The maximum value, max(h, h gt ) for h and h gt The maximum values, w and w gt The widths of the predicted box and the real box, h and h respectively gt are the lengths of the predicted box and the true box, respectively. θ is an adjustable variable to indicate the importance of the shape loss function to the total loss. In this invention, θ is set to 4.
[0179] The traditional CIoU loss function converges the function based on the overall shape of the two boxes, while the SIoU regression loss function converges the length and width to achieve the overall shape convergence effect.
[0180] like Figure 4 As shown, the formula for the intersection-over-union loss is as follows:
[0181]
[0182] Where A is the real box, B is the predicted box, and IoU is the ratio of the intersection and union between the real box and the predicted box;
[0183] The intersection-over-union loss is expressed by calculating the ratio of the intersection and union between the true box and the predicted box.
[0184] Finally, combining the above four parts, the regression loss function is:
[0185] 2. Replace the traditional standard cross entropy loss function with the focal loss classification loss function:
[0186] The focal loss function can address the imbalance between positive and negative samples in object detection. Weights are assigned to the loss corresponding to each image sample based on the difficulty of distinguishing the sample, with smaller weights assigned to easily distinguishable samples and larger weights assigned to difficult-to-distinguish ones.
[0187] The formula of the focal loss classification loss function is as follows:
[0188] L cls =-ζ t (1-p t ) δ log(p t )
[0189] in
[0190] Where, L cls is the classification loss value, y takes the value of 1 and -1, t represents the current input and has no special meaning, p t is the probability of belonging to positive and negative samples, ζ t is the weight parameter for positive and negative samples, y = 1 represents the foreground of the image sample, y = -1 represents the background of the image sample, p is the probability that the network model predicts that the image sample belongs to the foreground (target), and the value range of p is 0-1. ζ is a weight parameter introduced to solve the imbalance of sample categories. In order to allow the model to distinguish between simple and difficult samples, the loss function focuses on the training of difficult samples. Therefore, the adjustment factor (1-p t )δ and adjustable aggregation parameters δ, in this case ζ = 0.25, δ = 1.5.
[0191] The expression of the total loss function is:
[0192] L=W1×L box +W2×L cls +W3×L obj
[0193]
[0194] L cls =-ζ t (1-p t ) δ log(p t ),
[0195]
[0196] Where L is the total loss, L box is the boundary regression loss, L obj is the target confidence loss, W1 is the weight of boundary regression loss in the total loss, W2 is the weight of focal loss classification loss in the total loss, W3 is the weight of target confidence loss in the total loss, IoU is intersection over union loss, Ω is shape loss, and △ is distance loss;
[0197] Step 3-3: Get the Anchor Box priori box size:
[0198] The k-means clustering algorithm is used to cluster 9 prior boxes suitable for the insulator size.
[0199] The YOLOv7 network has nine anchor priors. To reduce the difficulty of fine-tuning the network model's priors to the actual box positions and eliminate the subjectivity of anchor settings, YOLOv7 performs a K-means cluster analysis on the bounding boxes annotated in the training set to find a priori box size that closely matches the training set.
[0200] The K-means clustering method is used to automatically generate the anchor size. When using 5 anchors, the accuracy of using 9 anchors in FasterRCNN can be achieved, which shows that the effect has been greatly improved.
[0201] The distance metric function and cluster centers are the core of the K-means clustering algorithm. If the traditional Euclidean distance is used as the distance function for clustering, large-sized boxes will produce larger errors than small-sized boxes. Because the purpose of clustering is to improve the Intersection over Union (IoU) score, which depends on the size of the box, the distance metric function for the anchor clustering sample is defined as:
[0202] d(box,centroid)=1-IoU(box,centroid)
[0203] IoU is the intersection over union (IoU) of the anchor (predicted box) and the groundtruth (real box). The centroid is the box chosen as the center during clustering, the box is the other box, and d is the "distance" between the two. The larger the IoU, the closer the "distance", indicating that the two boxes are of similar size.
[0204] Because the 9 prior frames of yolov7 before the improvement are the prior frame sizes clustered on a large public dataset, before training, based on the real frames of the image samples in the training set of this invention, 9 anchor frames arranged in ascending order of size are obtained a priori through the k-means clustering algorithm. The results obtained are {(13,12),(21,21),(39,31),
[0205] (135,131),(65,326),(101,304),(430,112),(188,324),(393,266)}.
[0206] The first three anchor frames correspond to the 80×80 feature map output by the last Head part, which is responsible for detecting small-sized targets; the middle three anchor frames correspond to the 40×40 feature map, which is responsible for detecting medium-sized targets; the last three anchor frames correspond to the 20×20 feature map, which is responsible for detecting large targets in the image.
[0207] Step 3-4: Improve NMS non-maximum suppression:
[0208] The NMS algorithm flow chart is as follows Figure 5 As shown in the figure, the traditional method of calculating IoU has certain defects. For example, using the traditional NMS to filter the prediction box will accidentally delete some occluded targets and cause missed detections.
[0209] The improved approach of this invention is to incorporate object scale and distance into the IoU calculation. SIoU is used to calculate the IoU value between the highest confidence candidate box and all other boxes. Based on a set confidence threshold, it is used to determine whether to remove candidate boxes with a confidence value greater than the set confidence threshold. This can solve the problem of insulator occlusion and insulators being too close together.
[0210] Step 3-5: Complete network construction:
[0211] like Figure 6 As shown, the YOLOv7 network model includes:
[0212] The CBS module consists of a convolutional layer, a BN normalization layer and a SiLu activation function.
[0213] The ELAN module consists of 6 CBS modules, each of which includes a splicing operation. The modules included in ELANC are the same as those in ELAN, except that the forward path of the splicing is different.
[0214] The MP layer is mainly divided into the maximum pooling layer and three CBS modules, among which the MP1 module and the MP2 module mainly change the ratio of the number of channels.
[0215] The Upsampling module consists of a CBS module and an upsampling module.
[0216] RepC is a heavily parameterized structure consisting of three CBS modules and two BN normalizations.
[0217] The Cat module is a tensor concatenation operation that expands the dimension of the tensor.
[0218] add is tensor addition, tensors are added directly without expanding the dimension.
[0219] The SPPCSP module is implemented based on SPPCSP.
[0220] SpatialPyramidPoolingCrossStagePartialNetwork Spatial pyramid pooling across stage partial networks.
[0221] The structure of the entire network model is divided into four parts: Input module, Backbone module, Neck module and Head module.
[0222] The input module performs a series of data augmentation operations on the image, including mosaicing, random cropping, and scaling, to prevent overfitting. The original input images vary in size and must all be resized to 640x640 before being fed into the backbone network.
[0223] The Backbone module primarily consists of the CBS module, the MP module, and the ELAN module. The CBS module consists of a convolution, a batch normalization (BN), and an activation function. Unlike traditional CNNs, the activation function is SiLU instead of LeakyReLU. The ELAN module, a network module proposed by YOLOv7, controls the shortest and longest gradient paths, enabling efficient learning and convergence in deeper networks. The ELAN module is also composed of several CBS modules. The feature map size remains unchanged, with only the final CBS module changing the number of output channels. The MP module consists of the Maxpooling and CBS modules.
[0224] The improved network model adds a gnConv recursive convolution between the third and fourth CBS modules in the backbone part. After the network passes through the third CBS module, the feature map size is reduced by nearly half, and the feature information will be greatly reduced. Therefore, adding recursive convolution can retain nonlinear capabilities, establish long-range attention, reduce gradient diffusion, and improve target detection effects, which is beneficial for detecting small targets such as insulator defects.
[0225] The improved network incorporates a CoordAtt attention mechanism between the Backbone and Neck components. This mechanism not only captures cross-channel information but also captures directional and positional information, helping the model accurately locate and identify objects of interest.
[0226] The Neck module consists of a path aggregation network (PAN) and a feature pyramid network (FPN). The 32x downsampled feature map output by the backbone is processed through SPPCSP, reducing the number of channels from 1024 to 512. Feature fusion is performed first using a top-down strategy and then a bottom-up strategy. The PA-FPN structure efficiently fuses feature maps from different layers. Compared to YOLOv5, YOLOv7 replaces the CSP module with the ELANC module and downsamples to the MP2 layer.
[0227] After passing through the PAFPN network, the network outputs three layers of feature maps of varying sizes. The head part passes through RepC and Conv to output the prediction results. The meaning of 20×20×(3+5)×3 is as follows: 20×20 represents dividing the final feature map into 400 small squares; the 3 in 3+5 represents the three categories output by the insulator dataset; 5 represents the coordinates of the center point of the prediction box, the length and width of the prediction box, and the confidence level of belonging to a certain category, so 3+5; plus, since there are three prediction boxes in a small square, multiply by 3. 40×40×(3+5)×3 and 80×80×(3+5)×3 have similar meanings, except that the feature map sizes differ.
[0228] Step 4: Train and improve the YOLOv7 convolutional neural network;
[0229] Software and hardware configuration parameters of the present invention:
[0230] Table 1 Software and hardware parameter configuration table
[0231]
[0232]
[0233] Before formally training the network model, some hyperparameters must be initialized:
[0234] The learning rate is a very important hyperparameter that directly affects the speed and convergence of network model training. Typically, before network model training begins, weights are randomly initialized. Setting a learning rate that is too high can cause severe oscillations in the network model, while setting a learning rate that is too low can lead to slow convergence. You can set a lower learning rate for the first few rounds of training by setting a warmup value, then increasing it after training becomes more stable. In this example, the learning rate is set to 0.01 and the warmup value is set to 3.
[0235] If the batch size is too large, there will be problems with the optimization and generalization of the network model. If it is too small, the gradient value may fluctuate greatly during training due to the small amount of data. In this example, it is set to 8.
[0236] The number of training rounds epochs is the number of training rounds for the network model. In this example, it is set to 50.
[0237] To increase target diversity and improve the detection and classification accuracy of the network model, we enhanced the image samples through pasting, cropping, mosaicing, affine transformation, and color space conversion. Setting hsv_h = 0.015, hsv_s = 0.7, and hsv_v = 0.4 in the code controls the hue (fraction), saturation (fraction), and brightness (fraction) of each image. After the parameters are set, to shorten training time, you can load some pre-trained weights for training. YOLOv7 provides several pre-trained weights, and different versions can be selected for training according to different needs. This model uses the pre-trained weights yolov7.pt.
[0238] Finally, the parameters are tuned according to the training results until the optimal training model results are obtained, and the optimal model weight results are saved.
[0239] In the early stages of network model training, you can check the effectiveness of the model using the validation set.
[0240] After the first epoch is completed, you can see the labels of the test batch0 ground truth values and the labels of the model prediction values, as follows Figure 7 As shown, it can be seen that the network model can well identify the target in the picture in the early stage;
[0241] After network model training is complete, feature maps of the trained network model are visualized, showing the feature maps output by each intermediate layer after processing by the network model. This allows us to see which aspects of the input image the network model focuses on, further understand the role of convolution, whether the added attention mechanism is effective, and whether the improved network model's feature extraction process focuses more on the characteristics of the target object.
[0242] Figure 9 The figure shows the feature maps of the first convolution module after visualization, the feature map after the Backbone module, and the feature maps output by the three Dectect detectors during the detect inference process using the trained network model. This figure only lists the feature maps of the first 12 channels, and does not visualize all the feature maps.
[0243] It can be seen that the features extracted from the first 12 feature maps after the first convolution are almost different. Some focus on edges, while others focus on the whole. Of course, this is only the feature map after the first convolution. Compared with deeper features, shallow features are mostly complete, and the features of deeper networks will be smaller.
[0244] The feature maps output by Backbone show that the addition of the attention mechanism effectively enhances the extracted feature maps and suppresses unnecessary features. Since the insulators in the images in the dataset are generally large and relatively easy to detect, the addition of the attention mechanism helps the neural network focus on more high-level semantic information, significantly improving both precision and recall.
[0245] The features output by the three Detect detectors correspond to the detection of three types of targets: large, medium and small. The Detect1 detector obviously extracts low-semantic information, which is more conducive to the detection of small targets, while the feature map of the Detect3 detector focuses more on some high-semantic information and is suitable for detecting large targets.
[0246] like Figure 11 As shown in the figure, after detecting an object, the network model still needs to perform classification. To understand which local locations in the original image led the model to the final classification decision, a heat map is generated for the input image. This intuitively shows that the network model "sees" the characteristics of the insulator, which leads to the conclusion that an insulator is present in the image, and "sees" the characteristics of the flashover, which leads to the conclusion that the image sample contains flashover. The heat map also shows that the network model does not focus on all features, but rather on the features in the image that we need to detect the object. It can be seen that the improved algorithm can effectively extract target feature information in the insulator image.
[0247] The following is a comparison of the evaluation indicators of YOLOv7 and the improved YOLOv7 algorithm:
[0248] First, we introduce common evaluation metrics.
[0249] Common evaluation metrics include accuracy, confusion matrix, recall, average precision (AP), mAP, precision-recall (PR) curve, etc. These metrics are understood and calculated using the confusion matrix, which is shown in Table 2.
[0250] Table 2 Confusion matrix
[0251]
[0252] TP represents a correct detection, where the model predicts a positive result and the actual result is also positive; FN represents a false detection, where the model predicts a negative result and the actual result is positive; FP represents a false detection, where the model predicts a positive result and the actual result is negative; TN represents a correct detection, where the model predicts a negative result and the actual result is also negative.
[0253] 1. Precision:
[0254]
[0255] Precision is used to measure the probability that a positive sample classified by a classifier is indeed a positive class, that is, to evaluate the accuracy of the network model's prediction.
[0256] 2. Recall:
[0257]
[0258] The recall rate is used to measure whether a classifier can find all positive samples, that is, to evaluate whether the prediction of the network model is complete.
[0259] 3. mAP_0.5
[0260] Average Precision (AP) is the area enclosed by the curves plotted against Precision and Recall and the coordinate axes. Generally, a larger area indicates better classifier performance. mAP is the average of the AP values across multiple categories; a larger value is better. The number following the _ indicates the Intersection over Union (IoU) threshold. For example, mAP_0.5 calculates the AP for all images in each category when the IoU is set to 0.5, then averages the AP across all categories to obtain the mAP.
[0261] Compare algorithms based on indicators. Figure 11 The comparison of the accuracy before and after the improvement shows that the improved YOLOv7 network model is significantly better than the original one; Figure 12 The comparison of recall rates before and after the improvement shows that the improved YOLOv7 network model is significantly better than the original one; Figure 13 The mAP_0.5 comparison before and after the improvement shows that the improved YOLOv7 network model is significantly better than the original one; Figure 14 and Figure 15 Comparing the PR curves before and after the improvement, we can see that the improved YOLOv7 network model is significantly better than the original one;
[0262] The better the classifier's performance, the more the PR curve bulges upward and to the right, and the larger the area enclosed by the coordinate axis. The precision-recall curves for YOLOv7 and the improved ones are shown in the figure. For both the PR curves for all categories and for any one category, the area enclosed by the improved detection curve and the coordinate axis is larger than that before the improvement. Therefore, it can be said that the proposed algorithm has better classification performance.
[0263] Table 3
[0264]
[0265] Table 3 compares the performance of the improved algorithms before and after the improvements. As can be seen, the improved model improves precision by 3.4%, recall by 3.8%, and mAP_0.5 by 5.9%. This significant increase in recall demonstrates that the improved model has significantly enhanced its ability to correctly classify positive samples. The increases in mAP at different IoU thresholds demonstrate that the improved model more accurately locates objects.
[0266] Step 5: Use the optimal model saved after training to detect the insulator image test set:
[0267] Input the insulator image in the test set into the final saved YOLOv7 model to test the model's target recognition ability and analysis results:
[0268] After model training, the best weights will be saved in best.pt. The best weights will be loaded and run through the detect script to output the detection results.
[0269] like Figure 16-23 As shown in the figure, in order to verify the generalization ability and robustness of the network model of the present invention, several pictures of the object to be tested and the background that are very similar are specially selected to increase the detection difficulty. Through comparative analysis, the improved algorithm can better identify small target defects of insulators and can also accurately identify some overlapping insulator targets.
[0270] Deployment test, deploy YOLOv7 on the development platform:
[0271] Convert YOLOv7's best.pt to an onnx file, and use the onnx file as an intermediate model to convert it into the corresponding network model.
[0272] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0273] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0274] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0275] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. The insulator defect detection method based on improved YOLOv7 is characterized by: include: The image to be identified is fed into a pre-trained network model. Based on the pre-obtained prediction frames, the network model outputs multiple preliminary prediction frames of the image to be identified that are the same size as the prediction frames. The SIoU-NMS improved non-maximum suppression algorithm is used to filter the preliminary prediction frames output by the image to be identified to obtain the final prediction frame. Based on the final prediction frame, the defect type of the image to be identified is obtained. The network architecture of the constructed network model includes an Input module, a Backbone module, a Neck module, and a Head module, which are connected in sequence; the Backbone module includes a first CBS module, a second CBS module, a third CBS module, a fourth CBS module, a gnConv module, a first ELAN module, a second ELAN module, a third ELAN module, a fourth ELAN module, a first MP1 module, a second MP1 module, a third MP1 module, and a CoordAtt module, which are connected in sequence; The first, second, third, and fourth CBS modules are all CBS modules, the first, second, third, and fourth ELAN modules are all ELAN modules, and the first, second, and third MP1 modules are all MP1 modules. The gnConv module uses recursive gated convolution, and the CoordAtt module uses the CoordAtt attention mechanism. The SIoU-NMS improved non-maximum suppression algorithm is used to filter the preliminary prediction box output of the image to be identified to obtain the final prediction box, which is achieved by the following steps: Step 1: Set the confidence threshold and SIoU threshold; Step 2: Calculate the confidence of all preliminary prediction boxes output by the network model, put the preliminary prediction boxes with confidence higher than the confidence threshold into the candidate list, and sort the preliminary prediction boxes in the candidate list in descending order from high to low according to confidence; Step 3: Take the preliminary prediction box with the highest confidence from the candidate list, save it to the output list, and delete the preliminary prediction box from the candidate list; Step 4: Calculate the intersection-and-union loss of the preliminary prediction box with the highest confidence obtained in the previous step and all other preliminary prediction boxes in the candidate list, and delete the preliminary prediction box with an intersection-and-union loss higher than the set SIoU threshold from the candidate list; Step 5: Repeat steps 3 and 4 until the candidate list is empty; Step 6: Take the preliminary prediction box in the output list as the final prediction box.
2. The insulator defect detection method based on improved YOLOv7 according to claim 1 is characterized in that: The network model is pre-trained and implemented through the following steps: Obtain a training set, which includes image samples and target ground truth boxes of the image samples; Preprocess the target ground truth box of the image sample to obtain multiple anchor boxes of fixed size; Build a network model, input image samples and fixed-size anchor boxes into the network model, and the network model divides the image samples into multiple grids; Based on the fixed-size anchor boxes, multiple fixed-size prediction boxes are generated with each grid as the center; Use the total loss function to calculate the difference between the target true box of the image sample and the fixed-size prediction box, and iteratively update the network parameters of the network model, the position of the prediction box, and the size of the prediction box; If the total loss function converges to a constant value, stop the iteration and output the final network model.
3. The insulator defect detection method based on improved YOLOv7 according to claim 2, characterized in that: Pre-acquisition of prediction boxes is achieved through the following steps: Filter the prediction boxes with the highest accuracy obtained by the network model during training as the pre-acquired prediction boxes.
4. The insulator defect detection method based on improved YOLOv7 according to claim 2, characterized in that: The expression of the total loss function is: L = W1 × L box +W2×L cls +W3×L obj L cls =-ζ t (1-p t ) δ log(p t ), Where L is the total loss, L box is the boundary regression loss, L obj is the target confidence loss, W1 is the weight of boundary regression loss in the total loss, W2 is the weight of focalloss classification loss in the total loss, W3 is the weight of target confidence loss in the total loss, IoU is intersection over union loss, Ω is shape loss, △ is distance loss; L cls is the focalloss classification loss, ζ t is the positive and negative sample weight parameter, p t is the probability of belonging to positive and negative samples, δ is an adjustable aggregation parameter, p is the probability that the network model predicts that the image sample belongs to the foreground, Y = 1 represents the foreground of the image sample, Y = -1 represents the background of the image sample, and ζ is the weight parameter.
5. The insulator defect detection method based on improved YOLOv7 according to claim 4, characterized in that: The expression of intersection-over-union loss is: Where A is the real box, B is the predicted box, and IoU is the intersection-over-union loss. The expression of shape loss is: Where Ω is the shape loss, w is the width of the prediction box, and w gt is the width of the real frame, max(w,w gt ) for w and w gt The maximum value, h is the height of the prediction box, h gt is the height of the real frame, max(h, h gt ) for h and h gt The maximum value in θ is an adjustable variable; the expression of distance loss is: Where α is the angle between the line connecting the center of the real frame to the center of the predicted frame and the X-axis, σ is the distance between the center of the real frame and the center of the predicted frame, x is the sine value of α, and C w1 is the width of the minimum bounding rectangle of the real box and the predicted box, C h1 is the height of the minimum bounding rectangle of the real box and the predicted box, C w C is the width of the rectangle constructed with the line connecting the center of the real box to the center of the predicted box as the diagonal line, h It is the height of the rectangle constructed with the line connecting the center point of the real frame to the center point of the predicted frame as the diagonal line, is the horizontal coordinate value of the center point of the real frame, b cx is the horizontal coordinate value of the center point of the prediction box, is the vertical coordinate value of the center point of the real frame, b cy is the vertical coordinate value of the center point of the prediction box, ^ is the angle loss, and △ is the distance loss. If the angle of α is greater than 45°, α is replaced by β, β = 90° - α.
6. The insulator defect detection method based on improved YOLOv7 according to claim 1, characterized in that: Preprocess the target true boxes of the image samples to obtain multiple fixed-size anchor boxes, which is achieved by the following steps: Use the K-means clustering algorithm to cluster the target true boxes of the image samples to obtain multiple fixed-size anchor boxes.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the method according to any one of claims 1 to 6 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Insulator defect detection method based on improved YOLOv5 convolutional neural network
CN112819804A
PCB surface defect detection method based on improved YOLOv5 algorithm
CN114372949A