A high-reflective cylinder workpiece surface defect detection method based on an improved YOLOv8 model

By improving the Bottleneck module and feature fusion technology of the YOLOv8 model, and combining it with a rolling device and a line scan camera, the efficiency and accuracy problems of surface defect detection for highly reflective cylindrical workpieces were solved, achieving efficient industrial defect detection.

CN118351054BActive Publication Date: 2026-11-27NINGBO INST OF TECH ZHEJIANG UNIV ZHEJIANG
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410310840.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-19
Publication Date
2026-11-27
Estimated Expiration
2044-03-19

Smart Images

  • Figure CN118351054B_ABST
    Figure CN118351054B_ABST
Patent Text Reader

Abstract

This invention discloses a method for detecting surface defects on highly reflective cylindrical workpieces based on an improved YOLOv8 model, relating to the field of defect detection. The method involves acquiring an image of the workpiece surface to be detected and inputting it into an improved YOLOv8 model to determine the location and type of defects. The model's network structure includes an improved C2f structure in the Backbone module, with the Bottleneck module constructed according to a preset multi-scale parallel convolution strategy. This effectively extracts weak defect features from the workpiece surface, improving robustness to complex environments and diverse defects. The head module employs a BIFPN structure, facilitating better capture of feature representations at different scales. Furthermore, the Fusion module within the head module is constructed according to a preset weighted fusion mechanism, enhancing the network's ability to process objects of different sizes and complexities. Therefore, this approach improves the accuracy and efficiency of surface defect detection for workpieces.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of defect detection technology, and more specifically, to a method for detecting surface defects of highly reflective cylindrical workpieces based on an improved YOLOv8 model. Background Technology

[0002] Equipment malfunctions or human error can both lead to product defects, such as scratches, spots, structural breaks, and bends. These defects can affect the product's lifespan and, in severe cases, even pose safety hazards. For example, the surface quality of the piston connecting rod in a car's shock absorber directly determines the shock absorber's lifespan and performance. Therefore, there are currently two main methods for detecting product defects and completing quality monitoring:

[0003] The first method is the traditional method, which relies on human eyes to observe and classify defects. However, this method is inefficient and highly subjective. The second method uses technologies such as industrial imaging and machine vision to locate and classify defects based on the product's color, shape, and other characteristics. However, this method has significant limitations when dealing with complex environments and small, diverse defects, and its effectiveness in practical applications is often poor, making it difficult to meet the inspection needs of the production site.

[0004] In addition, workpiece defect samples suffer from low visibility, meaning that surface defects are often only a small area in high-resolution images, with low contrast to the surrounding background and insufficient significance. Furthermore, noise introduced during imaging can also interfere with defect detection. Therefore, designing a scheme with good environmental adaptability and robust feature extraction to achieve defect detection on workpiece surfaces is an urgent problem to be solved. Summary of the Invention

[0005] The problem solved by this invention is to provide a method for detecting surface defects of highly reflective cylindrical workpieces based on an improved YOLOv8 model, which can effectively improve the detection accuracy and efficiency of surface defects of workpieces compared with traditional vision algorithms.

[0006] To address the above problems, this invention provides a method for detecting surface defects in highly reflective cylindrical workpieces based on an improved YOLOv8 model, comprising:

[0007] Acquire the image of the surface of the workpiece to be inspected;

[0008] The image to be detected is input into a pre-trained improved YOLOv8 model to determine the location of defects on the surface of the workpiece and the type of the defects.

[0009] The improved YOLOv8 model's network structure includes a Backbone module and a head module. The Backbone module contains an improved C2f structure, and the Bottleneck module in the improved C2f structure is constructed based on a preset multi-scale parallel convolution strategy that can extract weak defect features. The head module is constructed using a BIFPN structure, and the Fusion module in the head module used for feature fusion is constructed based on a preset weighted fusion mechanism that can combine multiple feature maps of different resolutions input to itself.

[0010] The beneficial effects of this invention are as follows: The backbone module contains an improved C2f structure, and the Bottleneck module in the improved C2f structure is constructed according to a preset multi-scale parallel convolution strategy, which can effectively extract weak defect features on the workpiece surface, thus improving robustness to complex environments and diverse defects; the head module is constructed using a BIFPN structure, which is conducive to better capturing feature representations at different scales, and the Fusion module in the head module is constructed according to a preset weighted fusion mechanism, which can combine features at different levels to ensure optimal feature integration, thereby improving the network's ability to process objects of different sizes and complexities. In summary, the solution provided by this application is beneficial to improving the detection accuracy and efficiency of surface defects on workpieces, saving manual inspection costs, and is beneficial to practical production applications.

