Defect detection method based on improved YOLOV8
By embedding the EMSC and SE attention modules in the YOLOV8 algorithm, and using the AFPN architecture and Inner-CIoU loss function, the problem of multi-scale feature output and low efficiency of the YOLOV8 algorithm in defect detection is solved, and the detection accuracy and efficiency are improved.
Patent Information
- Application Number
- CN202410320232.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-20
- Publication Date
- 2024-09-03
AI Technical Summary
The existing YOLOV8 algorithm cannot achieve multi-scale feature output in defect detection. The recognition accuracy is low, the model parameters are large, the detection efficiency is low, and it cannot meet the needs of real-time and efficient detection.
Based on the YOLOV8 algorithm framework, the EMSC module and the SE attention module are embedded into the Bottleneck of the C2f module, using the AFPN architecture and Inner-CIoU loss function, and introducing the residual unit through feature alignment and convolution kernels and Stride with different sampling rates. Generate multi-scale feature output and progressive feature fusion.
It reduces the amount of model parameters and calculations, improves the recognition speed and target detection accuracy, enhances the model's performance and computational efficiency for defect detection, and achieves more efficient target detection.
Smart Images

Figure CN118587146A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of target detection technology, and in particular to a defect detection method based on improved YOLOV8. Background Art
[0002] In modern industrial production, the quality of basic accessories such as pipes and wood boards has an important impact on the performance and life of the finished products. When these basic accessories are defective, such as automobile screws and nuts, and built-in pipes in houses, it is easy to cause safety and performance hazards in the assembled products. For targets that need to be inspected for defects, people usually use manual visual observation or pressure testing to determine whether they have defects. This method is time-consuming and easily affected by subjective factors. The number of test individuals is also limited, and it cannot meet the needs of efficient and accurate inspection of large quantities of inspection objects.
[0003] With the rapid development of computer vision and artificial intelligence technology, target detection algorithms based on deep learning have become an effective solution for defect detection. Target detection algorithms based on deep learning are divided into two categories: two-stage and single-stage. Two-stage algorithms such as Fast R-CNN and Faster R-CNN generate candidate regions and then perform classification and regression to improve accuracy, which is suitable for scenarios with high detection accuracy requirements. Single-stage algorithms such as the YOLO series and SSD series directly output target information end-to-end, with the advantages of faster detection speed, high efficiency and lightweight, and are particularly suitable for applications with high real-time requirements. Among them, the YOLOV8 algorithm is an advanced target detection algorithm with high accuracy and real-time performance. The algorithm can automatically detect and identify tool defects by building a deep neural network model, thereby improving detection efficiency and accuracy. However, due to the structural characteristics of the YOLOV8 algorithm, when it is directly used to build a deep neural network model for defect recognition of the detected object, it cannot achieve multi-scale feature output, has low recognition accuracy, and requires a large number of model parameters, resulting in low detection efficiency. Summary of the invention
[0004] In order to solve the above problems existing in the prior art, the present invention provides a defect detection method based on improved YOLOV8. On the basis of the YOLOV8 algorithm framework, the EMSC module and the SE attention module are embedded in the Bottleneck of the C2f module to reduce the number of parameters and the amount of calculation of the model, and improve the recognition speed and target detection accuracy of the model. At the same time, the AFPN architecture is introduced to adopt a progressive strategy to generate multi-scale feature outputs, and the performance and computational efficiency of the model for defect detection are improved by feature alignment and preparation, convolution kernels and strides with different sampling rates, and the introduction of residual units. The technical solution provided by the present invention is as follows:
[0005] According to one aspect of an embodiment of the present invention, a defect detection method based on improved YOLOV8 is provided, wherein the method comprises:
[0006] S10: Acquire an image of the detected object;
[0007] S20: marking defect features in each inspection object image to construct an inspection object defect image dataset;
[0008] S30: Construct and initialize an improved YOLOV8 convolutional neural network detection model, train and optimize the improved YOLOV8 convolutional neural network detection model according to the defect image dataset of the detection object, and obtain a defect detection neural network model corresponding to the detection object; the improved YOLOV8 convolutional neural network detection model is based on the YOLOV8 detection algorithm framework, embeds the EMSC module and the SE attention module in the Bottleneck layer of the three C2f modules after the Backbone layer, and replaces the CIoU loss function with the Inner-CIoU loss function, and replaces the FPN architecture of the Neck layer with the AFPN architecture.
[0009] In a preferred embodiment, in the Backbone layer of the improved YOLOV8 convolutional neural network detection model, the EMSC module is used to divide the input into two parts, X1 and X2, in the channel dimension, and group X2 in the channel dimension into four groups, and the convolution kernel size of each group is 1, 3, 3, and 5, respectively. After the convolution operation, the result is stacked with X1, and finally 1×1 convolution is used to fuse the features after convolution of each group, and no activation function is used between each group of convolution and 1×1 convolution.
[0010] In a preferred embodiment, the SE attention module is used to perform global pooling on the input (H×W×C), the pooling size is (H, W), the output feature map size is 1×1×C, and the number of neurons connecting the two fully connected layers is C / 16 and C respectively; ReLu and Sigmoid activation functions are used respectively to increase the nonlinear factor, and a 1×1×C feature map is output from the Sigmoid layer. Finally, the input (H×W×C) and the feature map are fully multiplied to output channel feature maps of different weights, with a size of (H, W, C); the Bottleneck layer of the C2f module is composed of a Conv module, an EMSC module and a SE attention module.
[0011] In a preferred embodiment, in the Backbone layer of the improved YOLOV8 convolutional neural network detection model, the Inner-CIoU loss function calculates the IoU loss through the auxiliary border, introduces a scale factor ratio to control the scale of the auxiliary border for calculating the loss, and the calculation method of the Inner-CIoU loss function is as shown in formulas (1)-(8):
[0012]
[0013]
[0014]
[0015]
[0016]
[0017] union=(w gt *h gt )*(ratio) 2 +(w*h)*(ratio) 2 -inter formula(6)
[0018]
[0019] L Inner-CIoU =L CIoU +IoU-IoU inner Formula (8)
[0020] in, represents the center point of the GT bounding box and the inner GT bounding box, (x c ,y c ) represents the center point of the anchor box and the internal anchor box; represents the left boundary of the GT bounding box, represents the right boundary of the GT bounding box, represents the upper boundary of the GT bounding box, represents the lower boundary of the GT bounding box, inter represents the intersection area of the GT bounding box and the predicted bounding box, and union represents the union area of the GT bounding box and the predicted bounding box; the width and height of the GT box are represented by w gt and h gt , and the width and height of the anchor box are represented as w and h respectively; the variable ratio is the scale factor, and its value range is [0.5, 1.5].
[0021] In a preferred embodiment, in the Neck layer of the improved YOLOV8 convolutional neural network detection model, AFPN adopts a progressive feature fusion method, determines the features output by the three C2f modules after the Backbone layer as {C1, C2, C3}, and then inputs the low-level features C1 and C2 into the feature pyramid network, and then adds C3 to gradually integrate low-level, high-level and highest-level features, and after feature fusion, generates a set of multi-scale features {P1, P2, P3}.
[0022] Compared with the prior art, the defect detection method based on improved YOLOV8 provided by the present invention has the following advantages:
[0023] The present invention provides a defect detection method based on improved YOLOV8. On the basis of the YOLOV8 algorithm, an EMSC module and an SE attention module are embedded in the Bottleneck of C2f, thereby reducing the number of parameters and the amount of calculation of the model, and improving the recognition speed of the model and the target detection accuracy. In addition, compared with the traditional FPN, the introduced AFPN architecture adopts a progressive strategy in the feature fusion process to generate multi-scale feature outputs, and improves the performance and computational efficiency of the model detection through methods such as feature alignment and preparation, application of convolution kernels and strides with different sampling rates, and introduction of residual units, thereby improving the detection capability and computational efficiency of the model target by using multi-scale features and a progressive feature fusion strategy. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0025] Figure 1 It is a method flow chart of a defect detection method based on improved YOLOV8 according to an exemplary embodiment of the present invention.
[0026] Figure 2 It is a structural diagram of the Bottleneck layer of an existing C2f module.
[0027] Figure 3 1 is a schematic structural diagram of an improved Bottleneck layer of a C2f module according to an exemplary embodiment of the present invention.
[0028] Figure 4 FIG. 4 is a schematic diagram showing the structure of an EMSC module according to an exemplary embodiment of the present invention.
[0029] Figure 5 FIG. 4 is a schematic diagram showing the structure of an SE module according to an exemplary embodiment of the present invention.
[0030] Figure 6 FIG. 4 is a schematic diagram of the structure of an AFPN according to an exemplary embodiment of the present invention.
[0031] Figure 7 It is a schematic diagram of the structure of an improved YOLOV8 convolutional neural network detection model according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention is described in detail below in combination with specific embodiments (but not limited to the embodiments) and the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0033] Figure 1 is a method flow chart of a defect detection method based on improved YOLOV8 according to an exemplary embodiment of the present invention. Figure 1 As shown, the defect detection method based on improved YOLOV8 includes:
[0034] S10: Acquire an image of the detected object.
[0035] The test objects can be basic accessories with high surface integrity requirements such as pipe fittings and automobile screws.
[0036] S20: Label the defect features in each inspection object image to construct an inspection object defect image dataset.
[0037] Defect features may be cracks, burrs, and the like.
[0038] In a feasible embodiment, the data set is divided into a training set, a validation set, and a test set in a ratio of 8:1:1.
[0039] S30: Construct and initialize an improved YOLOV8 convolutional neural network detection model, train and optimize the improved YOLOV8 convolutional neural network detection model according to the defect image dataset of the detection object, and obtain a defect detection neural network model corresponding to the detection object; the improved YOLOV8 convolutional neural network detection model is based on the YOLOV8 detection algorithm framework, embeds the EMSC module and the SE attention module in the Bottleneck layer of the three C2f modules after the Backbone layer, and replaces the CIoU loss function with the Inner-CIoU loss function, and replaces the FPN architecture of the Neck layer with the AFPN architecture.
[0040] It should be noted that the Bottleneck layer of the C2f module in the existing YOLOV8 algorithm consists of two consecutive Conv modules, such as Figure 2 As shown; and the improved Bottleneck of the embodiment of the present invention is composed of a Conv module, an EMSC module and a SE attention module, as shown Figure 3 Optionally, the structural diagram of the EMSC module provided by the present invention can be as shown in Figure 4 As shown in the figure, the EMSC module contains a convolution group consisting of multiple convolution layers and a final 1x1 convolution layer, and each convolution layer in the convolution group has the same number of output channels, which is determined by 1 / 4 of the number of input channels.
[0041] In a preferred embodiment, in the Backbone layer of the improved YOLOV8 convolutional neural network detection model, the EMSC module is used to divide the input into two parts, X1 and X2, in the channel dimension, and group X2 in the channel dimension into four groups, and the convolution kernel size of each group is 1, 3, 3, and 5, respectively. After the convolution operation, the result is stacked with X1, and finally 1×1 convolution is used to fuse the features after convolution of each group, and no activation function is used between each group of convolution and 1×1 convolution.
[0042] In the forward propagation method of the EMSC module of the embodiment of the present invention, the input tensor x is first divided into two parts in the channel dimension: X1 and X2, and then a convolution operation is performed according to the following steps:
[0043] 1) Transform the shape of X2 and group the channel dimensions to obtain multi-scale information.
[0044] 2) Perform convolution operations on each convolution kernel size and stack the results together to obtain a tensor containing the outputs of multiple convolution groups.
[0045] 3) Rearrange the outputs of multiple convolution groups into their original shape.
[0046] 4) Connect X1 and X2 processed by multi-scale convolution in the channel dimension.
[0047] 5) Performing a 1x1 convolution operation on the connected features helps to fuse information on the connected feature map.
[0048] Optionally, the present invention provides a structural diagram of a SE attention module as follows: Figure 5 As shown in Figure 1, the SE module contains a global pooling layer and two fully connected layers. Finally, the weight value output by the last fully connected layer is multiplied by the original feature map.
[0049] In a preferred embodiment, the SE attention module is used to perform global pooling on the input (H×W×C), the pooling size is (H, W), the output feature map size is 1×1×C, and the number of neurons connecting the two fully connected layers is C / 16 and C respectively; ReLu and Sigmoid activation functions are used respectively to increase the nonlinear factor, and a 1×1×C feature map is output from the Sigmoid layer. Finally, the input (H×W×C) and the feature map are fully multiplied to output channel feature maps of different weights, with a size of (H, W, C).
[0050] The SE attention module of the embodiment of the present invention performs a convolution operation in the forward propagation method according to the following steps:
[0051] 1) Perform global pooling on the input X(H×W×C) with a pooling size of (H,W) and an output feature map size of 1×1×C.
[0052] 2) The number of neurons connecting the two fully connected layers are C / 16 and C respectively.
[0053] 3) Use ReLu activation function for the first fully connected layer.
[0054] 4) Use Sigmoid activation function for the first fully connected layer.
[0055] 5) Output the 1×1×C feature map from the Sigmoid layer.
[0056] 6) Multiply the input X (H × W × C) by the feature map (1 × 1 × C) output by the Sigmoid layer.
[0057] 7) Output channel feature maps of different weights, with a size of (H×W×C).
[0058] The Bottleneck layer of the C2f module consists of a Conv, an EMSC module and a SE attention module.
[0059] In a preferred embodiment, in the Neck layer of the improved YOLOV8 convolutional neural network detection model, AFPN adopts a progressive feature fusion method, determines the features output by the three C2f modules after the Backbone layer as {C1, C2, C3}, and then inputs the low-level features C1 and C2 into the feature pyramid network, and then adds C3 to gradually integrate low-level, high-level and highest-level features, and after feature fusion, generates a set of multi-scale features {P1, P2, P3}.
[0060] The structural diagram of AFPN can be shown as Figure 6As shown. It should be noted that the traditional FPN directly fuses features of all levels during feature fusion. In contrast, the AFPN adopted in the present invention adopts a progressive feature fusion process, gradually integrating low-level, high-level and highest-level features, which makes the semantic gap between features at different levels gradually reduce during the fusion process, which helps to better capture the semantic information in the image. AFPN uses different convolution kernels and strides to perform downsampling according to the required downsampling rate, so as to flexibly adapt to different image scales. This adaptability makes AFPN more robust when processing images of different resolutions, and can better cope with the scale changes of target objects in the image.
[0061] Exemplarily, the structural schematic diagram of the improved YOLOV8 convolutional neural network detection model provided by the present invention can be as follows: Figure 7 shown.
[0062] AFPN reduces the semantic gap between non-adjacent level features by introducing progressive feature fusion, which is crucial to improving the performance of object detection, especially when different levels of semantic information are involved, enabling better feature fusion.
[0063] In a preferred embodiment, the formula for multi-level feature fusion is as follows:
[0064]
[0065] Formula (9) represents the fusion of three levels of features. represents the feature vector at position (i, j) from Level n to Level l. The resulting feature vector is expressed as Obtained through adaptive spatial fusion of multi-level features and linear combination of feature vectors and and represents the spatial weight of the features of the three levels at Level l, and the constraints are
[0066] The present invention improves the performance of the target detection algorithm for multi-scale and multi-resolution images by introducing progressive feature fusion and adaptive operations for different sampling rates.
[0067] In a preferred embodiment, in the Backbone layer of the improved YOLOV8 convolutional neural network detection model, the Inner-CIoU loss function calculates the IoU loss through the auxiliary border, introduces a scale factor ratio to control the scale of the auxiliary border for calculating the loss, and the calculation method of the Inner-CIoU loss function is as shown in formulas (1)-(8):
[0068]
[0069]
[0070]
[0071]
[0072]
[0073] union=(w gt *h gt )*(ratio) 2 +(w*h)*(ratio) 2 -inter formula(6)
[0074]
[0075] L Inner-CIoU =L CIoU +IoU-IoU inner Formula (8)
[0076] in, represents the center point of the GT bounding box and the inner GT bounding box, (x c ,y c ) represents the center point of the anchor box and the internal anchor box; represents the left boundary of the GT bounding box, represents the right boundary of the GT bounding box, represents the upper boundary of the GT bounding box, represents the lower boundary of the GT bounding box, inter represents the intersection area of the GT bounding box and the predicted bounding box, and union represents the union area of the GT bounding box and the predicted bounding box; the width and height of the GT box are represented by w gt and h gt , and the width and height of the anchor box are represented as w and h respectively; the variable ratio is the scale factor, and its value range is [0.5, 1.5].
[0077] (3) Modify the loss function of YOLOV8, use the Inner-CIoU loss function instead of the CIoU loss function, and integrate the Inner-IoU into the existing CIoU loss function to obtain faster and more effective regression results. The IoU loss is calculated through the auxiliary border, and the scale factor ratio is introduced to control the scale of the auxiliary border for calculating the loss. The value of the ratio needs to be adjusted for different sample sizes. If the sample to be predicted is a medium or large sample, the value of the ratio can be set between 0.65 and 0.85, and the auxiliary border that is smaller than the actual border will generate a gain for the high IoU sample. If the sample to be predicted is a small sample, the value of the ratio can be set between 1.15 and 1.30, and the effect of accelerating convergence for low IoU samples is achieved by generating a larger auxiliary border.
[0078] In an optional embodiment, the hyperparameter imgsz is set to 640, epochs is set to 300, batch is set to 16, the initial learning rate Init_lr=0.01, the minimum learning rate Min_lr=0.0001, cosine learning rate scheduling is used, SGD is used as the optimizer, and the Mosaic data enhancement method is used. After the parameters of the improved YOLOV8 network structure are set, it is placed in a computer with a configured environment, and the improved YOLOV8 convolutional neural network detection model is trained and optimized using the defect image data set of the inspection object, and the parameter optimization model is adjusted to obtain a defect detection neural network model corresponding to the inspection object.
[0079] The defect detection method provided by the present invention can more effectively perceive and learn features of different scales and different semantics by embedding the EMSC module in the C2f module, thereby improving the network's ability to express multi-level information; AFPN uses a progressive feature fusion process to gradually integrate low-level, high-level and highest-level features. This makes the semantic gap between features at different levels gradually decrease during the fusion process, and can better fuse features. In addition, AFPN has fewer parameters than FPN, which improves computational efficiency. Finally, Inner-CIoU is used as the loss function to accelerate the convergence speed of the model and improve the detection accuracy of the model.
[0080] Compared with the prior art, the defect detection method based on improved YOLOV8 provided by the present invention has the following advantages:
[0081] The present invention provides a defect detection method based on improved YOLOV8. On the basis of the YOLOV8 algorithm, an EMSC module and an SE attention module are embedded in the Bottleneck of C2f, thereby reducing the number of parameters and the amount of calculation of the model, and improving the recognition speed of the model and the target detection accuracy. In addition, compared with the traditional FPN, the introduced AFPN architecture adopts a progressive strategy in the feature fusion process to generate multi-scale feature outputs, and improves the performance and computational efficiency of the model detection through methods such as feature alignment and preparation, application of convolution kernels and strides with different sampling rates, and introduction of residual units, thereby improving the detection capability and computational efficiency of the model target by using multi-scale features and a progressive feature fusion strategy.
[0082] Although the present invention has been described in detail above with general description, specific implementation and test, it is obvious to those skilled in the art that modifications or improvements can be made on the basis of the present invention. Therefore, these modifications or improvements made without departing from the spirit of the present invention all belong to the scope of protection claimed in the present invention. Those skilled in the art will easily think of other embodiments of the present invention after considering the specification and practicing the invention here. The present invention is intended to cover any modification, use or adaptation of the present invention, which follows the general principles of the present invention and includes common knowledge or customary technical means in the art that are not disclosed in the present invention. It should be understood that the present invention is not limited to the precise structure described above and shown in the drawings, and various modifications and changes can be made without departing from its scope.
Claims
1. A defect detection method based on improved YOLOV8, characterized in that: The method comprises: S10: Acquire an image of the detected object; S20: marking defect features in each inspection object image to construct an inspection object defect image dataset; S30: Construct and initialize an improved YOLOV8 convolutional neural network detection model, train and optimize the improved YOLOV8 convolutional neural network detection model according to the defect image dataset of the detection object, and obtain a defect detection neural network model corresponding to the detection object; the improved YOLOV8 convolutional neural network detection model is based on the YOLOV8 detection algorithm framework, embeds the EMSC module and the SE attention module in the Bottleneck layer of the three C2f modules after the Backbone layer, and replaces the CIoU loss function with the Inner-CIoU loss function, and replaces the FPN architecture of the Neck layer with the AFPN architecture.
2. The method according to claim 1, characterized in that In the Backbone layer of the improved YOLOV8 convolutional neural network detection model, the EMSC module is used to divide the input into two parts, X1 and X2, in the channel dimension, and group X2 in the channel dimension into four groups, and the convolution kernel size of each group is 1, 3, 3, and 5 respectively. After the convolution operation, the result is stacked with X1, and finally 1×1 convolution is used to fuse the features after convolution of each group, and no activation function is used between each group of convolution and 1×1 convolution.
3. The method according to claim 1, characterized in that The SE attention module is used to perform global pooling on the input (H×W×C), the pooling size is (H, W), the output feature map size is 1×1×C, and the number of neurons connecting the two fully connected layers is C / 16 and C respectively; ReLu and Sigmoid activation functions are used respectively to increase the nonlinear factor, and a 1×1×C feature map is output from the Sigmoid layer. Finally, the input (H×W×C) and the feature map are fully multiplied to output channel feature maps of different weights, with a size of (H, W, C); the Bottleneck layer of the C2f module consists of a Conv module, an EMSC module and a SE attention module.
4. The method according to claim 1, characterized in that: In the Backbone layer of the improved YOLOV8 convolutional neural network detection model, the Inner-CIoU loss function calculates the IoU loss through the auxiliary border, and introduces the scale factor ratio to control the scale of the auxiliary border for calculating the loss. The calculation method of the Inner-CIoU loss function is as shown in formulas (1)-(8): union = (w gt *h gt )*(ratio) 2 +(w*h)*(ratio) 2 -inter Official(6) L Inner-CIoU =L CIoU +IoU-IoU inner Formula (8) in, represents the center point of the GT bounding box and the inner GT bounding box, (x c ,y c ) represents the center point of the anchor box and the internal anchor box; represents the left boundary of the GT bounding box, represents the right boundary of the GT bounding box, represents the upper boundary of the GT bounding box, represents the lower boundary of the GT bounding box, inter represents the intersection area of the GT bounding box and the predicted bounding box, and union represents the union area of the GT bounding box and the predicted bounding box; the width and height of the GT box are represented by w gt and h gt , and the width and height of the anchor box are represented as w and h respectively; the variable ratio is the scale factor, and its value range is [0.5, 1.5].
5. The method according to claim 1, characterized in that In the Neck layer of the improved YOLOV8 convolutional neural network detection model, AFPN adopts a progressive feature fusion method, determines the features output by the three C2f modules after the Backbone layer as {C1, C2, C3}, and then inputs the low-level features C1 and C2 into the feature pyramid network, and then adds C3 to gradually integrate low-level, high-level and highest-level features, and after feature fusion, generates a set of multi-scale features {P1, P2, P3}.
Citation Information
Cited By
Intelligent detection method and device for state of cotter pin of tower crane
CN119181034A
Strain clamp defect detection method based on unmanned aerial vehicle digital X-ray
CN119380227A
