Construction method of network structure based on Yolo, defect detection method and system
By optimizing the Yolo network structure, using DC3K2 convolution module and upsampling module, combined with SDConv feature fusion, the problem of unbalanced detection accuracy and efficiency in the existing methods is solved, and efficient identification of small targets and stable detection in complex scenarios is achieved.
Patent Information
- Application Number
- CN202510544317.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-28
- Publication Date
- 2025-08-08
AI Technical Summary
Existing defect detection methods are difficult to balance detection accuracy and efficiency in complex scenarios, especially for the unstable identification of minor defects, and deep learning network models are inefficient or low in accuracy when detecting small targets.
By replacing the attention mechanism module in the backbone network and neck network of Yolo architecture with DC3K2 convolution module, and adding an upsampling module to the neck network, a small object detection head is added to the head network, and combining the SDConv feature fusion module, the network structure is optimized to improve detection accuracy and efficiency.
While reducing network parameters, the accuracy and efficiency of defect detection are improved, especially the detection stability and accuracy of small targets, achieving efficient identification in complex scenarios.
Smart Images

Figure CN120451101A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision recognition technology, and in particular to a Yolo-based network structure construction method, a defect detection method, and a system. Background Art
[0002] Some containers for products, such as plastic bottles, are an important part of the packaging industry. Their product quality directly affects food safety, brand image and consumer experience.
[0003] However, due to current manufacturing demands, plastic bottle manufacturers need to fully automate the sorting of good and bad plastic bottles to reduce manual labor. Furthermore, not all defective plastic bottles need to be screened out as bad. To account for costs, each manufacturer has an acceptable level of defects as a basis for judging good and bad plastic bottles.
[0004] However, in existing defect detection methods, such as image processing methods based on traditional images, it is difficult to distinguish complex defects in scenarios where there is too much interference between defects, and the detection results are also unstable in complex detection scenarios.
[0005] In recent years, among the deep learning methods commonly used in the field of computer vision recognition, the existing deep learning network models generally have good recognition effects on large targets, but they can only detect defects. Some minor defects such as cracks are within the acceptable range for on-site manufacturers. It is not stable to distinguish between good and defective products simply by the confidence level of deep learning.
[0006] At the same time, existing deep learning network models either have high detection efficiency but low detection accuracy, or high detection accuracy but slow detection efficiency.
[0007] Therefore, how to balance the accuracy and efficiency of defect detection has become an urgent problem to be solved. Summary of the Invention
[0008] To solve the above problems, the present invention provides a Yolo-based network structure construction method, a defect detection method and a system, which replace the attention mechanism modules in the backbone network and the neck network of the Yolo architecture with the DC3K2 convolution module, add an upsampling module in the neck network of the Yolo architecture, and add a small target detection head in the head network of the Yolo architecture. It can effectively balance the defect detection accuracy and detection efficiency during the defect detection process.
[0009] In a first aspect, the present invention provides a method for constructing a network structure based on the Yolo framework, the method comprising:
[0010] The attention mechanism modules in the backbone network and neck network of the Yolo architecture are replaced with the DC3K2 convolution module; the DC3K2 convolution module is improved based on the DSConv module;
[0011] Add an upsampling module to the neck network of the Yolo architecture and connect the upsampling module to the DC3K2 convolution module in the backbone network that is not connected to the Concat module in the neck network;
[0012] A small target detection head is added to the head network of the Yolo architecture. The small target detection head is connected to the upsampling module through the DC3K2 convolution module in the neck network.
[0013] Optionally, the DC3K2 convolution module includes a DSConv module, a residual link module, a separation module, and a DS3 module group, the DS3 module group includes multiple DS3 modules connected in series, and the DS3 module is a lightweight feature extraction module designed based on the DSConv module;
[0014] The separation module is used to perform channel separation on the image output by the DSConv module to obtain multiple single-channel sub-images and transmit the multiple single-channel sub-images to the residual link module and the DS3 module group respectively;
[0015] The DS3 module group is used to perform convolution processing on multiple single-channel sub-images through the DS3 module;
[0016] The residual link module is used to perform residual linking on multiple single-channel sub-images and the image after convolution of each DS3 module to obtain a link feature map.
[0017] Optionally, the DS3 module is used to perform feature extraction on the received tensor through the DSConv module to obtain a first feature tensor, transmit the first feature tensor to a model composed of at least one BottleNeck module for feature extraction to obtain a second feature tensor, concatenate the first feature tensor and the second feature tensor and perform feature extraction again through the DSConv module to obtain and output a link feature map.
[0018] Optionally, the method further includes replacing the convolutional feature fusion module in the backbone network and the neck network of the Yolo architecture with the SDConv feature fusion module;
[0019] The SDConv feature fusion module is used to perform feature fusion on the input feature map after a global context module and residual link, and then perform feature fusion on the same feature map through lightweight convolution of different scales.
[0020] Optionally, the SDConv feature fusion module processes the fused feature map including:
[0021] Perform a global average pooling operation on the feature map to be fused to obtain the first pooled feature map;
[0022] Use a 1*1 convolution block to adjust the number of channels of the first pooled feature map to obtain the first channel adjusted feature map;
[0023] Splicing the first channel adjusted feature map and the feature map to be fused to obtain a first spliced feature map;
[0024] The first spliced feature map is transmitted to the DSConv module for feature extraction to obtain an extracted feature map. The first spliced feature map is subjected to a global average pooling operation to obtain a second pooled feature map. A 1*1 convolution block is used to adjust the number of channels of the second pooled feature map to obtain a second channel-adjusted feature map.
[0025] Perform dot product fusion of coefficient S(x) and coefficient 1-S(x) on the extracted feature map and the second channel adjusted feature map, and concatenate the two dot product fused feature maps to obtain a dot product fused feature map;
[0026] Perform a global average pooling operation on the dot product fusion feature map to obtain the third pooling feature map, and use a 1*1 convolution block to adjust the number of channels of the third pooling feature map to obtain the third channel adjusted feature map;
[0027] Concatenate the third channel adjusted feature map with the dot product fusion feature map.
[0028] Optionally, the head network of the Yolo architecture includes multiple original detection heads;
[0029] Multiple original detection heads are connected to different DC3K2 convolution modules in the neck network of the Yolo architecture;
[0030] The DC3K2 convolution module connected to the small target detection head is located upstream of the DC3K2 convolution modules connected to multiple original detection heads and downstream of the upsampling module.
[0031] Optionally, the step of splicing the upsampling module with the DC3K2 convolution module in the backbone network that is not connected to the Concat module in the neck network includes:
[0032] The upsampling module is spliced with the shallow DC3K2 convolution module in the backbone network. The shallow DC3K2 convolution module is the DC3K2 convolution module located upstream of the DC3K2 convolution module in the backbone network that is connected to the Concat module in the neck network.
[0033] In a second aspect, the present invention provides a defect detection method, the method comprising:
[0034] Inputting the image to be inspected into the network structure constructed by the method of the first aspect to locate defects in the image to be inspected and obtain a positioning result;
[0035] Determine whether the object in the image to be inspected is a good product based on the positioning result.
[0036] Optionally, the step of determining whether the object to be detected in the image to be detected is a good product according to the positioning result includes:
[0037] According to the positioning results, the image to be inspected is segmented to obtain a segmented image containing the defective area;
[0038] Traverse the segmented image in the specified direction to obtain multiple sets of pixel values;
[0039] Calculate the average value of each group of pixel values;
[0040] The maximum average value is used as the threshold to perform binarization on the segmented image to obtain a binary image;
[0041] Based on the binary image, the segmented image is filled with red to determine the outline of the defect area in the segmented image;
[0042] Calculating a first average grayscale value of the segmented image within the contour and a second average grayscale value of the segmented image outside the contour;
[0043] Whether the object to be inspected in the image to be inspected is a good product is determined according to the absolute value of the difference between the first average grayscale value and the second average grayscale value.
[0044] In a third aspect, the present invention provides a defect detection system, comprising:
[0045] An input module is configured to input the image to be inspected into the network structure constructed by the method of the first aspect to locate defects in the image to be inspected and obtain a positioning result;
[0046] The judgment module is configured to judge whether the object to be detected in the image to be detected is a good product according to the positioning result.
[0047] The embodiments of the present invention provide a Yolo-based network structure construction method, a defect detection method, and a system. By replacing the attention mechanism modules in the backbone network and the neck network of the Yolo framework with the DC3K2 convolution module, an upsampling module is added to the neck network of the Yolo framework, and a small target detection head is added to the head network of the Yolo framework, while reducing the parameters in the network structure, multi-scale feature splicing is added, and effective features are learned to the maximum extent while ensuring the reduction of the amount of learning parameters. That is, the present invention provides improvements to the accuracy and parameters of the Yolo framework, respectively, and increases the speed through lightweight convolution blocks while ensuring the improvement of accuracy, thereby effectively balancing the accuracy and efficiency of defect detection in the defect detection process. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the conventional technology, the following briefly introduces the drawings required for use in the embodiments or the conventional technology descriptions. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0049] Figure 1 A schematic diagram of a network structure according to an embodiment of the present application;
[0050] Figure 2 This is a schematic structural diagram of the Yolov11 model according to one embodiment of the present application;
[0051] Figure 3 Schematic comparison diagram of the convolution kernels of the VQK component and the KDS component according to an embodiment of the present application;
[0052] Figure 4 Schematic convolution structure diagram of the DSConv module according to one embodiment of the present application;
[0053] Figure 5 This is a schematic convolution structure diagram of the DC3K2 convolution module according to an embodiment of the present application;
[0054] Figure 6 This is a schematic convolution structure diagram of the DS3 module according to an embodiment of the present application;
[0055] Figure 7 This is a schematic convolution structure diagram of the SDConv feature fusion module according to an embodiment of the present application;
[0056] Figure 8 A segmented image of an image to be detected according to an embodiment of the present application;
[0057] Figure 9A binary image of the image to be detected according to an embodiment of the present application;
[0058] Figure 10 This is a schematic structural diagram of a segmented image after red filling according to an embodiment of the present application. DETAILED DESCRIPTION
[0059] To facilitate understanding of the present application, the present application will be described more fully below with reference to the accompanying drawings. The accompanying drawings provide embodiments of the present application. However, the present application may be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided to make the disclosure of the present application more thorough and comprehensive.
[0060] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application pertains. The terms used herein in the specification of this application are for the purpose of describing specific embodiments only and are not intended to limit this application.
[0061] It should be noted that when an element is referred to as being "connected to" another element, it can be directly on the other element or there can be an intervening element. When an element is referred to as being "connected to" another element, it can be directly connected to the other element or there can be an intervening element. In contrast, when an element is referred to as being "directly on" another element, there are no intervening elements.
[0062] When used herein, the singular forms "a", "an", and "the" may also include the plural forms, unless the context clearly indicates otherwise. It should also be understood that the terms "include / comprise" or "have" and the like specify the presence of stated features, integers, steps, operations, components, parts, or combinations thereof, but do not preclude the possibility of the presence or addition of one or more other features, integers, steps, operations, components, parts, or combinations thereof.
[0063] In a first aspect, the present invention provides a method for constructing a network structure based on Yolo (You Only Look Once Weighted Transformers). Figure 1 and Figure 2 The method includes steps S101 to S103, wherein steps S101 to S103 are executed in no particular order.
[0064] Step S101: Replace the attention mechanism modules in the backbone network and the neck network of the Yolo architecture with the DC3K2 (Depthwise Separable Convolution-cross stage partial with kernel size 2) convolution module; the DC3K2 convolution module is improved based on the DSConv (DistributionShifting Convolution) module, which is a quantized activated switchable stride convolution module.
[0065] It is understandable that the Yolo framework can be any Yolov model, such as the Yolov11 model or the Yolov8 model.
[0066] Among them, in the Yolov11 model, the convolution modules in its backbone network and neck network are C3K2 (crossstage partial with kernel size 2, strided convolution with convolution kernel size of 2) modules; in the Yolov8 model, the convolution modules in its backbone network and neck network are C2f (Faster Implementation of Communicating Sequential Processes Bottleneck with 2convolutions, fast execution of communication sequential process neck through 2 convolutions) modules.
[0067] Preferably, the Yolo framework is the Yolov11 model, combined with Figure 2 .Depend on Figure 2 As can be seen, the Yolov11 network has only three detection heads, all of which perform category and location prediction on the deep network. This results in significant loss of information about small objects during the convolution process in the backbone network. Furthermore, the use of traditional convolution kernels of fixed size and shape for feature extraction results in limited flexibility when extracting features.
[0068] The DSConv module in this invention decomposes the traditional convolution kernel into two components, namely the variable quantized kernel (VQK) component and the kernel distribution shifter (KDS) component. The two components share a floating point value for each block of size B, and the size of each filter is Figure 3The DSConv module achieves lower memory usage and higher speed by storing only integer values in the VQK component, while maintaining the same output as the original convolution by applying kernel-based and channel-based distribution shifts. The VQK component and KDS component modules in the DSConv module are constructed as follows: Figure 4 .
[0069] Variable quantization kernel component: This tensor holds only variable-length integer values and has the same size (cho, chi, k, k) as the original convolution tensor. The parameter values are set to be quantized from the original floating-point model and cannot be changed once set. This is the quantization component of DSConv. The full name of cho is channel out, and its Chinese name is output channel; the full name of chi is channel input, and its Chinese name is input channel.
[0070] Distribution Shift Component: The purpose of this component is to shift the distribution of the VQK component to try to mimic the distribution of the original convolution kernel. This is achieved by transforming the two domains using two tensors. The first tensor is the kernel distribution shift component, which changes the distribution of each (1, BLK, 1, 1), where BLK stands for Block. Given the original single-precision tensor size of (128, 128, 3, 3), the bit size hyperparameter is set to 2 bits and the block size is set to 64. The size of the VQK component that holds the 2-bit integer is (128, 128, 3, 3). After quantization, the VQK component is converted from single precision to integer. The size of the kernel shifter (KDS) that holds the FP32 number is 2*(128, 2, 3, 3), and the size of the channel shifter that holds the FP32 number is 2*128. In this embodiment, compared to the Yolov model, the convolution kernel of the convolution module of the network structure is reduced to 7% of its original size.
[0071] The purpose of the distribution shift component is to shift the VQK values so that the output matches the values of the original weight tensor. At the same time, the tensor is scaled by the kernel distribution shift (KDS), represented by ξ. A good initial value plays a big role in optimization because if the network structure is placed near the optimal value, only fine-tuning is required to achieve maximum accuracy. The method for calculating the initial value of the tensor is to minimize the KL divergence, which attempts to find the minimum information loss between the original weight distribution and the kernel distribution shift. The method for calculating the minimum loss is shown in formula (1).
[0072]
[0073] Among them, T j Represents the softmax value of the feature map after the shift, I j represents the softmax value of the original feature map, Indicates that the input of any slice is 1 channel, the output is BLK, and the size of the slice is 1x1.
[0074] After calculating the minimum loss, the weights are continuously updated using the gradient descent algorithm until the loss converges, thus obtaining the value of each parameter in the tensor ξ. This value is used as the offset for the DSConv convolution, thereby achieving the goal of reducing the number of channels and improving the speed.
[0075] In a further optional embodiment of this embodiment, in combination with Figure 5 The DC3K2 convolution module includes the DSConv module, the residual link (Concat) module, the separation (Split) module and the DS3 module group. The DS3 module group includes multiple DS3 modules connected in series. The DS3 module is a lightweight feature extraction module designed based on the DSConv module.
[0076] Specific, combined Figure 6 The DS3 module is used to perform feature extraction on the received tensor through the DSConv module to obtain a first feature tensor, transmit the first feature tensor to a model composed of at least one BottleNeck module for feature extraction to obtain a second feature tensor, concatenate the first feature tensor and the second feature tensor and perform feature extraction again through the DSConv module to obtain and output a link feature map.
[0077] Among them, the tensor received by the DS3 module is BCHW data, and the link feature map is also BCHW data different from the tensor received by the DS3 module.
[0078] Furthermore, this embodiment improves the C3K2 module in the Yolov11 model by connecting a series of DS3 modules in series for feature extraction. The DS3 module is a lightweight feature extraction module designed based on DSConv. In order to extract low-parameter features from the input part, the SDC (Switchable DSConvConvolution, switchable depth separable convolution) multi-scale lightweight fusion module is used to perform high-frequency feature fusion to compensate for the feature information lost by the small number of convolution kernel parameters in the DS3 module. Based on the original C3K2 module, the original ordinary Conv convolution module in the Yolov11 model is replaced with a DC3K2 module. The DSConv module undergoes channel separation operation, and each branch is residually linked with the DS3 module to obtain the output link feature map.
[0079] DC3K2 module structure see Figure 5 , the implementation principle of the formula is shown in formula (2).
[0080] Yout = DSConv + (X + DSConv (DSConv (X, W1), W2)) Formula (2)
[0081] Among them, X+DSConv(DSConv(X, W1), W2) represents Figure 6 The output of the right half branch after feature extraction by N BottleNeck modules is concatenated with the left branch. N is a positive integer. BottleNeck modules are standard modules in the Yolo architecture and are not limited to this in this embodiment. The DC3K2 module achieves effective feature extraction by residually linking the shallow DSConv convolution results with the deep convolution results after the deep convolution.
[0082] The separation module performs channel separation on the image output by the DSConv module, generating multiple single-channel sub-images. These sub-images are then passed to the residual link module and the DS3 module group. The DS3 module group performs convolution on the sub-images via the DS3 module. The residual link module performs residual convolution on the sub-images and the image after convolution by each DS3 module, generating a concatenated feature map.
[0083] Step S102: add an upsampling module to the neck network of the Yolo architecture, and splice the upsampling module with the DC3K2 convolution module in the backbone network that is not connected to the Concat module in the neck network.
[0084] In a further optional embodiment of this embodiment, the step of splicing the upsampling module with the DC3K2 convolution module in the backbone network that is not connected to the Concat module in the neck network includes:
[0085] The newly added upsampling module is spliced with the shallow DC3K2 convolution module in the backbone network. The shallow DC3K2 convolution module is the DC3K2 convolution module located upstream of the DC3K2 convolution module in the backbone network that is connected to the Concat module in the neck network.
[0086] Step S103: Add a small target detection head to the head network of the Yolo architecture. The small target detection head is connected to the upsampling module through the DC3K2 convolution module in the neck network.
[0087] This embodiment improves the Yolov11 model by introducing a feature extraction module into the shallow backbone network and adding a shallow feature detection head. At the same time, the traditional convolution module is replaced with a lightweight, multi-branch feature splicing SDC module, and the C3K2 module in the original network is improved to perform feature extraction and regression prediction.
[0088] In a further optional embodiment of this embodiment, in combination with Figure 1 ,The head network of the Yolo architecture includes multiple original detection heads;,the multiple original detection heads are respectively connected to different DC3K2,convolution modules in the neck network of the Yolo architecture;
[0089] The DC3K2 convolution module connected to the small target detection head is located upstream of the DC3K2 convolution modules connected to multiple original detection heads, and downstream of the newly added upsampling module.
[0090] It should be noted that the upsampling module is because the image input into the network structure is extracted through the convolutional neural network (CNN), and the output size tends to become smaller. At this time, the image needs to be restored to its original size for further calculation, thereby realizing the operation of mapping the image from small resolution to large resolution.
[0091] The Concat module concatenates two or more tensors along a certain dimension to generate a larger tensor. This can be used to increase the number of channels or feature dimensions in deep learning models to better capture the relationship between different features in subsequent layers.
[0092] The detection head uses depthwise separable convolution to reduce the number of parameters. The classification detection head in the decoupling head adds two depthwise separable convolutions. The role of depthwise separable convolution can greatly reduce the number of parameters of the model, making the network lighter, thereby predicting the category and position of the object.
[0093] In a further optional embodiment of this embodiment, the method further includes: replacing the convolutional feature fusion module in the backbone network and the neck network of the Yolo architecture with an SDConv feature fusion module.
[0094] The SDConv feature fusion module is used to perform feature fusion on the input feature map after a global context module and residual link, and then perform feature fusion on the same feature map through lightweight convolution of different scales.
[0095] It should be noted that the SDConv feature fusion module is a lightweight convolution module proposed in the present invention. Unlike the traditional convolution module, the SDConv feature fusion module performs feature fusion on the same feature map through a global context module and residual link, and sacrifices parameter quantization based on the DSConv module. Therefore, in the SDConv feature fusion module, convolution kernels with different expansion rates are filtered and then dot products are performed on each other, and then feature superposition is performed. After these operations, the module passes through a global context feature extraction model and outputs features after dimensionality reduction. The principle of the SDConv feature fusion module is shown in Figure 7and formula (3).
[0096] SDC=S(x)*DSConv(x,w,1)+(1-S(x))*DSConv(x,w+Δw) Formula (3)
[0097] Among them, x represents the input, w represents the weight, and S(x) represents the switching function.
[0098] The SDC feature fusion module ensures that the missing weights are compensated by feature fusion using the inverse residual principle. Where w + Δw represents the missing weight, where w represents the weight of the prediction level model, Δw = w i -w i-1 , Δw is initialized to zero, which makes the selection of scale during network training more flexible and effective without changing the pre-trained model.
[0099] In a further optional embodiment of this embodiment, in combination with Figure 7 , the SDConv feature fusion module processes the fused feature map including:
[0100] Perform a global average pooling operation on the feature map to be fused to obtain the first pooled feature map;
[0101] Use a 1*1 convolution block to adjust the number of channels of the first pooled feature map to obtain the first channel adjusted feature map;
[0102] Splicing the first channel adjusted feature map and the feature map to be fused to obtain a first spliced feature map;
[0103] The first spliced feature map is transmitted to the DSConv module for feature extraction to obtain an extracted feature map. The first spliced feature map is subjected to a global average pooling operation to obtain a second pooled feature map. A 1*1 convolution block is used to adjust the number of channels of the second pooled feature map to obtain a second channel-adjusted feature map.
[0104] Perform dot product fusion of coefficient S(x) and coefficient 1-S(x) on the extracted feature map and the second channel adjusted feature map, and concatenate the two dot product fused feature maps to obtain a dot product fused feature map;
[0105] Perform a global average pooling operation on the dot product fusion feature map to obtain the third pooling feature map, and use a 1*1 convolution block to adjust the number of channels of the third pooling feature map to obtain the third channel adjusted feature map;
[0106] Concatenate the third channel adjusted feature map with the dot product fusion feature map.
[0107] The network structure based on the Yolov11 model provided in this embodiment adds an Upsample upsampling module to the neck network to double the size of the feature map. The DC3K2 module of the second layer and the Upsample upsampling module of the 17th layer are then concat-operated to increase the number of channels in the feature map. Finally, through feature extraction from the DC3K2 convolution module, the parameters of the SDConv feature fusion module are effectively reduced by one-third while the number of channels remains unchanged. The extracted features are then residually spliced, and a small target detection head is added to the DC3K2 convolution module of the 19th layer to perform small target positioning and category prediction. Assuming a 640*640 image is input, the four detection heads predict shapes of 128*160*160, 64*80*80, 128*40*40, and 256*20*20, respectively, achieving multi-scale target prediction. While the robustness of large target detection accuracy remains basically unchanged, the stability and accuracy of small target detection are effectively improved.
[0108] The proposed SDC convolution module and improved DC3K2 convolution module reduce parameters while increasing multi-scale feature concatenation, ensuring that the maximum number of effective features is learned while reducing the number of learning parameters. This method improves both accuracy and parameters, ensuring improved accuracy while also increasing speed through lightweight convolution blocks.
[0109] In a second aspect, another embodiment of the present invention provides a Yolo-based network structure, which is constructed using the method in the first aspect.
[0110] The network structure uses images of 1280*1280 input size to train the network structure.
[0111] In a third aspect, the present invention provides a defect detection method, which includes steps S201 to S202.
[0112] Step S201: inputting the image to be inspected into the network structure of the second aspect to locate defects in the image to be inspected and obtain a positioning result.
[0113] Step S202: judging whether the object to be detected in the image to be detected is a good product according to the positioning result.
[0114] In this embodiment, the method is a method for detecting stripe defects on the surface of plastic bottles.
[0115] In a further optional embodiment of this embodiment, the step of determining whether the object to be detected in the image to be detected is a good product according to the positioning result includes steps S2021 to S2027.
[0116] Step S2021: Segment the image to be inspected based on the positioning result to obtain a segmented image containing defective areas. Figure 8 .
[0117] Step S2022: traverse the segmented image in the specified direction to obtain multiple groups of pixel values.
[0118] The specified direction can be any direction on the surface of the plastic bottle. In this embodiment, the direction of the stripe defect is the vertical direction, and the specified direction is also the vertical direction.
[0119] Step S2023: Calculate the average value of each group of pixel values.
[0120] Step S2024: Use the maximum average value as the threshold to perform binarization on the segmented image to obtain a binary image. Figure 9 .
[0121] Step S2025: Based on the binary image, the segmented image is filled with red to determine the outline of the defect area in the segmented image. Figure 10 .
[0122] Step S2026: Calculate a first average grayscale value of the segmented image within the contour and a second average grayscale value of the segmented image outside the contour.
[0123] Step S2027: judging whether the object to be inspected in the image to be inspected is a good product according to the absolute value of the difference between the first average grayscale value and the second average grayscale value.
[0124] In this embodiment, the step of judging whether the item to be inspected in the image to be inspected is a good product based on the absolute value of the difference between the first average grayscale value and the second average grayscale value includes: calculating the absolute value of the difference between the first average grayscale value and the second average grayscale value; comparing the absolute value with a limit value, if the absolute value exceeds the limit value, the item to be inspected is a defective product, otherwise the item to be inspected is a good product.
[0125] The range of the delimiting value is 15 to 17. In this embodiment, the delimiting value is 16, which can effectively distinguish good products from defective products.
[0126] This embodiment provides an improved deep learning combined with traditional image processing method to extract strip defects in plastic bottles with high robustness, thereby distinguishing good from defective products. First, all convolution modules of YOLOv11 are replaced with lightweight SDConv modules, and then a shallow network detection head is added. After locating the strip defects, the contour of the strip defects is analyzed by cleverly obtaining the boundary value. The average grayscale difference inside and outside the contour of the strip defect is used as the basis for distinguishing good from defective products. This effectively solves the problem that plastic bottle manufacturers cannot accurately control the difference between good and defective products within their acceptable defect range.
[0127] In a fourth aspect, the present invention provides a defect detection system, the system comprising:
[0128] An input module is configured to input the image to be inspected into the network structure of the second aspect to locate defects in the image to be inspected and obtain a positioning result;
[0129] The judgment module is configured to judge whether the object to be detected in the image to be detected is a good product according to the positioning result.
[0130] In a further optional embodiment of this embodiment, the judgment module includes:
[0131] The segmentation submodule is configured to segment the image to be detected according to the positioning results to obtain a segmented image containing defective areas. Figure 8 .
[0132] The traversal submodule is configured to traverse the segmented image in a specified direction to obtain multiple sets of pixel values.
[0133] The specified direction can be any direction on the surface of the plastic bottle. In this embodiment, the direction of the stripe defect is the vertical direction, and the specified direction is also the vertical direction.
[0134] The first calculation submodule is configured to calculate an average value of each group of pixel values.
[0135] The binarization submodule is configured to use the maximum average value as the threshold to perform binarization on the segmented image to obtain a binary image. Figure 9 .
[0136] The red filling submodule is configured to perform red filling on the segmented image based on the binary image, determine the contour of the defect area in the segmented image, and combine Figure 10 .
[0137] The second calculation submodule is configured to calculate a first average grayscale value of the segmented image within the contour and a second average grayscale value of the segmented image outside the contour.
[0138] The judgment submodule is configured to judge whether the object to be tested in the image to be tested is a good product according to the absolute value of the difference between the first average gray value and the second average gray value.
[0139] Furthermore, the judgment submodule includes:
[0140] a calculating unit configured to calculate an absolute value of a difference between the first average grayscale value and the second average grayscale value;
[0141] The comparison unit is configured to compare the absolute value with a limit value. If the absolute value exceeds the limit value, the item to be inspected is a defective product; otherwise, the item to be inspected is a good product.
[0142] Throughout this specification, references to terms such as "some embodiments," "other embodiments," and "desired embodiments" indicate that a particular feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the present application. The schematic descriptions of these terms throughout this specification do not necessarily refer to the same embodiment or example.
[0143] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0144] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be determined by the appended claims.
Claims
1. A method for constructing a network structure based on Yolo, characterized in that: The method comprises: The attention mechanism modules in the backbone network and neck network of the Yolo architecture are replaced with DC3K2 convolution modules; the DC3K2 convolution modules are improved based on the DSConv modules; Add an upsampling module to the neck network of the Yolo architecture, and splice the upsampling module with the DC3K2 convolution module in the backbone network that is not connected to the Concat module in the neck network; A small target detection head is added to the head network of the Yolo architecture, and the small target detection head is connected to the upsampling module through the DC3K2 convolution module in the neck network.
2. The method according to claim 1, characterized in that The DC3K2 convolution module includes a DSConv module, a residual link module, a separation module and a DS3 module group, wherein the DS3 module group includes multiple DS3 modules connected in series, and the DS3 module is a lightweight feature extraction module designed based on the DSConv module; The separation module is used to perform a channel separation operation on the image output by the DSConv module to obtain multiple single-channel sub-images and transmit the multiple single-channel sub-images to the residual link module and the DS3 module group respectively; The DS3 module group is used to perform convolution processing on the multiple single-channel sub-images through the DS3 modules; The residual link module is used to perform residual linking on the multiple single-channel sub-images and the image after convolution of each DS3 module to obtain a link feature map.
3. The method according to claim 2, characterized in that The DS3 module is used to perform feature extraction on the received tensor through the DSConv module to obtain a first feature tensor, transmit the first feature tensor to a model composed of at least one BottleNeck module for feature extraction to obtain a second feature tensor, splice the first feature tensor and the second feature tensor and then perform feature extraction again through the DSConv module to obtain and output the link feature graph.
4. The method according to claim 1, wherein The method further comprises: The convolutional feature fusion modules in the backbone network and the neck network of the Yolo architecture are replaced with the SDConv feature fusion module; The SDConv feature fusion module is used to perform feature fusion on the input feature map to be fused after performing a global context module and residual link, and then perform feature fusion on the same feature map through lightweight convolution of different scales.
5. The method according to claim 4, characterized in that The SDConv feature fusion module processes the feature map to be fused including: Perform a global average pooling operation on the feature map to be fused to obtain a first pooled feature map; Use a 1*1 convolution block to adjust the number of channels of the first pooling feature map to obtain a first channel adjusted feature map; Splicing the first channel adjusted feature map with the feature map to be fused to obtain a first spliced feature map; The first spliced feature map is transmitted to the DSConv module for feature extraction to obtain an extracted feature map, the first spliced feature map is subjected to a global average pooling operation to obtain a second pooled feature map, and the number of channels of the second pooled feature map is adjusted using a 1*1 convolution block to obtain a second channel-adjusted feature map; Performing dot product fusion of coefficient S(x) and dot product fusion of coefficient 1-S(x) on the extracted feature map and the second channel adjusted feature map, and splicing the two dot product fused feature maps to obtain a dot product fused feature map; Performing a global average pooling operation on the dot product fusion feature map to obtain a third pooling feature map, and adjusting the number of channels of the third pooling feature map using a 1*1 convolution block to obtain a third channel adjusted feature map; The third channel adjustment feature map is concatenated with the dot product fusion feature map.
6. The method according to claim 1, characterized in that The head network of the Yolo architecture includes multiple original detection heads; The plurality of original detection heads are respectively connected to different DC3K2 convolution modules in the neck network of the Yolo architecture; The DC3K2 convolution module to which the small target detection head is connected is located upstream of the DC3K2 convolution modules to which the multiple original detection heads are connected, and is located downstream of the upsampling module.
7. The method according to claim 1, characterized in that The step of splicing the upsampling module with the DC3K2 convolution module in the backbone network that is not connected to the Concat module in the neck network comprises: The upsampling module is spliced with a shallow DC3K2 convolution module in the backbone network, where the shallow DC3K2 convolution module is a DC3K2 convolution module located upstream of the DC3K2 convolution module in the backbone network that is connected to the Concat module in the neck network.
8. A defect detection method, characterized in that: The method comprises: Inputting the image to be inspected into the network structure constructed by the method according to any one of claims 1 to 7 to locate the defects in the image to be inspected and obtain a positioning result; It is determined whether the object to be detected in the image to be detected is a good product according to the positioning result.
9. The method according to claim 8, characterized in that The step of judging whether the object to be detected in the image to be detected is a good product according to the positioning result includes: Segmenting the image to be inspected according to the positioning result to obtain a segmented image containing a defective area; Traversing the segmented image in a specified direction to obtain multiple sets of pixel values; Calculate the average value of each group of pixel values; Using the largest average value as a threshold, performing binarization processing on the segmented image to obtain a binarized image; Performing red filling on the segmented image according to the binary image to determine the outline of the defect area in the segmented image; Calculating a first average grayscale value of the segmented image within the contour and a second average grayscale value of the segmented image outside the contour; Whether the object to be inspected in the image to be inspected is a good product is determined according to the absolute value of the difference between the first average grayscale value and the second average grayscale value.
10. A defect detection system, characterized in that: The system comprises: an input module configured to input an image to be inspected into the network structure constructed by the method according to any one of claims 1 to 7, so as to locate defects in the image to be inspected and obtain a positioning result; The judgment module is configured to judge whether the object to be detected in the image to be detected is a good product according to the positioning result.
Citation Information
Cited By
Wind power blade defect detection method and equipment based on improved YOLO11n
CN121526959A
Wind power blade defect detection method and device based on improved YOLO11n
CN121526959B