Mechanical surface defect damage detection and identification method based on improved YOLOv8n
By improving the YOLOv8n model, introducing AKCDown convolution and CBAM modules, and using the Center-EIoU loss function, the problem of insufficient accuracy of traditional mechanical surface defect detection methods is solved, achieving higher detection accuracy and better adaptability.
Patent Information
- Application Number
- CN202411393148.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-01-21
AI Technical Summary
Traditional mechanical surface defect detection methods are difficult to deal with complex defect types, resulting in low detection accuracy, especially in high-precision manufacturing.
Adopting improved YOLOV8N models, through building an improved YOLOV8N network, including introducing AKCDOWN convolution and CBAM modules in the BackBone layer and NECK layer, and using the Center-EIIUU loss function to identify the target box.
It improves the accuracy of mechanical surface defect detection, enhances the accuracy of the model, can better adapt to the changing goals, reduce the calculation cost, and improve the detection effect.
Smart Images

Figure CN119338767A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of defect detection technology, and in particular to a method for detecting and identifying mechanical surface defects and damage based on an improved YOLOv8n. Background Art
[0002] Traditional methods for detecting mechanical surface defects mainly include manual detection, optical detection, electromagnetic detection, etc. The quality of the mechanical surface directly affects the appearance, performance and service life of the product; therefore, rapid and accurate detection and identification of mechanical surface defects is an important means to improve product quality and reduce production costs.
[0003] In recent years, with the rapid development of computer vision and deep learning technology, surface defect detection methods based on deep learning have gradually become a research hotspot; in recent years, deep learning technology has achieved remarkable results in the field of image processing, especially in target detection tasks.
[0004] Traditional mechanical surface defect detection methods include: relying on manual visual inspection, simple image processing algorithms (such as edge detection, threshold segmentation, etc.) or traditional machine learning methods; because mechanical surfaces usually have complex textures, lighting changes and noise interference, traditional algorithms are difficult to cope with complex defect types, resulting in low detection accuracy; the ability to distinguish between tiny defects or similar defects is poor, and false detection or missed detection problems are prone to occur, especially in high-precision manufacturing, where the requirements for accuracy are extremely high, and traditional methods are difficult to meet the needs. Summary of the invention
[0005] In view of the shortcomings of the existing methods, the present invention uses an improved YOLOv8n model to solve the problem of insufficient detection accuracy of traditional mechanical surface defect detection methods.
[0006] The technical solution adopted by the present invention is: based on the improved YOLOv8n mechanical surface defect damage detection and identification method, the following steps are included:
[0007] Step 1: Construct a data set of mechanical surface defects and damage;
[0008] As a preferred embodiment of the present invention, the defects and damage include: pressed iron oxide scale, patches, cracks, pitting surfaces, inclusions and scratches.
[0009] Step 2: Build an improved YOLOv8n network, replace the Conv convolution of the 8th layer of the Backbone layer with AKCDown convolution, and introduce the CBAM module after the SPPF module of the 10th layer of the backbone layer;
[0010] As a preferred embodiment of the present invention, AKCDown convolution includes: AKConv, Conv2d and DW convolution cascade; wherein, the parameters in AKConv convolution are set to: C, 2C, the parameter amount is 8, and the step size is 1; the parameters in Conv2d convolution are set to: 2C, 2C, kernel is 3, stride is 2, and group is 2C; the convolution kernel size of DW convolution is 3x3.
[0011] As a preferred embodiment of the present invention, improving the YOLOv8n network also includes: replacing the Conv convolution of the 21st layer of the Neck layer with an AKCDown convolution.
[0012] Step 3: Use the training set to train the improved YOLOv8n network, and use the target box loss to identify mechanical surface defects;
[0013] As a preferred implementation of the present invention, the target box loss function is Center-EIoU, which introduces penalty weights of the center point, width, and height to adjust the loss contribution of each part.
[0014] As a preferred implementation of the present invention, the formula of Center-EIoU is:
[0015]
[0016] Among them, w c and h c is the width and height of the minimum bounding box covering the two boxes, ρ is the Euclidean distance between the two points, and weight center To control the weight of the center point distance penalty, weight width Control the weight of the width penalty, weight height To control the weight of height penalty.
[0017] As a preferred embodiment of the present invention, the improved YOLOv8n network is evaluated using precision, recall and average precision.
[0018] As a preferred embodiment of the present invention, a mechanical surface defect and damage detection and identification system based on an improved YOLOv8n includes: a memory for storing instructions executable by a processor; and a processor for executing instructions to implement a mechanical surface defect and damage detection and identification method based on an improved YOLOv8n.
[0019] As a preferred embodiment of the present invention, a computer-readable medium stores a computer program code, and when the computer program code is executed by a processor, the computer program code implements a mechanical surface defect and damage detection and identification method based on the improved YOLOv8n.
[0020] Beneficial effects of the present invention:
[0021] 1. Based on YOLOv8n, the accuracy of the model is enhanced by introducing the CBAM attention mechanism. In addition, the original Conv is replaced in the backbone and head, and the constructed AKCDown module is introduced. The AKCDown module fuses SCDown and AKConv, giving the convolution kernel any number of parameters and any sampling shape, solving the problem that the convolution kernel with a fixed sample shape and a square cannot adapt well to the changing target; it provides more choices for the trade-off between network overhead and performance, and decouples space and channel;
[0022] 2. The AKCDown module first adjusts the number of channels through 1×1 point-by-point convolution, and then performs spatial downsampling through 3×3 depth convolution, which reduces the computational cost while retaining the information to the maximum extent;
[0023] 3. Center-EIOU separates the influencing factors of the aspect ratio of the predicted box and the true box based on the penalty term of CIOU, calculates the length and width of the predicted box and the true box respectively, and introduces the center penalty weight on this basis to enable the neural network to pay more attention to the center of the box, thereby solving the problems existing in CIOU and effectively improving the detection effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 It is a network structure diagram based on improved YOLOv8n of the present invention;
[0025] Figure 2 (a) and (b) are the structural diagrams of SCDown convolution and AKCDown convolution respectively. DETAILED DESCRIPTION
[0026] The present invention is further described below in conjunction with the accompanying drawings and embodiments. This figure is a simplified schematic diagram, which only illustrates the basic structure of the present invention in a schematic manner, and therefore it only shows the components related to the present invention.
[0027] like Figure 1 As shown, a mechanical surface defect and damage detection and recognition method based on improved YOLOv8n includes the following steps:
[0028] Step 1: Construct a data set of mechanical surface defects and damage;
[0029] The images of mechanical surface defects and damage of different types are collected. The defect and damage categories include: pressed oxide scale (RS), patch (Pa), crack (Cr), pitting surface (PS), inclusion (In) and scratch (Sc). A data set containing 1800 grayscale images is formed and annotated. 50 images are selected from the six categories to form a validation set, and the rest are training sets.
[0030] Step 2: Build an improved YOLOv8n network model;
[0031] like Figure 1 As shown in FIG. 1 , the improved YOLOv8n network includes: replacing the Conv convolution of the 8th layer of the Backbone layer with the AKCDown convolution, and introducing the CBAM module after the SPPF module of the 10th layer of the Backbone layer;
[0032] Improvements to the YOLOv8n network also include: replacing the Conv convolution of the 21st layer of the Neck layer with AKCDown convolution;
[0033] The Backbone layer is a basic feature extraction module responsible for extracting high-level features from the original input image. In the traditional YOLO structure, downsampling is performed through a pooling layer or a convolution layer. Since mechanical surface defects are usually very small, traditional Backbone layer detection will lose some defect detail information. The present invention uses AKCDown convolution to perform downsampling in a "Split-Concatenate" manner, and replaces the Conv convolution of the 8th layer of the backbone layer with AKCDown convolution, which can reduce the dimension while retaining more feature information.
[0034] The neck layer is responsible for fusing feature maps of different scales. Applying AKCDown convolution to the 21st neck layer can better transmit and fuse multi-scale information and avoid information loss, especially in tasks dealing with small targets or complex backgrounds, especially for the pressed iron oxide scale, patches, cracks, pitting surfaces, inclusions and scratches of the present invention, the performance is more stable when dealing with such small target defects.
[0035] The neck layer is responsible for fusing feature maps of different scales. Applying AKCDown convolution to the neck layer can better transmit and fuse multi-scale information and avoid information loss, especially in tasks dealing with small targets or complex backgrounds, and the performance is more stable.
[0036] like Figure 2As shown in the figure, AKCDown convolution replaces the first Conv in SCDown convolution with AKConv convolution; AKCDown convolution includes: AKConv, Conv2d and DW convolution; among them, AKConv convolution (C, 2C, num_param = 8, stride = 1), Conv2d convolution (2C, 2C, kernel = 3, stride = 2, group = 2C), and the convolution kernel size of DW convolution is 3x3.
[0037] By using the AKConv convolution kernel with any number of parameters and any sampling shape, the problem that the convolution kernel with fixed sample shape and square shape cannot adapt well to the changing target is solved. It provides more choices for the trade-off between network overhead and performance; Conv2d adjusts the number of channels through 1×1 point-by-point convolution; and then performs spatial downsampling through 3×3 DW convolution, which can reduce the computational cost while retaining the information to the maximum extent.
[0038] Center-EIoU separates the influencing factors of the aspect ratio of the predicted box and the real box based on the penalty term of CIoU, calculates the length and width of the predicted box and the real box respectively, and adds Focal to focus on the high-quality anchor box. On this basis, the introduction of the center penalty weight can make the neural network pay more attention to the center of the box to solve the problem of CIoU;
[0039] The calculation formula of CIoU is:
[0040] Among them, d is the distance between the center point of the predicted box and the real box, and c is the diagonal distance of the minimum enclosing rectangle.
[0041]
[0042] Among them, v is a correction factor used to further adjust the loss function to take into account the shape and direction of the target box; the formula for v is:
[0043]
[0044] Among them, (w G ,h G ) and (w P ,h P ) are the width and height of the target box and the predicted box respectively.
[0045] The original YOLOv8n network uses CIoU, which increases the computational complexity because CIOU introduces additional calculations of center point distance and diagonal distance. Therefore, compared with traditional IoU, the computational complexity has increased, the computational cost has increased, and the implementation is difficult. The calculation method of CIoU is relatively complex and requires more processing and calculation of the coordinates of the bounding box. Therefore, it may be relatively difficult to implement and requires more technical and experience support.
[0046] In response to the above problems, the CIoU loss was corrected and the innovative Center-EIOU loss was adopted, which is defined as follows:
[0047] The original EIoU consists of three parts: IoU loss, distance loss, and height-width loss (overlapping area, center point example, aspect ratio); the height-width loss directly minimizes the difference in height and width between the predicted target bounding box and the true bounding box, enabling faster convergence and better positioning results.
[0048]
[0049] Among them, w c and h c is the width and height of the minimum bounding box covering the two boxes, and ρ is the Euclidean distance between the two points; that is, the loss function is divided into three parts: IoU loss L IOU , distance loss L dis and direction loss L asp , the formula is:
[0050]
[0051] On this basis, Center-EIoU introduces penalty weights for center point, width, and height, where weight center To control the weight of the center point distance penalty, weight width Control the weight of the width penalty, weight height To control the weight of the height penalty, the three can flexibly adjust the contribution of each part to the final EIoU loss, which can retain the effective characteristics of the CIoU loss; at the same time, the Center-EIOU loss directly minimizes the difference between the width and height of the target box and the anchor box, thereby making the convergence faster and the positioning effect better.
[0052] Among them, the CBAM module adopts a lightweight attention mechanism, which can perform Attention operations in spatial and channel dimensions; CBAM contains two sub-modules, CAM (Channel Attention Module) and SAM (Spartial Attention Module), which perform channel and spatial attention respectively; this not only saves parameters and computing power, but also ensures plug-and-play and strong integration.
[0053] Improvements to the YOLOv8n network also include replacing CIoU with the innovative Center-EIoU.
[0054] Input the training set into the improved YOLOv8n network for training; build the experimental environment: use the Pytorch-GPU training framework and Python language implementation, use CUDA version 11.7, and GPU version NVIDIA GeForce GTX3080Ti. Set model parameters: set the image training size to 1024×1024; epoch to 200; batch-size to 16.
[0055] The test set images are input into the trained model, and the error is compared with the true standard information after the detection results are obtained.
[0056] Ablation experiment,In order to analyze the impact of different improvement strategies on the,detection performance of the algorithm, two groups of experiments were designed,and the training was completed under the premise of ensuring the same,data set and training parameters.,The experimental results are shown in the following table.
[0057] Table 1 shows the ablation experiment of the YOLOv8n model
[0058]
[0059]
[0060] Table 2 is the comparison results between the present invention and the YOLOv10n model
[0061]
[0062] Table 3 Comparison of different penalty weights
[0063]
[0064] It can be seen from Tables 1-3 that the precision rate of the present invention is improved by 13% compared with the YOLOv8n model, and the precision rate is also improved by 12% compared with the YOLOv10n model, and the recall rate is almost unaffected, indicating that the model of the present invention greatly improves the accuracy of mechanical surface defect detection.
[0065] Based on the above ideal embodiments of the present invention, the relevant staff can make various changes and modifications without departing from the technical concept of the present invention through the above description. The technical scope of the present invention is not limited to the contents of the specification, and its technical scope must be determined according to the scope of the claims.
Claims
1. Based on the improved YOLOv8n mechanical surface defect damage detection and recognition method, it is characterized by: The following steps are involved: Step 1: Construct a data set of mechanical surface defects and damage; Step 2: Build an improved YOLOv8n network, replace the Conv convolution of the 8th layer of the Backbone layer with AKCDown convolution, and introduce the CBAM module after the SPPF module of the 10th layer of the backbone layer; Step 3: Use the training set to train the improved YOLOv8n network, and use the target box loss function to identify mechanical surface defects.
2. According to the improved YOLOv8n mechanical surface defect detection and identification method according to claim 1, it is characterized in that: Replace the Conv convolution of the 21st layer of the Neck layer with AKCDown convolution.
3. The method for detecting and identifying mechanical surface defects and damage based on improved YOLOv8n according to claim 1 or 2, characterized in that: AKCDown convolution includes: AKConv, Conv2d and DW convolution cascade; among them, the parameters in AKConv convolution are set to: C, 2C, the parameter amount is 8, and the step size is 1; the parameters in Conv2d convolution are set to: 2C, 2C, kernel is 3, stride is 2, group is 2C; the convolution kernel size of DW convolution is 3x3.
4. The method for detecting and identifying mechanical surface defects and damage based on improved YOLOv8n according to claim 1 is characterized in that: The target box loss function is Center-EIoU, which introduces penalty weights for the center point, width, and height to adjust the loss contribution of each part.
5. According to the improved YOLOv8n mechanical surface defect detection and identification method according to claim 4, it is characterized in that: The formula for Center-EIoU is: Among them, w c and h c is the width and height of the minimum bounding box covering the two boxes, ρ is the Euclidean distance between the two points, and weight center To control the weight of the center point distance penalty, weight width Control the weight of the width penalty, weight height To control the weight of height penalty.
6. The method for detecting and identifying mechanical surface defects and damage based on improved YOLOv8n according to claim 1 is characterized in that: The improved YOLOv8n network is evaluated using precision, recall and average precision.
7. The method for detecting and identifying mechanical surface defects and damage based on improved YOLOv8n according to claim 1 is characterized in that: Defects and damage include: pressed iron scale, patches, cracks, pitting surfaces, inclusions and scratches.
8. Based on the improved YOLOv8n mechanical surface defect damage detection and recognition system, it is characterized by: include: a memory for storing instructions executable by a processor; A processor, used to execute instructions to implement the mechanical surface defect and damage detection and identification method based on improved YOLOv8n as described in any one of claims 1 to 7.
9. A computer readable medium storing a computer program code, characterized in that: When the computer program code is executed by a processor, the method for detecting and identifying mechanical surface defects and damages based on the improved YOLOv8n as described in any one of claims 1 to 7 is implemented.