[0011] Furthermore, the Backbone module includes an inherent C2f structure and at least one improved C2f structure, and the number of input channels of the CBS structure located one layer above the improved C2f structure is greater than a preset channel limit threshold.

[0012] In this scheme, the above settings can be used to improve the C2f structure while ensuring parameter control, thereby effectively enhancing the model's robustness to complex environments and diverse defects, resulting in better practical application performance.

[0013] Furthermore, the Bottleneck module is constructed according to the preset multi-scale parallel convolution strategy, including:

[0014] Determine g groups of convolution kernels of different sizes, where g is an even number greater than 1;

[0015] For each of the aforementioned convolutional kernels, a corresponding convolutional layer is established;

[0016] The minimum number of channels is determined by dividing the channel by the g, where the channel is the number of channels of the first image input to the Bottleneck module;

[0017] The channels are grouped according to the minimum number of channels, and the g sub-images with the minimum number of channels are respectively input into the g convolutional layers;

[0018] The outputs of each convolutional layer are stacked and merged, and the processed result is fed into a 1*1 convolutional layer. The convolution result of the 1*1 convolutional layer is used as the output of the Bottleneck submodule.

[0019] Furthermore, the Fusion module is constructed according to the preset weighted fusion mechanism, including:

[0020] Initialize the predefined variable ans, which is used to store the cumulative result;

[0021] For multiple feature maps of different resolutions input to the Fusion module, determine whether the size of each feature map is the same as the preset target size of the expected output feature map;

[0022] If not, the size of the feature map is matched to the preset target size according to the preset size matching strategy, and the processed result is passed through a preset convolutional layer and then multiplied element-wise with the current ans variable to obtain the enhanced feature.

[0023] Store the enhanced features into the ans variable;

[0024] After determining that the size of each feature map matches the preset target size, the stored result in the ans variable is determined to be the output of the Fusion module.

[0025] In this scheme, the feature fusion mechanism described above can combine features at different levels. The fusion weights are learned during training, ensuring optimal feature integration and improving the network's ability to process objects of different sizes and complexities.

[0026] Furthermore, matching the size of the feature map to the preset target size according to a preset size matching strategy includes:

[0027] Determine whether the size of the feature map is larger than the preset target size;

[0028] If the size is larger than the preset target size, downsampling is performed according to the average pooling operation to match the size of the feature map larger than the preset target size to the preset target size;

[0029] If the size is smaller than the target size, upsampling is performed using bilinear interpolation to match the size of the feature map smaller than the preset target size to the preset target size.

[0030] Furthermore, acquiring an image of the surface of the workpiece to be inspected includes:

[0031] Drive the rolling device to control the movement of the workpiece mounted on the rolling device;

[0032] The workpiece is captured by a line scan camera during its movement, and the captured images are then stitched together to obtain a complete image of the workpiece's surface to be inspected.

[0033] In this solution, the above settings can better capture a complete 360-degree image of the workpiece surface to be inspected, laying the foundation for accurate defect detection in the future.

[0034] Furthermore, the improved YOLOv8 model is pre-trained based on a training dataset, and the steps for determining the training dataset include:

[0035] Determine the base sample image;

[0036] The location of defects in the base sample image and the type of the defects are labeled;

[0037] Data augmentation operations are performed on the base sample images to use the augmented dataset as a training dataset. The data augmentation operations include one or more combinations of mirroring, horizontal flipping, changing contrast, changing brightness, changing sharpness, and adding random Gaussian noise.

[0038] In this scheme, the above settings can ensure the training effect as much as possible when the number of base sample images used for training is small.

[0039] Furthermore, the bounding box regression loss in the loss function used to pre-train the improved YOLOv8 model is constructed using the DFL loss and the improved ShapeIoU loss function;

[0040] The expression for the improved ShapeIoU loss function is as follows:

[0041] L ShapeIoU =1-IoU+distance shape +0.5×Ω shape

[0042] Among them, L ShapeIoU The total loss value is represented by IoU, where IoU represents the IoU loss and distance is the distance. shape Ω represents distance loss. shape Indicates shape loss;

