Improved yolov12-based intelligent detection method for oil seal defects
By improving the YOLOv12 model and adding a small target detection layer, a dynamic upsampling module, and an MSAF module, the problems of insufficient detection accuracy and robustness in oil seal defect detection were solved, and efficient and accurate oil seal defect detection was achieved.
Patent Information
- Application Number
- CN202511180676.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-22
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2045-08-22
AI Technical Summary
Existing oil seal defect detection methods rely on manual inspection, which results in inconsistent detection results, low efficiency, and high cost. The existing YOLO model lacks sufficient accuracy and robustness in complex environments, making it difficult to meet the needs of industrial production.
The YOLOv12 model was improved by adding a small target detection layer, a dynamic upsampling module, an MPDIoU loss function, and an MSAF module to construct the MPD-YOLO model, thereby improving the detection accuracy and robustness of small target defects.
It significantly improves the detection accuracy and real-time performance of oil seal surface defects, enhances the model's ability to identify small-sized defects, solves the detection problem in complex environments, and meets the needs of industrial production.
Smart Images

Figure CN120707566B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of oil seal defect detection, in particular to an oil seal defect intelligent detection method based on improved YOLOv12. BACKGROUND
[0002] In the field of industrial production, oil seals, as a kind of key sealing elements, are widely used in various mechanical equipment. Its role is to prevent the leakage of lubricating oil or grease, and at the same time prevent the intrusion of external pollutants into the equipment. It plays a crucial role in protecting the normal operation of mechanical equipment and prolonging the service life. Once the oil seal has surface defects such as scratches, burrs, and concave defects, it will cause the leakage of lubricating oil, and then affect the normal operation of the equipment, and in severe cases, it may cause equipment failure, resulting in production stagnation and causing huge economic losses.
[0003] The traditional oil seal surface defect detection method mainly relies on manual visual inspection, which has many drawbacks. On the one hand, manual detection is greatly affected by subjective factors, and there are differences in experience and judgment standards among different detection personnel, resulting in a lack of consistency and accuracy in the detection results. On the other hand, long-term repeated detection work by manual detection can easily cause visual fatigue, and then lead to missed detection, false detection, and other situations. In addition, manual detection is low in efficiency and difficult to meet the detection needs of large-scale industrial production, and the labor cost is high.
[0004] With the development of science and technology, image processing-based oil seal surface defect detection methods have been gradually applied, such as dividing the oil seal grayscale image into blocks, analyzing the pixel point features in the blocks to enhance the contrast between the dirty area and other areas, and achieving accurate segmentation of the dirty area; oil seal defect image edge detection method based on threshold segmentation and chain code method, using least squares method to fit the circular profile of the oil seal lip, and detecting defects; there is also an oil seal defect detection method based on entropy rate clustering segmentation and ring band difference. However, since these detection methods must manually obtain oil seal defect features, this method of manually extracting defect features has certain limitations, and the steps are tedious, and the requirements for technical personnel are also higher.
[0005] In recent years, deep learning technology has developed rapidly, and target detection algorithms based on convolutional neural networks have shown strong performance in many fields. Among them, the YOLO series algorithm has been widely adopted because it can quickly and efficiently identify targets in images and perform well in real-time object detection tasks. However, in the context of oil seal surface defect detection, existing YOLO models still face many challenges:
[0006] 1) There are many types of defects in the production process of oil seals, and it is difficult to obtain a large-scale high-quality training dataset covering all defect types, which restricts the detection ability and accuracy of deep models for defects.
[0007] 2) The actual industrial detection environment is complex and changeable, and factors such as unstable lighting conditions and equipment vibration can interfere with the detection results, leading to a decrease in the efficiency of the existing YOLO model in processing high-definition image streams and maintaining high accuracy under changing lighting conditions, making it difficult to meet the needs of industrial production for high-precision, high-reliability oil seal surface defect detection.
[0008] 3) Limited feature extraction capability for small-sized targets, easily disturbed by complex background noise, leading to reduced detection accuracy.
[0009] Therefore, it is of great practical significance and application value to develop a method that can effectively overcome the above problems and improve the efficiency and accuracy of oil seal surface defect detection. SUMMARY
[0010] To solve the above technical problems, the present application provides an oil seal defect intelligent detection method based on improved YOLOv12, which improves the detection accuracy of small target defects, real-time detection capability, and the robustness of the model.
[0011] To solve the above technical problems, the technical solution provided by the present application is:
[0012] An oil seal defect intelligent detection method based on improved YOLOv12, comprising the following steps:
[0013] Step S1, collect image data of the oil seal, and label to obtain an oil seal defect data set;
[0014] Step S2, improve the network framework of the YOLOv12 model, and construct an oil seal surface defect detection model based on YOLOv12, i.e. MPD-YOLO model;
[0015] Step S3, train the MPD-YOLO model to obtain the trained MPD-YOLO model;
[0016] Step S4, evaluate the trained MPD-YOLO model according to the oil seal defect test set, and adjust the MPD-YOLO model according to the evaluation result;
[0017] In step S2, the improvement of the network framework of the YOLOv12 model includes the following operations:
[0018] S2-1, adjust the head level structure of the YOLOv12 model, fuse shallow semantic information, and add a small target detection layer;
[0019] S2-2, replace the nearest neighbor interpolation upsampling module of the YOLOv12 model with a dynamic upsampling module;
[0020] S2-3, replacing the CIoU loss function of the YOLOv12 model with an MPDIoU loss function;
[0021] S2-4, replacing the C3k2 module in the backbone network of the YOLOv12 model with an MSAF module.
[0022] As a further improvement of the above technical solution:
[0023] Preferably, the adjustment of the detection head hierarchy of the YOLOv12 model is based on the addition of a set of small target detection layers P2 to the three detection layers, followed by the addition of a P2 upsampling fusion module after the first detection layer P3 and the second detection layer P4 two rounds of upsampling fusion modules, and the connection to the small target detection layer P2.
[0024] Preferably, in the dynamic upsampling module, the input feature map X is first interpolated into a continuous feature map through bilinear interpolation; then, an offset O is generated through a linear layer, and the offset determines the position of the sampling point in the continuous space, which is used to reconstruct the upsampled feature map X'.
[0025] Preferably, in the dynamic upsampling module, a sampling point generator based on a static range factor or a dynamic range factor is used to generate the sampling point.
[0026] Preferably, the specific structure of the MSAF module is: starting from the input feature, a double-branch parallel processing architecture is constructed, the upper branch of the double branch uses dilated convolution with dilation coefficients of 1, 2, 3, and 4 to obtain multi-scale features and perform concatenation, and then adjusts the dimension through channel shuffling and 1x1 convolution; the lower branch of the double branch first performs multi-scale pooling through pyramid pooling, and then the flattened and concatenated pooling results are operated with the query vector extracted from the input feature to generate a weight that acts on the value vector branch and is output through 1x1 convolution; finally, the results of the upper and lower branches are output through element-wise addition operation to output enhanced features that fuse multi-scale and attention mechanisms.
[0027] Preferably, the evaluation method of the trained MPD-YOLO model in step S4 is:
[0028] The oil seal defect test set is input into the trained MPD-YOLO model, and according to the set key indicators: average precision mean, precision, and recall rate, the evaluation results are obtained;
[0029] The precision formula is:
[0030] ;
[0031] The recall rate formula is:
[0032] ;
[0033] In the formula, TP represents the number of correct classification as positive samples; FP represents the number of false classification as positive samples; and FN represents the number of false classification as negative samples.
[0034] The average precision mean calculation formula is:
[0035] ;
[0036] In the formula, n represents the number of categories, i represents the category index, represents the function form of the precision-recall curve, P represents the precision, R represents the recall.
[0037] The oil seal defect intelligent detection method based on improved YOLOv12 provided by the application has the following advantages compared with the prior art:
[0038] (1) The oil seal defect intelligent detection method based on improved YOLOv12 solves the problems of low small target detection rate and poor adaptability of the prior art, and improves the detection accuracy, real-time performance and robustness of surface defects such as oil seal burrs, concave defects and scratches by increasing a small target detection layer, using an MSAF module, combining dynamic upsampling and a new loss function, effectively solving the small size defect recognition problem in industrial detection.
[0039] (2) The oil seal defect intelligent detection method based on improved YOLOv12 effectively fuses shallow features by introducing a small target detection layer and combining a P2 upsampling fusion block, significantly enhancing the model's detection ability for small target defects and improving the accuracy and reliability of oil seal surface defect recognition.
[0040] (3) The oil seal defect intelligent detection method based on improved YOLOv12 introduces a dynamic upsampling module, replaces the nearest neighbor interpolation upsampling method in the feature fusion step, effectively avoids time-consuming dynamic convolution operations and additional subnetwork construction through a content-based dynamic point sampling strategy, realizes fine-grained offset control of small target regions, ensures accurate recovery of small size defects and edge features in the upsampling process, and significantly improves the model's detection ability for small size defects and multi-shape defects.
[0041] (4) The improved YOLOv12-based oil seal defect intelligent detection method of the present application introduces MPDIoU to replace CIoU, MPDIoU calculates different loss function values for prediction boxes of different width and height, can more effectively guide the prediction box to approach the real box, solves the problem of CIoU failure, MPDIoU not only simplifies the calculation process, but also stabilizes the model convergence, and improves the detection effect of small size defects.
[0042] (5) The improved YOLOv12-based oil seal defect intelligent detection method of the present application introduces MSAF module to replace C3k2 module of YOLOv12 backbone network part, MSAF module can more comprehensively understand the input image by processing local features and global features at the same time. In the target detection task, this helps the model to identify the targets in the image and correctly locate them. Local features help to capture the detailed information of the target such as edges, textures, etc., while global features provide the context of the target such as background, relationship between targets, etc. Through the dilated convolution and different size pooling operations in the MSAF module, the module can extract features at multiple scales, so as to better handle multi-scale targets and avoid the receptive field problem in traditional convolutional networks. Through the channel scrambling operation, the module can make the features generated by each convolution operation better fused, which not only avoids the information bottleneck, but also improves the network's expression ability for details and complex patterns in the image. BRIEF DESCRIPTION OF DRAWINGS
[0043] Figure 1 The flowchart of the improved YOLOv12-based oil seal defect intelligent detection method of the present application.
[0044] Figure 2 The structure diagram of the MPD-YOLO model of the present application.
[0045] Figure 3 The structure diagram of the dynamic upsampling module of the present application.
[0046] Figure 4 The structure diagram of the sampling point generator based on static range factor in the dynamic upsampling module of the present application.
[0047] Figure 5 The structure diagram of the sampling point generator based on dynamic range factor in the dynamic upsampling module of the present application.
[0048] Figure 6 The structure diagram of the MSAF module of the present application. DETAILED DESCRIPTION
[0049] The specific embodiments of the present application are described in detail below. It should be understood that the specific embodiments described herein are only used to illustrate and explain the present application, and are not used to limit the present application.
[0050] As Figure 1 shown, the application is based on an improved YOLOv12 oil seal defect intelligent detection method, based on the YOLOv12 model, introduces a small target detection layer, replaces the nearest neighbor interpolation up-sampling module with a dynamic up-sampling module, and replaces the CIoU (Complete Intersection over Union) loss function with the MPDIoU (Minimum Perimeter Distance Intersection over Union) loss function, replaces the C3k2 module in the YOLOv12 model backbone network with the MSAF module, and constitutes the MPD-YOLO oil seal defect detection model, which improves the detection accuracy, real-time detection ability and robustness of the model for small target defects.
[0051] The application is based on an improved YOLOv12 oil seal defect intelligent detection method, which specifically includes the following steps:
[0052] Step S1, collect the image data of the oil seal, label the obtained oil seal image set, and obtain the training sample.
[0053] Specifically, the following steps are included:
[0054] S1-1, use a high-definition camera to collect image data of industrial oil seals during production, and collect oil seal images from an open-source data set website, and obtain the original data set through the two methods.
[0055] S1-2, the original data set is manually screened to eliminate excessively blurred and overexposed pictures, and an oil seal image set including multiple scales and multiple defect types is obtained; then data enhancement methods such as rotation, scaling, blurring and changing brightness are used to obtain sample data.
[0056] The oil seal image is subjected to data enhancement processing, so that each oil seal image is expanded into multiple images. Specifically, the torchvision.transforms (image transformation module in PyTorch vision tool library) module in the PyTorch platform can be used for data enhancement. The transforms.RandomRotation (random rotation transformation function) function can be used to randomly rotate the image; the transforms.RandomResizedCrop (random cropping and resizing transformation function) function can be used to randomly crop and resize the image; the transforms.ColorJitter (color jitter transformation function) function can be used to randomly transform the brightness and contrast of the image; and the transforms.GaussianBlur (Gaussian blur transformation function) function can be used to randomly Gaussian blur the image. In this way, the size of the data set is expanded, the generalization ability of the model is improved, the robustness of small target detection is enhanced, and the risk of model overfitting is reduced.
[0057] S1-3, label the image, record the defect type and position in each image, and manually review the labeling result to ensure the accuracy of the labeling. In the process of processing the data set, the collected oil seal images are labeled in detail using the LabelImg tool, and the defect type and position are labeled. The defects are divided into three categories: burr, dent and scratch, wherein the burr is "burr", the dent is "dent", and the scratch is "scratch".
[0058] S1-4, after the labeling is completed, the entire data set is divided into a training set, a validation set and a test set in a ratio of 8:1:1 to ensure the effectiveness and generalization ability of the model.
[0059] Step S2, improve the network framework of the YOLOv12 model, and construct an oil seal surface defect detection model based on YOLOv12, i.e. MPD-YOLO model.
[0060] In this embodiment, the specific operations of improving the network framework of the YOLOv12 model include the following operations:
[0061] S2-1, adjust the head part of the YOLOv12 model hierarchical structure, fuse shallow semantic information, and add a small target detection layer;
[0062] Firstly, the YOLOv12 model head part hierarchy is adjusted to fuse shallow semantic information. A small target detection layer P2 is added based on the three detection layers, and then a P2 upsampling fusion module is added after the first detection layer P3 and the second detection layer P4 two rounds of upsampling fusion modules, and connected to the small target detection layer P2. Combined with the P2 upsampling fusion block, the shallow features are effectively fused, which significantly enhances the model's detection ability for small target defects and improves the precision and reliability of the oil seal surface defect recognition.
[0063] S2-2, using a dynamic upsampling module to replace the nearest neighbor interpolation upsampling module of the YOLOv12 model. The dynamic upsampling module replaces the nearest neighbor interpolation upsampling method in the feature fusion step, effectively avoids the time-consuming dynamic convolution operation and additional subnetwork construction, realizes the fine-grained offset control of the small target area, ensures the accurate recovery of small size defects and edge features in the upsampling process, and significantly improves the detection ability of the model for small size defects and multi-shape defects.
[0064] In the dynamic upsampling module, first, the input feature map X is interpolated into a continuous feature map through bilinear interpolation. Then, an offset O is generated through a linear layer, and these offsets determine the positions of the sampling points in the continuous space. These sampling points are finally used to reconstruct the upsampled feature map X'. Specifically, as shown in Figure 3 , given a feature map X of size and a set of sampling points S of size , where C is the number of channels, H and B are the height and width of the feature map respectively, 2 represents the coordinates of x and y directions, and g represents the number of groups, the feature map is divided into g groups along the channel range, and the grid_sample function uses the positions in the sampling set S to resample X to generate a feature map X' of size , and this upsampling process is shown in equation (1):
[0065] (1)
[0066] where is the grid_sample function, X is the input feature, X' is the upsampled feature, and S is the sampling set. The sampling point generator generates the sampling set S, given the upsampling scale factor s and the feature map X of size CxHxB, a linear layer with input and output channel numbers C and is used to generate an offset O of size xHxB, and then it is reshaped to by pixel recombination.
[0067] Further, in the dynamic upsampling module, a sampling point generator based on a static range factor or a dynamic range factor is used to generate the sampling points.
[0068] (1) Static range factor: As shown in Figure 4 , the input feature map X is first generated into a low-dimensional feature through a linear transformation, then multiplied by a fixed factor 0.25, and then subjected to a pixel rearrangement operation, denoted as:
[0069] (2)
[0070] wherein O represents an offset, represents a linear layer, the input channel number of which is C and the output channel number of which is 2s2.
[0071] The static range factor makes the upsampling stable and controllable, and is suitable for processing scenes with consistent scale changes.
[0072] (2) Dynamic range factor: The introduction of the dynamic range factor makes the sampling process more flexible. First, a range factor is generated, and then it is used to adjust the offset O. Here, sigma represents a Sigmoid function, which is used to generate the range factor. By dynamically adjusting the offset, the dynamic upsampling can automatically adjust the sampling points according to different input feature maps, thereby avoiding the limitations of traditional interpolation methods, denoted as:
[0073] (3)
[0074] wherein, , represent two different linear layers, are used to generate values related to the dynamic range factor, generate values related to the offset.
[0075] The dynamic factor can adaptively adjust the scaling scale of different inputs, and is particularly suitable for processing images with multi-scale features or large changes in resolution. This mechanism can better capture detailed information at different scales, and improve the flexibility and adaptability of the model.
[0076] The above formula (3) represents the method adopted by the method proposed in the disclosure, as shown in Figure 5 , a Sigmoid function and a static factor of 0.5 are used, so that the dynamic range is limited to [0, 0.5], and a point-by-point dynamic range factor is generated with 0.25 as the center.
[0077] In this embodiment, further, the sampling set S is the sum of the offset O and the original sampling grid G, and the operation process is shown in formula (4):
[0078] (4)
[0079] The dynamic up-sampling of the embodiment realizes dynamic up-sampling from a low-resolution feature map to a high-resolution feature map. The generation and position adjustment of the sampling points are dynamically determined according to the content of the input feature map. This method helps to better extract feature information and ensures the efficiency and effect of the up-sampling process.
[0080] S2-3, replace the CIoU loss function of the YOLOv12 model with the MPDIoU loss function. MPDIoU calculates different loss function values for prediction boxes of different widths and heights, which can more effectively guide the prediction box to approach the real box and solve the CIoU failure problem. MPDIoU not only simplifies the calculation process, but also stabilizes the model convergence and improves the detection effect of small size defects.
[0081] The MPDIoU calculation formula is as follows:
[0082] (5);
[0083] In the formula, w and h are the width and height of the prediction box, is the distance between the upper left corner point of the prediction box and the upper left corner point of the real box, are the distances between the right lower corner points of the prediction box and the real box, respectively. and The calculation formula of and is as follows:
[0084] (6);
[0085] (7);
[0086] wherein, is the left upper corner point coordinate of the real box, is the right lower corner point coordinate of the real box; is the left upper corner point coordinate of the prediction box, is the right lower corner point coordinate of the prediction box.
[0087] The loss function calculation formula based on MPDIoU is as follows:
[0088] (8);
[0089] The MPDIoU loss function comprehensively considers the position and size offset between the bounding boxes, can effectively converge in the case of overlapping or not overlapping between the predicted box and the labeled box, and reduces the loss by minimizing the distance between the predicted two corner points. The point distance-based measurement method solves the problem that the CIoU loss function cannot effectively optimize the predicted bounding box and the real bounding box with the same aspect ratio but completely different length and width values, thereby more accurately measuring the difference between the oil seal surface defect prediction box and the oil seal surface defect real box, and effectively improving the detection accuracy of the model on the oil seal surface defect.
[0090] S2-4, using a MSAF module (Multi Scale Attention Fusion module) to replace the C3k2 module in the backbone network of the YOLOv12 model. The MSAF module can better understand the input image by processing local features and global features simultaneously. In the task of object detection, this helps the model to identify objects in the image and correctly locate them. Local features help to capture detailed information of the object such as edges, textures, etc., while global features provide the context of the object such as background, relationship between objects, etc. Through the dilated convolution and different size pooling operations in the MSAF module, the module can extract features at multiple scales, thus better handling multi-scale objects and avoiding the receptive field problem in traditional convolutional networks. Through the channel shuffling operation, the module can make the features generated by each convolution operation better fused, which not only avoids the information bottleneck, but also improves the network's ability to express details and complex patterns in the image.
[0091] As shown in Figure 6 , the specific structure of the MSAF module in S2-4 is as follows: the module starts with input features, builds a double-branch parallel processing architecture. The upper branch uses dilated convolution with dilation coefficients of 1, 2, 3, and 4 to obtain multi-scale features and concatenate them, then performs channel shuffling and adjusts the dimension through 1x1 convolution; the lower branch first performs multi-scale pooling through pyramid pooling, then the flattened and concatenated pooling results are operated with the query vector extracted from the input features to generate weights that act on the value vector branch, and finally output through 1x1 convolution. Finally, the results of the upper and lower branches are added element by element to output enhanced features that fuse multi-scale and attention mechanisms.
[0092] In this embodiment, the MSAF module uses multiple strategies to enhance the feature extraction capability of the network, which combines local feature extraction, global feature extraction and attention mechanism to improve the performance of object detection.
[0093] S2-4-1, Local feature capture: The module extracts local features through four convolutional layers with different dilation rates, which can effectively expand the receptive field and capture local information of different sizes. Then, the features of different convolutional layers are mixed through channel shuffle operation to improve information flow.
[0094] S2-4-2, Global feature capture: To capture global context information, the module uses a custom QKV module. This module generates query, key and value tensors, then calculates the similarity between query and key to obtain attention weights. After softmax normalization, the calculated similarity is weighted with the value tensor to obtain the global feature.
[0095] S2-4-3, Feature fusion: Local features and global features are combined in the output stage. First, the global feature is added to the original input after a 1x1 convolution to obtain an enhanced feature representation. Finally, the local feature is added to the global feature to form the final output.
[0096] The local feature extraction formula is as follows:
[0097] (9);
[0098] (10);
[0099] The global feature extraction formula is as follows:
[0100] (11);
[0101] (12);
[0102] (13);
[0103] (14);
[0104] (15);
[0105] (16);
[0106] (17);
[0107] (18);
[0108] The final output formula is as follows:
[0109] (19);
[0110] wherein, represents input feature map, , , , respectively represent the results of different dilated rate (dilated rate is 1, 2, 3, 4 respectively) convolution operations on the input feature map , represents splicing, is a channel rearrangement operation, represents the feature map after channel rearrangement, represents 1x1 convolution operation, is the weight of 1x1 convolution operation when fusing the feature map after channel rearrangement, represents local feature , QKV_block represents a custom query-key-value module, Q represents a query tensor, K represents a key tensor, V represents a value tensor, is the 1x1 convolution weight of the branch, and the output dimension is , , represents pyramid pooling, represents flattening, is the 1x1 convolution weight of the branch, and the output dimension is consistent with , that is , is the 1x1 convolution weight of the branch, and the output dimension is V , , T represents matrix transposition, is a scaling factor, and sim_map represents a similarity matrix, is a normalization function that normalizes a numerical vector into a probability distribution vector, and dim represents the dimension, represents the normalized similarity matrix, W is the weight of 1x1 convolution operation when fusing the global feature, represents global feature.
[0111] In this embodiment, as shown in Figure 2 , a YOLOv12-based oil seal surface defect detection model is constructed, specifically:
[0112] The initialized input image is input to a 0th Conv module (standard convolution module), the output of the 0th Conv module is connected to the input of a 1st Conv module, the output of the 1st Conv module is connected to the input of a 2nd MSAF module (multi-scale attention fusion module), the output of the 2nd MSAF module is connected to the input of a 3rd Conv module and the input of a 16th Concat module, the output of the 3rd Conv module is connected to the input of a 4th MSAF module, the output of the 4th MSAF module is connected to the input of a 5th Conv module and the input of a 13th Concat module, the output of the 5th Conv module is connected to the input of a 6th A2C2f module (attention mechanism and feature fusion module), the output of the 6th A2C2f module is connected to the input of a 7th Conv module and the input of a 10th Concat module, the output of the 7th Conv module is connected to the input of an 8th A2C2f module, the output of the 8th A2C2f module is connected to the input of a 9th dynamic upsampling module and the input of a 25th Concat module.
[0113] The output of the 9th dynamic upsampling module is connected to the input of the 10th Concat module, the output of the 10th Concat module is connected to the input of an 11th A2C2f module, the output of the 11th A2C2f module is connected to the input of a 12th dynamic upsampling module and the input of a 22nd Concat module, the output of the 12th dynamic upsampling module is connected to the input of the 13th Concat module, the output of the 13th Concat module is connected to the input of a 14th A2C2f module, the output of the 14th A2C2f module is connected to the input of a 15th dynamic upsampling module and the input of a 19th Concat module, the output of the 15th dynamic upsampling module is connected to the input of a 16th Concat module, the output of the 16th Concat module is connected to the input of a 17th A2C2f module, the output of the 17th A2C2f module is connected to the input of an 18th Conv module and the input of a first 27th Detect module, the output of the 18th Conv module is connected to the input of a 19th Concat module, the output of the 19th Concat module is connected to the input of a 20th A2C2f module, the output of the 20th A2C2f module is connected to the input of a 21st Conv module and the input of a second 27th Detect module, the output of the 21st Conv module is connected to the input of a 22nd Concat module, the output of the 22nd Concat module is connected to the input of a 23rd A2C2f module, the output of the 23rd A2C2f module is connected to the input of a 24th Conv module and the input of a third 27th Detect module, the output of the 24th Conv module is connected to the input of a 25th Concat module, the output of the 25th Concat module is connected to the input of a 26th C3k2 module, and the output of the 26th C3k2 module is connected to the input of a fourth 27th Detect module.
[0114] The outputs of the first, second, third, and fourth Detect modules 27 constitute the output of the total feature.
[0115] Step S3, training the oil seal surface defect detection model using the training samples to obtain a trained MPD-YOLO model.
[0116] The MPD-YOLO model is trained according to the oil seal defect training set.
[0117] Step S4, evaluating the trained MPD-YOLO model and adjusting the MPD-YOLO model according to the evaluation result.
[0118] Specifically, the following steps are included:
[0119] S4-1, inputting the oil seal defect test set to the trained MPD-YOLO model to obtain an evaluation result according to the set key indicators: mAP (mean average precision), Precision (precision), and Recall (recall).
[0120] When evaluating the model performance on the validation set, the detection precision (Precision, P), recall rate (Recall, R), and mean average precision (Mean Average Precision, mAP) are used as evaluation indicators.
[0121] The detection precision measures the proportion of actual defect targets among all targets predicted by the model as defects, reflecting the accuracy of the model in identifying defects, and the calculation formula is as follows:
[0122] (20);
[0123] The recall rate represents the proportion of defect targets successfully detected by the model among all actual existing defect targets, measuring the coverage of the model on real targets, and the calculation formula is as follows:
[0124] (21);
[0125] In the formula, TP represents the number of correctly classified positive samples (actual defect, model detection result as defect); FP represents the number of incorrectly classified positive samples (actual normal, model detection result as defect); and FN represents the number of incorrectly classified negative samples (actual defect, model detection result as normal).
[0126] The mean average precision comprehensively considers the precision and recall performance of the model under different IoU thresholds, is usually calculated by the area under the precision-recall curve, and is an important indicator for evaluating the global performance of the model, and the calculation formula is as follows:
[0127] (22);
[0128] wherein, n represents the number of categories, i represents the category index, represents the function form of the precision-recall curve, P represents the precision, R represents the recall.
[0129] Through these evaluation indicators, the actual performance of the improved YOLOv12 model in oil seal surface defect detection can be comprehensively evaluated, ensuring the optimization of its accuracy and recall.
[0130] S4-2, adjusting the hyperparameters of the MPD-YOLO model according to the evaluation results to obtain an adjusted MPD-YOLO model.
[0131] The above implementation cases are only preferred embodiments of the present application, and do not limit the present application in any form. Although the present application has been disclosed as above with preferred embodiments, it is not intended to limit the present application. Therefore, any simple modification, equivalent change and modification made to the above embodiments without departing from the technical solution of the present application, in accordance with the technical essence of the present application, shall fall within the scope of protection of the technical solution of the present application.
Claims
1. An improved YOLOv12-based intelligent detection method for oil seal defects, characterized in that, The method comprises the following steps: Step S1, collecting image data of the oil seal and labeling to obtain an oil seal defect data set; Step S2, improving the network framework of the YOLOv12 model, and constructing an oil seal surface defect detection model based on the YOLOv12, namely an MPD-YOLO model; Step S3, training the MPD-YOLO model to obtain a trained MPD-YOLO model; Step S4, evaluating the trained MPD-YOLO model according to an oil seal defect test set, and adjusting the MPD-YOLO model according to the evaluation result; In the step S2, the operation of improving the network framework of the YOLOv12 model comprises the following operations: S2-1, adjusting the head level structure of the YOLOv12 model, fusing shallow semantic information, and adding a small target detection layer; S2-2, using a dynamic upsampling module to replace a nearest neighbor interpolation upsampling module of the YOLOv12 model; S2-3, using an MPDIoU loss function to replace a CIoU loss function of the YOLOv12 model; S2-4, using an MSAF module to replace a C3k2 module in a backbone network of the YOLOv12 model; The adjustment of the head level structure of the YOLOv12 model is that a group of small target detection layers P2 is added on the basis of three detection layers, then a P2 upsampling fusion module is added after a first detection layer P3, a second detection layer P4 and a two-round upsampling fusion module, and the P2 upsampling fusion module is connected to the small target detection layer P2; The specific structure of the MSAF module is that a double-branch parallel processing architecture is constructed from input features, a top branch in the double branch acquires multi-scale features by means of hole convolutions with expansion coefficients of 1, 2, 3 and 4, and the multi-scale features are spliced, and then the dimension is adjusted by channel scrambling and 1×1 convolution; a bottom branch in the double branch first performs multi-scale pooling by pyramid pooling, the pooled results are flattened and spliced, and then the spliced results are operated with a query vector extracted from the input features to generate weights acting on a value vector branch, and the value vector branch is output by 1×1 convolution; finally, the results of the top and bottom branches are output by element-wise addition operation to output enhanced features fused with multi-scale and attention mechanisms.
2. The improved YOLOv12-based oil seal defect intelligent detection method according to claim 1, characterized in that, In the dynamic upsampling module, the input feature map X is interpolated into a continuous feature map by bilinear interpolation; then, an offset O is generated by a linear layer, and the offset determines the position of the sampling point in the continuous space, and the sampling point is used to reconstruct the upsampled feature map X'.
3. The improved YOLOv12-based oil seal defect intelligent detection method according to claim 2, characterized in that, In the dynamic upsampling module, a sampling point generator based on a static range factor or a dynamic range factor is used to generate the sampling point.
4. The improved YOLOv12-based oil seal defect intelligent detection method according to claim 1, characterized in that, The evaluation of the trained MPD-YOLO model in the step S4 is performed in the following manner: The oil seal defect test set is input into the trained MPD-YOLO model, and evaluation results are obtained according to the set key indicators: average precision mean, precision and recall rate; The precision formula is: ; The recall rate formula is: ; In the formula, TP represents the number of correctly classified positive samples, FP represents the number of incorrectly classified positive samples, and FN represents the number of incorrectly classified negative samples; The average precision mean calculation formula is: ; wherein n denotes the number of classes, i denotes the class index, denotes the functional form of the precision-recall curve, P stands for precision, R stands for recall.
Citation Information
Patent Citations
Defect target detection method, system and equipment based on improved YOLOv5 and medium
CN119919646A
Penicillin bottle body defect detection method based on improved YOLOv8
CN120318607A
Cited By
Battery shell inner surface defect lightweight detection method based on channel grouping optimization and dual-domain enhancement
CN122434908A