Ox horn capacitor bushing polarity detection method and system based on YOLO
By improving the YOLOv8 model, integrating the CBAM attention module and efficient ladder pyramid structure, the problems of low recognition rate of horn capacitance detection and complex model training are solved, and efficient and accurate horn capacitance detection effect is achieved.
Patent Information
- Application Number
- CN202411293097.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-01-07
AI Technical Summary
In the prior art, the recognition rate of the horn capacitance detection is low, the real-time requirements are high, and the model training is complex, making it difficult to effectively process video stream data.
The improved YOLOv8 model is adopted, the CBAM attention module is integrated, the PANet is modified to efficient ladder pyramid EPS, and the loss function CIOU is modified to MPDIOU, combining video stream preprocessing and CutMix algorithm to improve detection accuracy and efficiency.
It improves the accuracy and efficiency of cattle horn capacitance detection, enhances the detection performance of small and multi-scale targets, simplifies bounding box regression calculation, and improves detection positioning accuracy and convergence speed.
Smart Images

Figure CN119274034A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of horn capacitor printing, and in particular to a method and system for detecting polarity of a horn capacitor sleeve based on YOLO. Background Art
[0002] With the rapid development of the manufacturing industry and the improvement of product quality requirements, the role of quality inspection in industrial production is becoming more and more important. However, the traditional manual inspection method is gradually being eliminated due to its low efficiency, the influence of subjective factors and the high cost. In contrast, the detection algorithm based on convolutional neural network (CNN) shows superior performance, thanks to its powerful feature extraction ability, which is better than the traditional machine vision algorithm. Therefore, the present application provides a horn capacitor polarity detection algorithm based on CNN.
[0003] Among many target detection methods, the YOLO series detectors have been widely used in the industrial field due to their simple and efficient design. However, unlike natural object detection, the detailed information of printed materials is crucial for accurate classification and positioning. Since general target detectors are mainly designed for structured natural objects, they may perform poorly when dealing with detection tasks. Therefore, this new road detection algorithm in the prior art (the "Improved YOLOv8 Road Defect Detection Algorithm" published in the journal "Qilu University of Technology" in June 2024) is based on YOLOv8. By adding the MPCA attention mechanism, proposing the C2f-MPDC module, and redesigning the network neck structure and detection head, the detection accuracy and efficiency are improved, while the model size is reduced. Although the algorithm has improved detection accuracy and efficiency, the introduction of multiple custom components increases the complexity of model training, requiring more sophisticated hyperparameter tuning and longer training time. In addition, in application scenarios with extremely high real-time requirements, its latency is high.
[0004] The patent document with publication number CN116012354A discloses a method, device, equipment and storage medium for detecting screen printing defects of chip capacitors. The patent document proposes a method for detecting screen printing defects of chip capacitors. The method uses the YOLOV5 model for training to obtain a target model for detecting defects in capacitor electrodes, and applies the model to perform real-time defect detection during the production process to achieve quality control and improve production efficiency. Despite this, the patent document only considers image samples and does not consider the processing of video streams. In addition, the yolov5 version is slightly less accurate than yolov8, and its accuracy is even lower than the improved yolov8 model in this application. Summary of the invention
[0005] In view of the defects in the prior art, the object of the present invention is to provide a method and system for detecting polarity of a horn capacitor bushing based on YOLO.
[0006] According to the present invention, a method for detecting polarity of a horn capacitor bushing based on YOLO includes the following steps:
[0007] Dataset construction steps: Preprocess the horn capacitance detection video to obtain the dataset;
[0008] Model optimization steps: optimize the YOLO detection model and build a target detection model;
[0009] Training iteration step: Iterate the training of the target detection model through the dataset;
[0010] Detection and judgment steps: Use the target detection model after training iteration to detect the horn capacitor detection video to determine whether the printing of the horn capacitor is wrong.
[0011] Preferably, the data set construction step specifically includes the following steps:
[0012] Step 1.1: Divide the horn capacitor detection video into video frames that do not contain horn capacitors and video frames that contain horn capacitors to obtain a horn capacitor dataset, annotate the horn capacitor dataset, and use the CutMix algorithm to perform image enhancement on the annotated horn capacitor dataset;
[0013] Step 1.2: Divide the image-enhanced horn capacitance dataset into a training dataset, a validation dataset, and a test dataset according to a preset ratio.
[0014] Preferably, the step 1.1 specifically includes the following steps:
[0015] Step 1.1.1: Select video frames containing horn capacitors from the video frames of the horn capacitor detection video, generate multiple images, form a reference image group, use the clip model to process the reference image group, and obtain the corresponding feature vector;
[0016] Step 1.1.2: Traverse the entire horn capacitance detection video, encode each video frame, and convert it into a feature vector, and calculate the cosine similarity between the feature vector of each video frame and each feature vector in the reference image group;
[0017] Step 1.1.3: Set a preset threshold of cosine similarity, and determine whether the cosine similarities between the feature vector of the video frame and all feature vectors in the reference image group are greater than the preset threshold. If so, the video frame is determined to be a video frame containing a cow-horn capacitor. If not, the video frame is determined to be a video frame not containing a cow-horn capacitor.
[0018] Preferably, the model optimization step is specifically as follows:
[0019] Integrate the CBAM attention module into the YOLOv8 detection model;
[0020] Modify the neck part of the YOLOv8 detection model and change PANet to step pyramid EPS;
[0021] The loss function CIOU in the YOLOv8 detection model is modified to the loss function MPDIOU.
[0022] Preferably, a CBAM attention module is inserted into the CSPLayer of the backbone network of the YOLOv8 detection model to form a CBAM-CSPL residual structure;
[0023] The CBAM-CSPL residual construction includes two branch paths: one branch path is the trunk path, which is formed by stacking multiple Bottleneck unit residual structures n times, and each Bottleneck unit is a residual structure; the other branch is the residual edge path, which performs convolution operations; the trunk path and the residual edge path are merged through the concat operation and the result is output;
[0024] The CBAM attention module is embedded between two convolutional layers in the Bottleneck structure.
[0025] Preferably, the CBAM attention module consists of two sub-modules executed sequentially: a channel attention module CAM and a spatial attention module SAM;
[0026] The process formula of the CBAM attention module is:
[0027]
[0028] Input feature F∈R C*H*W , R represents a real number, C represents the number of image channels, H represents the height of the image, and W represents the width of the image. The one-dimensional convolution M of the channel attention module CAM is performed. c ∈R C*1*1 , multiply the convolution result by the original image as the output result F, of the channel attention module CAM;
[0029] Take the output result F of the channel attention module CAM as input and perform the two-dimensional convolution M of the spatial attention module SAM s ∈R 1*H*W ,Then multiply the convolution result by F, as the output result F,,of the spatial attention module SAM;
[0030] The process formula of the channel attention module CAM is:
[0031]
[0032] Among them, σ represents the activation function, MLP is the multi-layer perceptron module, and W0 and W1 are the learnable weights of MLP. They represent average pooling and maximum pooling respectively. The input feature map is diverted and processed through two parallel pooling layers: one layer is the MaxPool layer, and the other layer is the AvgPool layer. Through the two pooling operations, the feature map of the original size of C*H*W is compressed to the size of C*1*1, and each channel is pooled to obtain the global features of each channel;
[0033] The compressed data is input into the MLP module, which is a multi-layer perceptron module. In the MLP module, first, the number of channels of the data is compressed to 1 / r of the original number of channels through a fully connected layer, where r is the compression rate. Then, the number of channels of the data is expanded back to the original number of channels through another fully connected layer.
[0034] The data processed by the MLP module is activated by the ReLU activation function to obtain two activated feature vectors. The two feature vectors are added element by element to fuse the feature information obtained by different pooling methods. The result of the addition is activated by a sigmoid activation function to generate a weight vector with the same number of original channels. The weight vector is used as the output result of the channel attention module CAM.
[0035] Multiply the weight vector by the original feature map channel by channel, adjust the importance parameter of each channel, and strengthen the model's attention parameter to key features;
[0036] After being processed by the above CBAM attention module, the output feature map maintains the original C*H*W size and carries the optimized channel weight information;
[0037] The process formula of the spatial attention module SAM is:
[0038]
[0039] In the formula, f 7×7 Indicates that the convolution kernel size is 7×7, They represent average pooling and maximum pooling respectively. The output results of the channel attention module CAM are applied with maximum pooling and average pooling respectively to generate two feature maps of size 1*H*W. The two feature maps are concatenated through the Concat operation and then converted into a single-channel feature map through a 7*7 convolution layer. The feature map is processed by the sigmoid function to obtain the feature map of the spatial attention module SAM. As the output result of the spatial attention module SAM, the output result is multiplied by the original image and restored to the size of C*H*W.
[0040] Preferably, the structure of the stepped pyramid EPS is horizontally connected on the basis of PANet, and the information in two directions is aggregated into a CSP module for calculation, the result of the bidirectional structure is achieved by relying on the parameters of the unidirectional structure, and the activation function Mish of each node is replaced by the activation function HardSwish.
[0041] Preferably, the formula of the loss function MPDIOU is as follows:
[0042]
[0043] in, are the coordinates of the prediction box, are the coordinates of the real frame, x1 and y1 are the coordinates of the upper left corner, x2 and y2 are the coordinates of the lower right corner, h and w are the height and width of the original image, and IoU is intersection over union.
[0044] The formula of the loss function CIOU is as follows:
[0045]
[0046] Among them, w gt and h gt Indicates the width and height of the real box, w prd and h prd represents the width and height of the prediction box, ρ(B gt ,B prd ) represents the Euclidean distance between the center coordinates of the real box and the predicted box, and C is the diagonal distance of the smallest box enclosing them.
[0047] Preferably, in the detection and judgment step, after the ox-horn capacitor detection video is processed by the target detection model, the coordinates of the cathode, the coordinates of the anode, the coordinates of the cathode identifier, the coordinates of the center of the circle, and the detection frame position and category information of the ox-horn capacitor outer frame are obtained, and the angle of the cathode-anode line and the line connecting the center of the circle-cathode identifier is calculated, and whether the printing of the ox-horn capacitor is wrong is judged according to the calculation results.
[0048] The present invention also provides a YOLO-based horn capacitor bushing polarity detection system, comprising the following modules:
[0049] Dataset construction module: pre-process the horn capacitance detection video to obtain the data set;
[0050] Model optimization module: optimizes the YOLO detection model and builds a target detection model;
[0051] Training iteration module: iterates the training of the target detection model through the data set;
[0052] Detection and judgment module: The target detection model after training iteration is used to detect the horn capacitor detection video to determine whether the printing of the horn capacitor is wrong.
[0053] Compared with the prior art, the present invention has the following beneficial effects:
[0054] 1. The present invention proposes an improved Yolo network and applies it to the printed detection video of horn capacitors. The improved Yolo network integrates the CBAM attention mechanism on the basis of the original Yolov8, improves PANet into the efficient step pyramid ESP, and modifies the loss function CIoU into MPDIoU. By adopting the improved Yolov8 structure, the problem of low recognition rate of horn capacitor detection is solved, thereby achieving the effect of accurate detection of horn capacitors.
[0055] 2. By adopting the CBAM attention mechanism, the present invention can solve the problem of inaccurate recognition of key features in Yolo, thereby improving the accuracy and efficiency of target detection. The CBAM attention mechanism can help the Yolo model focus more on the key areas and features in the image, thereby improving the detection performance of the model.
[0056] 3. The present invention solves the problem of insufficient feature fusion in multi-scale target detection by adopting the structure of an efficient stepped pyramid ESP, thereby achieving the effect of improving the detection performance of small targets and multi-scale targets. The efficient stepped pyramid ESP can effectively fuse features at different levels, thereby enhancing the model's perception ability for targets of different sizes and improving the accuracy and stability of detection.
[0057] 4. The present invention solves the problem of low accuracy in bounding box regression calculation by adopting the MPDIoU structure, thereby achieving the effect of improving target detection positioning accuracy and convergence speed. MPDIoU not only comprehensively considers factors such as center point distance and aspect ratio, but also simplifies the calculation process, allowing the model to converge faster while improving the positioning accuracy of the detection box.
[0058] 5. The present invention solves the problem of data classification and labeling in horn capacitor detection videos by adopting a video stream preprocessing structure, thereby achieving the effect of improving data quality and diversity and accurately identifying video frames containing horn capacitors. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0060] Figure 1 It is a flowchart of the steps of the polarity detection method of the horn capacitor bushing based on YOLO;
[0061] Figure 2 Schematic diagram of the framework structure of the CBAM attention module;
[0062] Figure 3 Schematic diagram of the framework structure of the channel attention module;
[0063] Figure 4 Schematic diagram of the framework structure of the spatial attention module;
[0064] Figure 5 This is a schematic diagram of the operation interface of the horn capacitor bushing polarity detection system based on YOLO. DETAILED DESCRIPTION
[0065] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0066] Embodiment 1:
[0067] like Figures 1 to 5 As shown, this embodiment provides a method for detecting polarity of a horn capacitor bushing based on YOLO, comprising the following steps:
[0068] Dataset construction steps: Preprocess the horn capacitance detection video to obtain the data set; the data set construction steps specifically include the following steps:
[0069] Step 1.1: Divide the horn capacitor detection video into video frames that do not contain horn capacitors and video frames that contain horn capacitors to obtain a horn capacitor dataset, annotate the horn capacitor dataset, and use the CutMix algorithm to perform image enhancement on the annotated horn capacitor dataset;
[0070] Step 1.1 specifically includes the following steps:
[0071] Step 1.1.1: Select video frames containing horn capacitors from the video frames of the horn capacitor detection video, generate multiple images, form a reference image group, use the clip model to process the reference image group, and obtain the corresponding feature vector; the video frames containing horn capacitors need to be manually selected;
[0072] Step 1.1.2: Traverse the entire horn capacitance detection video, encode each video frame, and convert it into a feature vector, and calculate the cosine similarity between the feature vector of each video frame and each feature vector in the reference image group;
[0073] Step 1.1.3: setting a preset threshold of cosine similarity, determining whether the cosine similarities between the feature vector of the video frame and all feature vectors in the reference image group are greater than the preset threshold; if so, the video frame is determined to be a video frame containing a horn capacitor; if not, the video frame is determined to be a video frame not containing a horn capacitor;
[0074] Step 1.2: Divide the image-enhanced horn capacitance dataset into a training dataset, a validation dataset, and a test dataset according to a preset ratio; the training set and the validation set are used for model training iterations, and the test set is used to test the effect of the trained model.
[0075] Model optimization steps: optimize the YOLO detection model and build a target detection model;
[0076] The model optimization steps are as follows:
[0077] Integrate the CBAM attention module into the YOLOv8 detection model;
[0078] Modify the neck part of the YOLOv8 detection model and change PANet to step pyramid EPS;
[0079] Change the loss function CIOU in the YOLOv8 detection model to the loss function MPDIOU;
[0080] Insert the CBAM attention module into the CSPLayer of the backbone network of the YOLOv8 detection model to form a CBAM-CSPL residual structure;
[0081] The CBAM-CSPL residual construction includes two branch paths: one branch path is the trunk path, which is formed by stacking multiple Bottleneck unit residual structures n times, and each Bottleneck unit is a residual structure; the other branch is the residual edge path, which performs convolution operations; the trunk path and the residual edge path are merged through the concat operation and the result is output;
[0082] The CBAM attention module is embedded between two convolutional layers in the Bottleneck structure;
[0083] The CBAM attention module consists of two sub-modules executed sequentially: the channel attention module CAM and the spatial attention module SAM;
[0084] The process formula of the CBAM attention module is:
[0085]
[0086] Input feature F∈R C*H*W , R represents a real number, C represents the number of image channels, H represents the height of the image, and W represents the width of the image. The one-dimensional convolution M of the channel attention module CAM is performed. c ∈R C*1*1 , multiply the convolution result by the original image as the output result F, of the channel attention module CAM;
[0087] Take the output result F of the channel attention module CAM as input and perform the two-dimensional convolution M of the spatial attention module SAM s ∈R 1*H*W ,Then multiply the convolution result by F, as the output result F,,of the spatial attention module SAM;
[0088] The process formula of the channel attention module CAM is:
[0089]
[0090] Among them, σ represents the activation function, MLP is the multi-layer perceptron module, and W0 and W1 are the learnable weights of MLP. They represent average pooling and maximum pooling respectively. The input feature map is diverted and processed through two parallel pooling layers: one layer is the MaxPool layer, and the other layer is the AvgPool layer. Through the two pooling operations, the feature map of the original size of C*H*W is compressed to the size of C*1*1, and each channel is pooled to obtain the global features of each channel;
[0091] The compressed data is input into the MLP module, which is a multi-layer perceptron module. In the MLP module, first, the number of channels of the data is compressed to 1 / r of the original number of channels through a fully connected layer, where r is the compression rate. Then, the number of channels of the data is expanded back to the original number of channels through another fully connected layer.
[0092] The data processed by the MLP module is activated by the ReLU activation function to obtain two activated feature vectors. The two feature vectors are added element by element to fuse the feature information obtained by different pooling methods. The result of the addition is activated by a sigmoid activation function to generate a weight vector with the same number of original channels. The weight vector is used as the output result of the channel attention module CAM.
[0093] Multiply the weight vector by the original feature map channel by channel, adjust the importance parameter of each channel, and strengthen the model's attention parameter to key features;
[0094] After being processed by the above CBAM attention module, the output feature map maintains the original C*H*W size and carries the optimized channel weight information;
[0095] The process formula of the spatial attention module SAM is:
[0096]
[0097] In the formula, f 7×7 Indicates that the convolution kernel size is 7×7, Represent average pooling and maximum pooling respectively. Apply maximum pooling and average pooling to the output results of the channel attention module CAM respectively to generate two feature maps of size 1*H*W. The two feature maps are concatenated through the Concat operation and then converted into a single-channel feature map through a 7*7 convolution layer. The feature map is processed by the sigmoid function to obtain the feature map of the spatial attention module SAM. As the output result of the spatial attention module SAM, the output result is multiplied by the original image to restore it to the size of C*H*W.
[0098] The structure of the stepped pyramid EPS is to connect horizontally on the basis of PANet, and aggregate the information in two directions to a CSP module for calculation, relying on the parameters of the unidirectional structure to achieve the results of the bidirectional structure, and replace the activation function Mish of each node with the activation function HardSwish;
[0099] The formula of the loss function MPDIOU is as follows:
[0100]
[0101] in, are the coordinates of the prediction box, are the coordinates of the real frame, x1 and y1 are the coordinates of the upper left corner, x2 and y2 are the coordinates of the lower right corner, h and w are the height and width of the original image, and IoU is intersection over union.
[0102] The formula of the loss function CIOU is as follows:
[0103]
[0104] Among them, w gt and h gt Indicates the width and height of the real box, w prd and h prd represents the width and height of the prediction box, ρ(B gt ,B prd ) represents the Euclidean distance between the center coordinates of the real box and the predicted box, and C is the diagonal distance of the smallest box enclosing them.
[0105] Training iteration step: Iterate the training of the target detection model through the dataset.
[0106] Detection and judgment steps: Use the target detection model after training iteration to detect the horn capacitor detection video to determine whether the printing of the horn capacitor is wrong;
[0107] In the detection and judgment step, after the horn capacitor detection video is processed by the target detection model, the coordinates of the cathode, the coordinates of the anode, the coordinates of the cathode identifier, the coordinates of the center of the circle, and the detection frame position and category information of the horn capacitor outer frame are obtained, and the angles of the cathode-anode connecting line and the center of the circle-cathode identifier connecting line are calculated. According to the calculation results, it is judged whether the printing of the horn capacitor is wrong; if the angle of the connecting line is less than or equal to 15°, it is judged as no error, and if the angle of the connecting line is greater than 15°, it is judged as an error.
[0108] The present invention also provides a YOLO-based ox-horn capacitor bushing polarity detection system, which can be implemented by executing the process steps of the YOLO-based ox-horn capacitor bushing polarity detection method, that is, those skilled in the art can understand the YOLO-based ox-horn capacitor bushing polarity detection method as a preferred implementation of the YOLO-based ox-horn capacitor bushing polarity detection system.
[0109] Embodiment 2:
[0110] This embodiment provides a YOLO-based horn capacitor bushing polarity detection system, including the following modules:
[0111] Dataset construction module: pre-process the horn capacitance detection video to obtain the data set;
[0112] Model optimization module: optimizes the YOLO detection model and builds a target detection model;
[0113] Training iteration module: iterates the training of the target detection model through the data set;
[0114] Detection and judgment module: The horn capacitor is detected through the target detection model after training iteration to determine whether the printing of the horn capacitor is wrong.
[0115] Embodiment 3:
[0116] Those skilled in the art may understand this embodiment as a more specific description of Embodiment 1 and Embodiment 2.
[0117] This embodiment provides a method for detecting polarity of a horn capacitor bushing based on YOLO, and the detailed process is as follows:
[0118] Step 1: Preprocess the horn capacitor detection video to divide it into video frames without horn capacitors and video frames with horn capacitors, and construct a dataset based on this. Then, the collected horn capacitor video frame dataset is annotated in detail. In order to further improve the quality and diversity of the data, the CutMix algorithm is used to perform data enhancement processing on the annotated horn capacitor dataset in a uniform distribution method, and finally a new optimized dataset is generated.
[0119] Step 1.1: Select the video frames containing the horn capacitor from the video frames, and then generate multiple images, which will form a reference image group. The purpose of this step is to reduce the error and improve the accuracy of recognition through multiple images. Use the clip model to process these reference images and obtain their corresponding feature vectors.
[0120] Step 1.2: Traverse the entire horn capacitance detection video, encode each frame, and convert it into a feature vector. For each feature vector of the video frame, calculate its cosine similarity with each feature vector in the reference image group.
[0121] Step 1.3: Set a cosine similarity threshold. If the cosine similarity between the feature vector of a certain video frame and all feature vectors in the reference image group is greater than the preset threshold, then the video frame is determined to be a video frame containing a horn capacitor. If the above condition is not met, the video frame is determined to be a video frame that does not contain a horn capacitor.
[0122] Step 2: Divide the processed data set into training set, validation set and test set in a ratio of 6:2:2.
[0123] Step 3: Optimize the YOLO detection model through the CBAM attention module and build an object detection model based on the improved YOLOv8.
[0124] Step 3.1: The specific operation of introducing the CBAM (Convolutional Block Attention Module) module in the YOLOv8 model is as follows: First, insert the CBAM module in the CSPLayer of the basic backbone network of the model. The CBAM-CSPL residual structure contains two branch paths. Among them, the trunk path is composed of multiple Bottleneck small unit residual structures stacked, and a total of n such stackings are performed, and each Bottleneck itself is also a residual structure. The other branch is the residual edge path, which only performs basic convolution operations. Finally, the trunk path and the residual edge path are merged through the concat operation and the result is output.
[0125] Step 3.2: The spatial attention module in CBAM selectively removes features in the channel dimension, retaining only those features that contain more critical semantic details. At the same time, the module also captures the more important position information on the feature map for small objects.
[0126] Step 3.1.1: CBAM is embedded between two convolutional layers in the Bottleneck structure, namely, 1×1 convolution and 3×3 convolution. The 1×1 convolution is mainly responsible for integrating the channels of the input feature map and does not involve downsampling of the original information. The 3×3 convolution will downsample the original information to extract features.
[0127] Step 3.1.2: CBAM is repeated n times with the n-times stacking of Bottleneck, that is, the key features are screened and optimized in each feature selection to ensure that the features entering the downsampling are of high quality.
[0128] Step 3.1.3: CBAM consists of two sequentially executed sub-modules: Channel Attention Module (CAM) and Spatial Attention Module (SAM). The overall process of CBAM is as follows Figure 2 As shown in Figure 1, it consists of input, channel attention module, spatial attention module and output. The overall process formula of CBAM is:
[0129]
[0130] Input feature F∈R C*H*W , followed by a channel attention module one-dimensional convolution M c ∈R C*1*1 , multiply the convolution result by the original image, take the CAM output result as input, and perform the two-dimensional convolution M of the spatial attention module s ∈R 1*H*W, and then multiply the output result with the original image.
[0131] Step 3.1.3.1: Channel Attention (CAM) process is as follows Figure 3 As shown, the formula is:
[0132]
[0133] The input feature map will be split and processed through two parallel pooling layers: one is the MaxPool layer and the other is the AvgPool layer. These two pooling operations will compress the feature map of the original size of CHW into the size of C11, that is, each channel is pooled to obtain the global features of each channel. Then, the compressed data is sent to a shared MLP (multi-layer perceptron) module. In the Share MLP module, the number of channels of the data is first compressed to 1 / r (r is the compression rate) of the original number of channels through a fully connected layer, and then the number of channels of the data is expanded back to the original number of channels through another fully connected layer. The design of these two fully connected layers is to first reduce the dimension of the data to reduce the amount of calculation, and then increase the dimension to restore to the original number of channels, so as to perform more refined feature transformation. The data processed by MLP will pass through the ReLU activation function to obtain two activated feature vectors. These two feature vectors will be added element by element to fuse the feature information obtained by different pooling methods. The result of the addition will pass through a sigmoid activation function to generate a weight vector with the same number of original channels, which represents the output of Channel Attention. Finally, this weight vector will be multiplied with the original feature map channel by channel to adjust the importance of each channel and strengthen the model's focus on key features. After being processed by such an attention mechanism, the output feature map will maintain the original CHW size, but carry optimized channel weight information.
[0134] Step 3.1.3.2: Spatial Attention (SAM) structure is as follows Figure 4 As shown, the announcement is as follows:
[0135]
[0136] The output of channel attention is subjected to maximum pooling and average pooling respectively, generating two feature maps of size 1*H*W. These two feature maps are then concatenated through a Concat operation and converted into a single-channel feature map through a 7*7 convolution layer. After that, the feature map is processed by a sigmoid function to obtain the feature map of Spatial Attention. Finally, this output is multiplied with the original image to restore it to the size of C*H*W.
[0137] Step 4: Modify the neck part of yolov8 and improve PANet into an efficient step pyramid (ESP). The structure of ESP is based on PANet, except for the horizontal connection, and the information in two directions is gathered into a CSP module for calculation, and the result of the bidirectional structure is achieved by relying on the parameters of the unidirectional structure. And replace the activation function Mish of each node with the lower complexity HardSwish to improve the fusion efficiency.
[0138] Step 5: Iterate the training of the horn capacitance detection model based on the improved YOLOv8. The model uses an excellent loss function in the iterative optimization process to judge the difference between the training results and the labels, and continuously guides the model optimization during the training process to improve the accuracy of detection. The loss functions of Yolov8 are mainly: bounding box regression loss CIoU. Bounding box regression is an important part of target detection and a key step in target positioning. Traditional Yolov8 uses CIOU, and the formula is as follows:
[0139]
[0140] Among them, w gt and h gt represents the width and height of the real box, and w prd and h prd represents the width and height of the prediction box, ρ(B gt ,B prd ) represents the Euclidean distance between the center coordinates of the real box and the predicted box, and C is the diagonal distance of the smallest box enclosing them.
[0141] This embodiment uses MPDIoU instead of the traditional CIoU of Yolov8, and its formula is as follows:
[0142]
[0143] in, are the coordinates of the prediction box, are the coordinates of the real box, x1 and y1 are the coordinates of the upper left corner, x2 and y2 are the coordinates of the lower right corner, h and w are the height and width of the original image, and IoU is intersection over union.
[0144] Compared with CIoU, MPDIoU does not use the absolute value of the height and width of the border to calculate, but uses a new type of bounding box with minimum point distance to calculate. MPDIoU not only integrates multiple factors that affect the bounding box regression calculation, such as center point distance and aspect ratio, but also optimizes the calculation steps, thereby significantly reducing the time required for model convergence and training.
[0145] The performance evaluation indicators of the model are: precision, recall, average precision (AP), mean average precision (mAP) and FScore value.
[0146] The model is continuously optimized through the above model evaluation indicators until the optimal target detection model is obtained or the epoch reaches the upper limit.
[0147] Among them, the formula for precision Precision is as follows:
[0148]
[0149] In the formula, TP represents the number of correctly identified positive samples, and FP represents the number of incorrectly identified negative samples. The formula for recall is as follows:
[0150]
[0151] Where FN represents the number of negative samples that are misidentified.
[0152] The formula for the F1-Score value is as follows:
[0153]
[0154] The formulas for average precision AP and mean average precision mAP are as follows:
[0155]
[0156] The improved model is based on the Yolov8s model, and transfer learning is performed and trained on a self-made dataset. The environment for the following experimental results is: CPU is i9 13900k, memory is 16g, graphics card is Nvidia 4070super 12g video memory. Based on the Pytorch framework, the number of training epochs is 700 rounds, and the number of patience rounds is 200 rounds. The specific training configuration is shown in Table 1.
[0157] Table 1: Training parameter configuration table
[0158]
[0159] The present invention compares the original Yolov8 and the Improved-Yolov8 model improved by the present invention.
[0160] Table 2: Algorithm experiment comparison table
[0161]
[0162] Experiments show that the Improved-Yolov8 algorithm of the present invention achieves better performance in mAP value, F1Score and Precision than the YOLOv8 algorithm in horn capacitor printing detection.
[0163] In the comparison of mAP indicators, the mAP50-95 indicator of YOLOv8 is 0.86687, while the mAP50-95 value of the algorithm of the present invention is up to 0.91827, which is 5.93% higher than that of YOLOv8. In the comparison of F1Score values, the F1Score value of the algorithm in this embodiment reaches 0.99969, which is 5.2 percentage points higher than that of YOLOv8 (0.95038).
[0164] Step 6: Through the processing of the model, the detection frame position and category information of the positive electrode, negative electrode, negative electrode identifier and the outer frame of the horn capacitor can be obtained. Once the detection is completed, these output results are imported into the preset system to automatically calculate the angle of the cathode-anode connection line and the center-cathode identifier connection line. The system will then determine whether the printing of the horn capacitor is wrong based on the calculated results. If there is no error, OK will be displayed on the system interface; if there is an error, NG will be displayed on the system interface. In addition, the system will create a table for each video, and record the total number, qualified number and qualified rate of this batch of horn capacitors in the table based on the printing situation detected in the video. Finally, the qualified and unqualified horn capacitor images will be stored in the corresponding folder for later review.
[0165] The present invention solves the problem of low recognition rate of horn capacitance detection by adopting the improved YOLOv8 structure, thereby achieving the effect of accurate detection of horn capacitance detection.
[0166] Those skilled in the art know that, in addition to realizing the system and its various devices, modules, and units provided by the present invention in a purely computer-readable program code, it is entirely possible to realize the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system and its various devices, modules, and units provided by the present invention can be considered as a hardware component, and the devices, modules, and units included therein for realizing various functions can also be regarded as structures within the hardware component; the devices, modules, and units for realizing various functions can also be regarded as both software modules for realizing the method and structures within the hardware component.
[0167] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A method for detecting polarity of a horn capacitor bushing based on YOLO, characterized in that: The steps include: Dataset construction steps: Preprocess the horn capacitance detection video to obtain the dataset; Model optimization steps: optimize the YOLO detection model and build a target detection model; Training iteration step: Iterate the training of the target detection model through the dataset; Detection and judgment steps: Use the target detection model after training iteration to detect the horn capacitor detection video to determine whether the printing of the horn capacitor is wrong.
2. The method for detecting polarity of a horn capacitor bushing based on YOLO according to claim 1 is characterized in that: The data set construction step specifically includes the following steps: Step 1.1: Divide the horn capacitor detection video into video frames that do not contain horn capacitors and video frames that contain horn capacitors to obtain a horn capacitor dataset, annotate the horn capacitor dataset, and use the CutMix algorithm to perform image enhancement on the annotated horn capacitor dataset; Step 1.2: Divide the image-enhanced horn capacitance dataset into a training dataset, a validation dataset, and a test dataset according to a preset ratio.
3. The method for detecting polarity of a horn capacitor bushing based on YOLO according to claim 2 is characterized in that: The step 1.1 specifically includes the following steps: Step 1.1.1: Select video frames containing horn capacitors from the video frames of the horn capacitor detection video, generate multiple images, form a reference image group, use the clip model to process the reference image group, and obtain the corresponding feature vector; Step 1.1.2: Traverse the entire horn capacitance detection video, encode each video frame, and convert it into a feature vector, and calculate the cosine similarity between the feature vector of each video frame and each feature vector in the reference image group; Step 1.1.3: Set a preset threshold of cosine similarity, and determine whether the cosine similarities between the feature vector of the video frame and all feature vectors in the reference image group are greater than the preset threshold. If so, the video frame is determined to be a video frame containing a cow-horn capacitor. If not, the video frame is determined to be a video frame not containing a cow-horn capacitor.
4. The method for detecting polarity of a horn capacitor bushing based on YOLO according to claim 1 is characterized in that: The model optimization steps are specifically as follows: Integrate the CBAM attention module into the YOLOv8 detection model; Modify the neck part of the YOLOv8 detection model and change PANet to step pyramid EPS; The loss function CIOU in the YOLOv8 detection model is modified to the loss function MPDIOU.
5. The method for detecting polarity of a horn capacitor bushing based on YOLO according to claim 4 is characterized in that: Insert the CBAM attention module into the CSPLayer of the backbone network of the YOLOv8 detection model to form a CBAM-CSPL residual structure; The CBAM-CSPL residual construction includes two branch paths: one branch path is the trunk path, which is formed by stacking multiple Bottleneck unit residual structures n times, and each Bottleneck unit is a residual structure; the other branch is the residual edge path, which performs convolution operations; the trunk path and the residual edge path are merged through the concat operation and the result is output; The CBAM attention module is embedded between two convolutional layers in the Bottleneck structure.
6. The method for detecting polarity of a horn capacitor bushing based on YOLO according to claim 4 is characterized in that: The CBAM attention module consists of two sub-modules executed sequentially: a channel attention module CAM and a spatial attention module SAM; The process formula of the CBAM attention module is: Input feature F∈R C*H*W , R represents a real number, C represents the number of image channels, H represents the height of the image, and W represents the width of the image. The one-dimensional convolution M of the channel attention module CAM is performed. c ∈R C*1*1 , multiply the convolution result by the original image as the output result F' of the channel attention module CAM; Take the output result F of the channel attention module CAM as input and perform the two-dimensional convolution M of the spatial attention module SAM s ∈R 1*H*W , and then multiply the convolution result by F, as the output result F`` of the spatial attention module SAM; The process formula of the channel attention module CAM is: Among them, σ represents the activation function, MLP is the multi-layer perceptron module, and W0 and W1 are the learnable weights of MLP. They represent average pooling and maximum pooling respectively. The input feature map is diverted and processed through two parallel pooling layers: one layer is the MaxPool layer, and the other layer is the AvgPool layer. Through the two pooling operations, the feature map of the original size of C*H*W is compressed to the size of C*1*1, and each channel is pooled to obtain the global features of each channel; The compressed data is input into the MLP module, which is a multi-layer perceptron module. In the MLP module, first, the number of channels of the data is compressed to 1 / r of the original number of channels through a fully connected layer, where r is the compression rate. Then, the number of channels of the data is expanded back to the original number of channels through another fully connected layer. The data processed by the MLP module is activated by the ReLU activation function to obtain two activated feature vectors. The two feature vectors are added element by element to fuse the feature information obtained by different pooling methods. The result of the addition is activated by a sigmoid activation function to generate a weight vector with the same number of original channels. The weight vector is used as the output result of the channel attention module CAM. Multiply the weight vector by the original feature map channel by channel, adjust the importance parameter of each channel, and strengthen the model's attention parameter to key features; After being processed by the above CBAM attention module, the output feature map maintains the original C*H*W size and carries the optimized channel weight information; The process formula of the spatial attention module SAM is: In the formula, f 7×7 Indicates that the convolution kernel size is 7×7, They represent average pooling and maximum pooling respectively. The output results of the channel attention module CAM are applied with maximum pooling and average pooling respectively to generate two feature maps of size 1*H*W. The two feature maps are concatenated through the Concat operation and then converted into a single-channel feature map through a 7*7 convolution layer. The feature map is processed by the sigmoid function to obtain the feature map of the spatial attention module SAM. As the output result of the spatial attention module SAM, the output result is multiplied by the original image and restored to the size of C*H*W.
7. The method for detecting polarity of a horn capacitor bushing based on YOLO according to claim 4 is characterized in that: The structure of the stepped pyramid EPS is based on PANet and is horizontally connected. It aggregates information from two directions into a CSP module for calculation, relies on the parameters of the unidirectional structure to achieve the results of the bidirectional structure, and replaces the activation function Mish of each node with the activation function HardSwish.
8. The method for detecting polarity of a horn capacitor bushing based on YOLO according to claim 4 is characterized in that: The formula of the loss function MPDIOU is as follows: in, are the coordinates of the prediction box, are the coordinates of the real frame, x1 and y1 are the coordinates of the upper left corner, x2 and y2 are the coordinates of the lower right corner, h and w are the height and width of the original image, and IoU is intersection over union. The formula of the loss function CIOU is as follows: Among them, w gt and h gt Indicates the width and height of the real box, w prd and h prd represents the width and height of the prediction box, ρ(B gt ,B prd ) represents the Euclidean distance between the center coordinates of the real box and the predicted box, and C is the diagonal distance of the smallest box enclosing them.
9. The method for detecting polarity of a horn capacitor bushing based on YOLO according to claim 1, characterized in that: In the detection and judgment step, after the ox-horn capacitor detection video is processed by the target detection model, the coordinates of the cathode, the coordinates of the anode, the coordinates of the cathode identifier, the coordinates of the center of the circle, and the detection frame position and category information of the ox-horn capacitor outer frame are obtained, and the angle of the cathode-anode line and the line connecting the center of the circle-cathode identifier is calculated, and whether the printing of the ox-horn capacitor is wrong is judged based on the calculation results.
10. A YOLO-based horn capacitor casing polarity detection system, characterized in that: Includes the following modules: Dataset construction module: pre-process the horn capacitance detection video to obtain the data set; Model optimization module: optimize the YOLO detection model and build a target detection model; Training iteration module: iterates the training of the target detection model through the data set; Detection and judgment module: The horn capacitor is detected through the target detection model after training iteration to determine whether the printing of the horn capacitor is wrong.
Citation Information
Patent Citations
Chip capacitor screen printing defect detection method, device and equipment and storage medium
CN116012354A
Cited By
Medical image automatic segmentation method based on YOLO-SAM collaborative attention mechanism
CN121505275A