[0043] The expression for the IoU loss is:

[0044]

[0045] a represents the predicted bounding box determined by the improved YOLOv8 model. gt This represents a pre-labeled true bounding box, a∩a gt Indicates that a and a gt The area of ​​the intersecting part, a∪a gt Indicates that a and a gt The area of ​​the merged portion;

[0046] The expression for the distance loss is:

[0047]

[0048] (x c ,y c ) represents the center point of a. Indicates that a gt The center point, c is the center point of a. gt The diagonal distance hh between the minimum bounding box and a is determined according to a. gt The weighting coefficients in the vertical direction determined by the size, ww is based on the a... gt The weighting coefficients in the horizontal direction are determined by the dimensions;

[0049] The expression for the shape loss is:

[0050]

[0051] θ is a preset parameter characterizing the degree of attention paid to shape loss, ω w and ω h Based on the first preset relation, the first preset relation is:

[0052]

[0053] w represents the width of a, h represents the height of a, w gt Indicates that a gt width, h gt Indicates that a gt of high.

[0054] In this solution, the problem of size differences among different defect categories of workpieces is effectively solved by constructing a bounding box regression loss, thereby improving the accuracy of defect detection using the improved YOLOv8 model.

[0055] Furthermore, according to the aforementioned a gt The dimensions determine the weighting coefficient hh in the vertical direction, including:

[0056] Based on the a gt width wgt The a gt high h gt The second preset relational formula determines the weighting coefficient hh in the vertical direction;

[0057] The second preset relation is:

[0058]

[0059] Where scale is the scaling factor.

[0060] Furthermore, according to the aforementioned a gt The dimensions determine the weighting coefficient ww in the horizontal direction, including:

[0061] Based on the a gt width w gt The a gt high h gt The third preset relational formula determines the weighting coefficient ww in the horizontal direction;

[0062] The third preset relation is:

[0063]

[0064] Where scale is the scaling factor. Attached Figure Description

[0065] Figure 1 A flowchart of a method for detecting surface defects of highly reflective cylindrical workpieces based on an improved YOLOv8 model provided by the present invention;

[0066] Figure 2 A schematic diagram of the network structure of an improved YOLOv8 model provided by this invention;

[0067] Figure 3 A schematic diagram of the structure of a Bottleneck module provided by the present invention is provided for this invention;

[0068] Figure 4 A schematic diagram of an improved C2f structure provided by the present invention;

[0069] Figure 5 A schematic diagram of the structure of a Fusion module provided by the present invention;

[0070] Figure 6 This is a schematic diagram of the structure where the predicted bounding box intersects with the ground truth bounding box, provided by the present invention.

[0071] Figure 7 This invention provides an image schematic diagram of a polygonal defect appearing on the surface of a shock absorber;

[0072] Figure 8 This is a schematic diagram of the heatmap results of the feature map of the last layer of the Backbone module when applying the traditional YOLOv8 model.

[0073] Figure 9 This is a schematic diagram of the heatmap results of the feature map of the last layer of the Backbone module when applying the improved YOLOv8 model. Detailed Implementation

[0074] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.

[0075] Please refer to Figure 1 , Figure 1 The flowchart of a method for detecting surface defects of highly reflective cylindrical workpieces based on an improved YOLOv8 model provided by the present invention.

[0076] This invention provides an embodiment of a method for detecting surface defects on highly reflective cylindrical workpieces based on an improved YOLOv8 model, comprising:

[0077] S11: Obtain the image of the surface of the workpiece to be inspected;

[0078] S12: Input the image to be detected as input to the pre-trained improved YOLOv8 model in order to determine the location of defects on the surface of the workpiece and the type of defects;

[0079] The improved YOLOv8 model's network structure includes a Backbone module and a head module. The Backbone module contains an improved C2f structure, and the Bottleneck module in the improved C2f structure is constructed based on a preset multi-scale parallel convolution strategy that can extract weak defect features. The head module is constructed using a BIFPN structure, and the Fusion module in the head module used for feature fusion is constructed based on a preset weighted fusion mechanism that can combine multiple feature maps of different resolutions input to itself.

[0080] In this embodiment, considering that the traditional YOLOv8 model, as a deep learning model including convolutional neural networks, has efficient feature extraction capabilities and powerful feature expression capabilities, improvements are made based on the traditional YOLOv8 model to obtain the improved YOLOv8 model in this application, which has been successfully applied to defect detection on the surface of workpieces.

[0081] Specifically, the workpieces referred to here are highly reflective cylindrical workpieces, including but not limited to shock absorbers. Please refer to [link / reference needed]. Figure 2 , Figure 2This document provides a schematic diagram of the network structure of an improved YOLOv8 model. Taking the parameters of the image to be detected as [3*640*640] as an example (where 3 represents the number of channels and 640*640 represents the size of the image to be detected), the Backbone module can be divided into layers P0-P9. Here, the improved C2f structure is mainly applied to layers P6 and P8. The input image to be detected is processed by the Backbone module to obtain four effective feature layers, which are then input into the head module for the next step of network construction. The CBS structure in the Backbone module still follows the processing method in the traditional YOLOv8 model, namely, it includes Conv2D+BN+SiLu (two-dimensional convolutional layer + BN layer + SiLu activation function). Figure 2 The C2f in the text indicates that this part still uses the inherent C2f structure of the traditional YOLOv8 model. For the head module (neck structure), the network of the traditional YOLOv8 head module is replaced with a BIFPN (Bi-directional Feature Pyramid Network) structure. This bi-directional connection can better capture feature representations at different scales and utilizes the improved Fusion module to achieve feature fusion. For a preferred configuration of the head module using the BIFPN structure, please refer to [reference needed]. Figure 2 The improved Fusion module in this application refers to the Fusion module. The final output of the head module is three enhanced features, which are fed into the Determination layer to obtain the prediction result, that is, the location of the defect and the category to which the defect belongs.

[0082] In summary, this application provides a method for detecting surface defects on highly reflective cylindrical workpieces based on an improved YOLOv8 model. The improved YOLOv8 model is specifically optimized for workpiece surface defect detection. The Backbone module incorporates an improved C2f structure, and the Bottleneck module within this structure is constructed using a pre-defined multi-scale parallel convolution strategy. This effectively extracts subtle defect features from the workpiece surface, enhancing robustness to complex environments and diverse defects. The head module employs a BIFPN structure, facilitating better feature capture at different scales. Furthermore, the Fusion module within the head module utilizes a pre-defined weighted fusion mechanism to combine features at different levels, ensuring optimal feature integration and improving the network's ability to process objects of varying sizes and complexities. Therefore, the solution provided in this application improves the accuracy and efficiency of workpiece surface defect detection, eliminates manual inspection costs, and leverages industrial vision technology to empower industrial production, making it suitable for practical applications.

[0083] In a preferred embodiment, the Backbone module includes an inherent C2f structure and at least one improved C2f structure, and the number of input channels of the CBS structure located one layer above the improved C2f structure is greater than a preset channel limit threshold.

[0084] Specifically, while the inherent C2f structure in the Backbone module of the traditional YOLOv8 model can be replaced with an improved C2f structure, practical applications have shown that this replacement is not very meaningful for parts with a small number of channels, and the improvement effect is not significant. Therefore, the Backbone module can be constructed using the above settings. For example, the preset channel limit threshold here can be 256. Please refer to... Figure 2 Then the inherent C2f structure of the P6 and P8 layers of the traditional YOLOv8 model is replaced with an improved C2f structure.

[0085] As a preferred embodiment, the Bottleneck module is constructed according to a preset multi-scale parallel convolution strategy, including:

[0086] Determine g groups of convolution kernels of different sizes, where g is an even number greater than 1;

[0087] Establish corresponding convolutional layers for each convolutional kernel;

[0088] The minimum number of channels is determined by dividing channel by g, where channel is the number of channels in the first image input to the Bottleneck module;

[0089] The channels are grouped according to the minimum number of channels, and the resulting g sub-images with the minimum number of channels are input into g convolutional layers respectively.

[0090] The outputs of each convolutional layer are stacked and merged, and the processed result is fed into a 1*1 convolutional layer. The convolution result of the 1*1 convolutional layer is used as the output of the Bottleneck submodule.

[0091] In this embodiment, on the one hand, considering that the features of the surface defects of the workpiece are small and weak and occupy a low number of pixels in the image, the network needs to have a stronger feature extraction capability. On the other hand, considering the size of the model parameters, we avoid introducing too many parameters. Therefore, the above-mentioned multi-scale grouped parallel convolution strategy was designed to construct the Bottleneck module in the improved C2f structure. It should be noted that the purpose of setting different sizes of convolution kernels here is to capture feature information of different sizes.

[0092] For details, please refer to Figure 3 , Figure 3 This is a schematic diagram of the structure of a Bottleneck module provided by the present invention, showing the forward propagation process. Figure 3 The parameters of the first image are [h*w*channels]. Preferably, g = 4 (in practice, g can also be set to 2, but the effect is not as good as setting it to 4). Different sizes of convolutional kernels are set as 1*1, 3*3, 5*5, and 7*7 (of course, they can also be set to 3*3, 5*5, 7*7, and 9*9; no special limitation is made here). Corresponding convolutional layers are established for different convolutional kernels, such as... Figure 3 As shown, taking a channel of 256 as an example, channel / g = 64, so the minimum number of channels is 64. The channels are grouped according to the minimum number of channels, and the sub-images after the channel grouping are respectively input to the convolutional layer. For example, channels 1 to 64 are sent to a 1*1 convolutional layer for convolution, and channels 65 to 128 are sent to a 3*3 convolutional layer for convolution.

[0093] Subsequently, the outputs of each convolutional layer are stacked and merged. Specifically, the `torch.stack` method is used to stack the outputs of each convolutional layer, and then the `rearrange` function is used to merge the number of channels in the group back together. In this way, after convolution processing and merging, the number of output channels returns to the original number of channels. Finally, the processed result is fed into a 1*1 convolutional layer, and the convolution result of the 1*1 convolutional layer is used as the output of the Bottleneck submodule. Therefore, for the entire Bottleneck module, the number of input channels and the number of output channels remain unchanged, but multi-scale convolution processing is performed internally. Compared with the Bottleneck module with the inherent C2f structure in the traditional YOLOv8 model, the improved C2f structure Bottleneck module in the improved YOLOv8 model inserts a set of convolutional layers with multi-scale convolution capabilities when passing feature maps, enabling the network to effectively absorb and process features of different scales.

[0094] Please refer to Figure 4 , Figure 4 This is a schematic diagram of an improved C2f structure provided by the present invention. For any improved C2f structure, the parameters of the feature map input to the upper-layer CBS structure are (c_in, w, h), and the parameters of the feature map output by the CBS structure are (c_out, w, h). It is divided into two feature maps equally along the channel dimension (i.e., ...). Figure 2The tensors are split into two layers (a and b) and stored in a list y = [a, b]. The parameters of a and b are both (c_out / 2, w, h). Then b is input into the Bottleneck module to get c, which has a size of (c2 / 2, w, h). c is then stored in y. The Bottleneck operation is repeated n times. The final list y contains n+2 tensors. The tensors in list y are concatenated in channels to obtain a tensor of size ((n+2)*c_out / 2, w, h). Finally, the tensor is passed through the CBS structure located below the improved C2f structure. The CBS structure outputs a tensor of size (c_out, w, h).

[0095] As a preferred embodiment, a Fusion module is constructed according to a preset weighted fusion mechanism, including:

[0096] Initialize the predefined variable ans, which is used to store the cumulative result;

[0097] For multiple feature maps of different resolutions input to the Fusion module, determine whether the size of each feature map is the same as the preset target size of the expected output feature map;

[0098] If not, the size of the feature map is matched to the preset target size according to the preset size matching strategy, and the processed result is passed through a preset convolutional layer and then multiplied element-wise with the current ans variable to obtain the enhanced feature.

[0099] Store the enhanced features into the ans variable;

[0100] After confirming that the size of each feature map matches the preset target size, the stored result in the ans variable is determined to be the output of the Fusion module.

[0101] It should be noted that all elements in the ans variable are 1 during initialization; enhanced features can provide more semantic information and finer details. Ultimately, through the above feature fusion mechanism, features at different levels can be combined. The fusion weights are learned during training, ensuring optimal feature integration and improving the network's ability to process objects of different sizes and complexities.

[0102] As a preferred embodiment, matching the size of the feature map to a preset target size according to a preset size matching strategy includes:

[0103] Determine whether the size of the feature map is larger than the preset target size;

[0104] If the size is larger than the preset target size, downsampling is performed according to the average pooling operation to match the size of the feature map larger than the preset target size to the preset target size;

[0105] If the size is smaller than the target size, upsampling is performed using bilinear interpolation to match the size of the feature map smaller than the preset target size to the preset target size.

[0106] For details, please refer to Figure 5 , Figure 5 This is a schematic diagram of the structure of a Fusion module provided by the present invention. Figure 5 The preset convolutional layer is labeled GSConv; the preset target size is labeled target_size; in addition, the size here refers to h*w; the multiple feature maps of different resolutions input to the Fusion module are x1~xn.

[0107] As a preferred embodiment, acquiring an image of the surface of the workpiece to be inspected includes:

[0108] Drive the rolling device to control the movement of the workpiece mounted on the rolling device;

[0109] A linear scan camera captures images of the workpiece during its movement, which are then stitched together to obtain a complete image of the workpiece's surface to be inspected.

[0110] In this embodiment, considering that the workpiece is a highly reflective cylindrical workpiece, such as a shock absorber, which is essentially a cylindrical metal body, the area scan camera cannot completely capture the image of the workpiece surface. Therefore, a rolling device is needed to move the workpiece evenly to capture the surface image. Specifically, the workpiece is placed on the rolling device. When the acquisition command is triggered, the rolling device is driven, causing the workpiece to roll. The line scan camera, through its photosensitive element, can acquire pixel information line by line to obtain the captured image. After stitching the captured images, the curve of the workpiece surface can be converted into a planar image, i.e., the complete image to be detected, thus completing the complete recording of the surface defect features. The size of the image to be detected can be 5120*1280.

[0111] As can be seen, the above method can better capture a complete 360-degree image of the workpiece surface to be inspected, laying the foundation for subsequent defect detection.

[0112] As a preferred embodiment, the improved YOLOv8 model is pre-trained based on a training dataset. The steps for determining the training dataset include:

[0113] Determine the base sample image;

[0114] Label the location and type of defects present in the base sample image;

[0115] Data augmentation operations are performed on the base sample images to use the augmented dataset as the training dataset. Data augmentation operations include one or more combinations of mirroring, horizontal flipping, changing contrast, changing brightness, changing sharpness, and adding random Gaussian noise.

[0116] Specifically, taking a base sample image of 5120*1280 as an example, the original base sample image is cropped by sliding to obtain an image sample of size 640*640. After defining the category to which the defects of the image sample belong, the defect labeling in the above steps is implemented using the LabelImg software. Considering that the number of base sample images used for training may be small, the above data augmentation operation can also be performed to ensure the training effect as much as possible, and finally the training dataset is obtained.

[0117] As a preferred embodiment, the bounding box regression loss in the loss function used to pre-train the improved YOLOv8 model is constructed using the DFL loss and the improved ShapeIoU loss function;

[0118] The improved expression for the ShapeIoU loss function is as follows:

[0119] L ShapeIoU =1-IoU+distance shape +0.5×Ω shape

[0120] Among them, L ShapeIoU The total loss value is represented by IoU, where IoU represents the IoU loss and distance is the distance. shape Ω represents distance loss. shape Indicates shape loss;

[0121] The expression for IoU loss is:

[0122]

[0123] 'a' represents the prediction box determined by the improved YOLOv8 model. gt This represents a pre-labeled true bounding box, a∩a gt Indicate a and a gt The area of ​​the intersecting part, a∪a gt Indicate a and a gt The area of ​​the merged portion;

[0124] The expression for distance loss is:

[0125]

[0126] (x c ,y c () represents the center point of a. Indicates agt The center point, c is a gt The diagonal distance of the minimum bounding box between a and 'a', hh is based on a gt The weighting coefficients in the vertical direction are determined by the size, and ww is based on a. gt The weighting coefficients in the horizontal direction are determined by the dimensions;

[0127] The expression for shape loss is:

[0128]

[0129] θ is a preset parameter characterizing the degree of attention paid to shape loss, ω w and ω h Based on the first preset relation, the first preset relation is:

[0130]

[0131] w represents the width of a, h represents the height of a, w gt Indicates a gt width, h gt Indicates a gt of high.

[0132] In this embodiment, to better address the issue of size differences among different defect categories of workpieces, the improved ShapeIoU loss function is used instead of the CIoU loss function in the traditional YOLOv8 model. The loss function of the improved YOLOv8 model consists of two parts: the first part is the category classification loss (VFL Loss), which uses cross-entropy loss; the second part is the bounding box regression loss, which is constructed using DFL loss and the improved ShapeIoU loss function. The DFL loss calculates the regression loss probabilistically, which has been detailed in the prior art and will not be repeated here. The expression of the improved ShapeIoU loss function has been explained above and will not be repeated here.

[0133] Please refer to Figure 6 , Figure 6 This is a schematic diagram of the structure where the predicted bounding box intersects with the ground truth bounding box, provided by the present invention. The relevant parameters are already shown in [the diagram]. Figure 6 As indicated above. It should also be noted that θ is a preset parameter characterizing the degree of attention paid to shape loss. To avoid reducing the movement of the prediction box due to attention to shape loss, θ can preferably be set to 4.

[0134] As a preferred embodiment, according to a gt The dimensions determine the weighting coefficient hh in the vertical direction, including:

[0135] Based on a gt width w gt agt high h gt The second preset relational formula determines the weighting coefficient hh in the vertical direction;

[0136] The second presupposed relation is:

[0137]

[0138] Where scale is the scaling factor.

[0139] It should be noted that scale is related to the size of the target dataset.

[0140] As a preferred embodiment, according to a gt The dimensions determine the weighting coefficient ww in the horizontal direction, including:

[0141] Based on a gt width w gt a gt high h gt The third preset relational formula determines the weighting coefficient ww in the horizontal direction;

[0142] The third presupposed relation is:

[0143]

[0144] Where scale is the scaling factor.

[0145] As proof of the effectiveness of the solution presented in this application, taking a shock absorber as an example, the improved YOLOv8 model was trained on a dataset of surface defects in shock absorbers. The results show that the improved YOLOv8 model significantly improves the detection accuracy for polygonal or ring-shaped defects on the shock absorber surface. The improved YOLOv8 model achieves an mAP of 89.3%, while the traditional YOLOv8 model only achieves 81.0%. Furthermore, to more intuitively demonstrate the effectiveness of the improved model in defect detection, please refer to... Figure 7 , Figure 8 and Figure 9 , Figure 7 This is a schematic diagram of an image showing a polygonal defect on the surface of a shock absorber, provided by the present invention. Figure 8 For corresponding Figure 7 A schematic diagram illustrating the heatmap results of the feature map of the last layer of the Backbone module when applying the traditional YOLOv8 model. Figure 9 For corresponding Figure 7The diagram shows the heatmap results of the feature map of the last layer of the Backbone module when applying the improved YOLOv8 model. It can be seen that the improved YOLOv8 model has stronger feature extraction capabilities and pays more attention to defect areas, thus verifying that the solution provided in this application can improve detection accuracy.

[0146] While the disclosure is as stated above, its scope of protection is not limited thereto. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of this disclosure, and all such changes and modifications will fall within the protection scope of this invention.

[0147] It should also be noted that in this specification, relational terms such as first, second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not imply any such actual relationship or order between these entities or operations.

Claims

1. A method for detecting surface defects in highly reflective cylindrical workpieces based on an improved YOLOv8 model, characterized in that, include: Acquire the image of the surface of the workpiece to be inspected; The image to be detected is input into a pre-trained improved YOLOv8 model to determine the location of defects on the surface of the workpiece and the type of the defects. The improved YOLOv8 model's network structure includes a Backbone module and a head module. The Backbone module contains an improved C2f structure, and the Bottleneck module in the improved C2f structure is constructed based on a preset multi-scale parallel convolution strategy that can extract weak defect features. The head module is constructed using a BIFPN structure, and the Fusion module in the head module used for feature fusion is constructed based on a preset weighted fusion mechanism that can combine multiple feature maps of different resolutions input to itself. The Backbone module includes an inherent C2f structure and at least one improved C2f structure, and the number of input channels of the CBS structure located one layer above the improved C2f structure is greater than a preset channel limit threshold. The Bottleneck module is constructed according to the preset multi-scale parallel convolution strategy, including: Determine g groups of convolution kernels of different sizes, where g is an even number greater than 1; For each of the aforementioned convolutional kernels, a corresponding convolutional layer is established; The minimum number of channels is determined by dividing the channel by the g, where the channel is the number of channels of the first image input to the Bottleneck module; The channels are grouped according to the minimum number of channels, and the g sub-images with the minimum number of channels are respectively input into the g convolutional layers; The outputs of each convolutional layer are stacked and merged, and the processed result is fed into a 1*1 convolutional layer. The convolution result of the 1*1 convolutional layer is used as the output of the Bottleneck submodule. The Fusion module is constructed according to the preset weighted fusion mechanism, including: Initialize the predefined variable `ans` to store the cumulative result; For multiple feature maps of different resolutions input to the Fusion module, determine whether the size of each feature map is the same as the preset target size of the expected output feature map; If not, the size of the feature map is matched to the preset target size according to the preset size matching strategy, and the processed result is passed through a preset convolutional layer and then multiplied element-wise with the current ans variable to obtain the enhanced feature. Store the enhanced features into the ans variable; After determining that the size of each feature map matches the preset target size, the stored result in the ans variable is determined to be the output of the Fusion module.

2. The method for detecting surface defects of highly reflective cylindrical workpieces based on the improved YOLOv8 model as described in claim 1, characterized in that, Matching the size of the feature map to the preset target size according to a preset size matching strategy includes: Determine whether the size of the feature map is larger than the preset target size; If the size is larger than the preset target size, downsampling is performed according to the average pooling operation to match the size of the feature map larger than the preset target size to the preset target size; If the size is smaller than the target size, upsampling is performed using bilinear interpolation to match the size of the feature map smaller than the preset target size to the preset target size.

3. The method for detecting surface defects of highly reflective cylindrical workpieces based on the improved YOLOv8 model as described in claim 1, characterized in that, Acquire an image of the surface of the workpiece to be inspected, including: Drive the rolling device to control the movement of the workpiece mounted on the rolling device; The workpiece is captured by a line scan camera during its movement, and the captured images are then stitched together to obtain a complete image of the workpiece's surface to be inspected.

4. The method for detecting surface defects of highly reflective cylindrical workpieces based on the improved YOLOv8 model as described in claim 1, characterized in that, The improved YOLOv8 model is pre-trained based on a training dataset, and the steps for determining the training dataset include: Determine the base sample image; The location of defects in the base sample image and the type of the defects are labeled; Data augmentation operations are performed on the base sample images to use the augmented dataset as a training dataset. The data augmentation operations include one or more combinations of mirroring, horizontal flipping, changing contrast, changing brightness, changing sharpness, and adding random Gaussian noise.

5. The method for detecting surface defects of highly reflective cylindrical workpieces based on the improved YOLOv8 model as described in any one of claims 1 to 4, characterized in that, The bounding box regression loss used in the loss function for pre-training the improved YOLOv8 model is constructed using the DFL loss and the improved ShapeIoU loss function; The expression for the improved ShapeIoU loss function is as follows: ; in, Total loss value, Indicates IoU loss. Indicates distance loss. Indicates shape loss; The expression for the IoU loss is: ; This represents the predicted bounding box determined by the improved YOLOv8 model. This represents the pre-labeled true bounding box. Indicates the With the The area of ​​the intersecting part Indicates the With the The area of ​​the merged portion; The expression for the distance loss is: ; Indicates the The center point, Indicates the The center point, For the With the The diagonal distance between the minimum bounding boxes. According to the above The weighting coefficients in the vertical direction are determined by the size. According to the above The weighting coefficients in the horizontal direction are determined by the dimensions; The expression for the shape loss is: ; Preset parameters to characterize the degree of attention paid to shape loss, and Based on the first preset relation, the first preset relation is: ; Indicates the width, Indicates the of high, Indicates the width, Indicates the of high.

6. The method for detecting surface defects of highly reflective cylindrical workpieces based on the improved YOLOv8 model as described in claim 5, characterized in that, According to the above The dimensions determine the weighting coefficients in the vertical direction. ,include: Based on the above width The above of high The second preset relational formula determines the weighting coefficients in the vertical direction. ; The second preset relation is: ; in, This is the scaling factor.

7. The method for detecting surface defects of highly reflective cylindrical workpieces based on the improved YOLOv8 model as described in claim 6, characterized in that, According to the above The dimensions determine the weighting coefficients in the horizontal direction. ,include: Based on the above width The above of high The third preset relational formula determines the weighting coefficients in the horizontal direction. ; The third preset relation is: ; in, This is the scaling factor.

Citation Information

Patent Citations

  • Moving target tracking method based on image

    CN108182388A

  • A residual learning based multi-scale parallel convolutions system for liver tumor detection and the method thereof

    KR1020230056300A