Lightweight yarn defect detection method based on improved YOLOv8n network

By improving the YOLOv8n network, replacing key modules and adopting lightweight detection heads, the problems of slow detection speed and low accuracy in yarn defect detection are solved, and fast and effective yarn defect detection is achieved, which is suitable for the real-time detection needs of yarn production lines.

CN119672027BActive Publication Date: 2025-05-23SHANGHAI YITAO SUPPLY CHAIN MANAGEMENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510194617.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2024-12-31
Filing Date
2025-02-21
Publication Date
2025-05-23
Estimated Expiration
2045-02-21

AI Technical Summary

Technical Problem

The existing yarn defect detection methods have problems such as slow detection speed, low detection accuracy, and high leakage detection rate, which is difficult to meet the real-time inspection needs of yarn production lines.

Method used

Improve the YOLOv8n network, by replacing the CBS module with the DMAConv module and the C2f module with the C2f-GhostDynamicConv module, and adopting the LSCDH module in the detection head part to reduce the model parameters and calculation amount, while enhancing the model's expression ability and adaptability.

Benefits of technology

It realizes the rapid and effective yarn defect detection, improves detection accuracy and confidence score, and is suitable for mobile devices deployed on yarn production lines to complete real-time inspection tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119672027B_ABST
    Figure CN119672027B_ABST
Patent Text Reader

Abstract

The present invention belongs to the technical field of yarn production detection and image processing, and discloses a lightweight yarn defect detection method based on an improved YOLOv8n network. Yarn pictures are collected on the production line, and the collected pictures are pre-processed and input into the offline trained DGL-YOLO network to output yarn defect detection pictures with abnormal positions and types. The DGL-YOLO network is based on the YOLOv8n network, and the CBS modules in Backbone except the first two and the CBS modules in neck are replaced by DMAConv modules, and the C2f modules in Backbone and Neck are replaced by C2f-GhostDynamicConv modules. The detection method of the present invention has high confidence in the identification of yarn anomalies, and is suitable for deployment on mobile devices of yarn production lines to complete the task of real-time yarn detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of yarn production detection and image processing, and specifically relates to a lightweight yarn defect detection method based on an improved YOLOv8n network. Background Art

[0002] Yarn production is an important part of the textile industry production process. The quality of the yarn obtained will directly affect the quality of silk fabrics. At the same time, because the yarn is thin and soft and difficult to observe, it is difficult to detect abnormal production conditions. Traditional detection methods are mainly divided into manual detection and sensor detection. Among them, manual inspection is difficult and costly, and is limited by the need for relevant workers with professional knowledge and rich experience. At the same time, long-term inspection work is easy to cause fatigue, greatly reducing the workers' attention, increasing the false detection rate, and thus causing losses. Sensor detection has low adaptability to the environment of different industrial sites and is easily interfered by factors such as electromagnetic radiation and environmental humidity, which is not conducive to actual deployment. At the same time, it is difficult to maintain and is not conducive to long-term use.

[0003] In recent years, with the continuous development of machine vision, more and more methods using related technologies for detection have emerged. One of them is a yarn detection system based on machine vision. It detects by adjusting contrast, morphological operations, counting the number of pixels, etc. Compared with traditional methods, it has stronger information capture capabilities, but it is still difficult to identify small target tasks, and its anti-interference ability is weak. It is easily disturbed by factors such as on-site lighting conditions and flying catkins, and has high false detection and missed detection rates. The other method is a target detection algorithm based on deep learning. It obtains yarn production anomaly data sets by pre-labeling, and then uses network training to obtain a detection model. Although it can solve most problems, it still has many shortcomings. For example, the improved Faster RCNN algorithm has high recognition accuracy in the field of small target detection, but its model is large in size and difficult to deploy in actual production. YOLOv8n is a lightweight model of the YOLOv8 series with good detection efficiency. However, when using YOLOv8n for yarn anomaly detection, there are still problems such as slow detection speed, low detection accuracy, and high missed detection rate. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a lightweight yarn defect detection method based on an improved YOLOv8n network, which is used for lightweight deployment and rapid and effective detection of yarn defects.

[0005] In order to solve the above technical problems, the present invention provides a lightweight yarn defect detection method based on an improved YOLOv8n network, comprising collecting yarn images on a production line, preprocessing the collected yarn images in a computer and inputting them into an offline trained DGL-YOLO network, and outputting yarn defect detection images with abnormal positions and types;

[0006] The DGL-YOLO network is based on the YOLOv8n network. The CBS modules except the first two in the Backbone of the YOLOv8n network are replaced by DMAConv modules, and the C2f modules are replaced by C2f-GhostDynamicConv modules; the CBS modules in the feature pyramid network and path aggregation network of the Neck of the YOLOv8n network are replaced by DMAConv modules, and the C2f modules are replaced by C2f-GhostDynamicConv modules; the Head adopts the LSCDH module.

[0007] As an improvement of the lightweight yarn defect detection method based on the improved YOLOv8n network of the present invention:

[0008] The DMAConv module is a convolution module based on DWConv convolution and integrated with the MLCA attention mechanism: after the input features undergo a DWConv convolution, the global and local attention weights are calculated respectively through local pooling and global pooling, and then the two are weighted combined, and the EMA method is used to adaptively determine the size of the one-dimensional convolution kernel k according to the input:

[0009] (3)

[0010] Among them, c is the number of input channels, b and g are hyperparameters for calculating the convolution kernel size.

[0011] As a further improvement of the lightweight yarn defect detection method based on the improved YOLOv8n network of the present invention:

[0012] The C2f-GhostDynamicConv module is: replacing the Bottleneck structure in the C2f module in the YOLOv8n network with an improved GhostModule;

[0013] The improved GhostModule adopts the DynamicConv layer to replace the convolution operation in the Ghost module.

[0014] As a further improvement of the lightweight yarn defect detection method based on the improved YOLOv8n network of the present invention:

[0015] The offline training and testing process of the DGL-YOLO network is:

[0016] Collect yarn production pictures on the production line, pre-process the collected pictures on the computer, and divide the pictures with yarn defects into training sets and test sets after manual annotation;

[0017] The images in the training set are input into the DGL-YOLO network. During the training process, the loss function value is calculated and the model parameters are iteratively optimized through backpropagation. The training ends after the preset number of epochs is reached. Then the test set is input into the DGL-YOLO network, and the intersection-over-union ratio and evaluation index of the candidate prediction box and the annotation box are calculated.

[0018] As a further improvement of the lightweight yarn defect detection method based on the improved YOLOv8n network of the present invention:

[0019] The preprocessing is to perform a binarization operation on the images and then scale each image to a uniform size.

[0020] The beneficial effects of the present invention are mainly reflected in:

[0021] 1. The present invention uses the DMAConv module to replace the CBS module of the original YOLOv8n network, which greatly reduces the number of parameters and calculations of the model. At the same time, the MLCA attention mechanism is introduced to strengthen the connection between the local and the global, avoiding the loss of interactive information between different channels, so that the model can better capture the details in the image;

[0022] 2. The present invention uses the C2f-GhostDynamicConv module to replace the C2f module of the original YOLOv8n network. The Ghost module maintains the expressiveness of the model while achieving lightweight operation, and the DynamicConv dynamic convolution reduces the overall model parameters while enhancing the flexibility and adaptability of the neural network;

[0023] 3. The present invention replaces the three Detect modules of the original Head part with one LSCDH module, thereby reducing the number of parameters and the amount of calculation of the model without affecting the detection accuracy;

[0024] 4. The lightweight yarn defect detection method proposed in the present invention has a high confidence score in identifying yarn anomalies and can be suitable for deployment on mobile devices of yarn production lines to complete the task of real-time yarn detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] The specific implementation modes of the present invention are further described in detail below with reference to the accompanying drawings.

[0026] Figure 1 Schematic diagram of the structure of the basic YOLOv8n network;

[0027] Figure 2 It is a schematic diagram of the structure of the DGL-YOLO network of the present invention;

[0028] Figure 3 Schematic diagram of the DWConv convolution structure;

[0029] Figure 4 is a schematic diagram of the DWAConv module structure of the present invention;

[0030] Figure 5 It is a schematic diagram of the Ghost module structure;

[0031] Figure 6 It is a schematic diagram of the C2f-GhostDynamicConv module structure of the present invention;

[0032] Figure 7 It is a schematic diagram of the LSCDH module structure;

[0033] Figure 8 Example pictures of yarn production anomalies collected;

[0034] Fig. 9 Schematic diagram of the process of online detection by the DGL-YOLO network of the present invention;

[0035] Fig.10 The DGL-YOLO network of the present invention is Figure 8 The following is an example of the detection effect of the yarn production abnormality picture shown. DETAILED DESCRIPTION

[0036] The present invention is further described below in conjunction with specific embodiments, but the protection scope of the present invention is not limited thereto:

[0037] Example 1: A lightweight yarn defect detection method based on an improved YOLOv8n network. The specific process is as follows:

[0038] 1. Improve the YOLOv8n network

[0039] The present invention is based on the improvement of the YOLOv8n network. Firstly, the DWConv lightweight module and the MLCA attention mechanism are used to combine local and global attention to obtain the characteristics of the features, and a DMAConv module with the advantages of both is designed, which ensures that the model can capture the detailed information in the image while being lightweight; secondly, the C2f module in the original network is replaced with C2f-GhostDynamicConv, which realizes lightweight operation without losing the expression ability of the model, and the dynamic convolution introduced at the same time improves the overall adaptability and computational efficiency; finally, a LSCDH detection head module is designed by introducing the idea of ​​shared parameters, which greatly reduces the model parameters without sacrificing the detection accuracy, so that the detection speed of yarn production is improved while the detection accuracy is close. The improved YOLOv8n network structure of the present invention is as follows Figure 2 shown.

[0040] 1.1. Build a basic YOLOv8n network

[0041] The YOLOv8n network is mainly composed of three parts: Backbone, Neck and Head. Its structure is as follows: Figure 1 As shown in the figure. The Backbone part mainly includes the CBS module, C2F module and SPPF module. Among them, the C2F module uses the Split operation and skip layer connection to ensure that YOLOv8n obtains richer gradient flow information based on lightweight design. The Neck part draws on the design ideas of FPN and PAN to transmit deep and shallow feature map information, realize multi-scale feature fusion, and enhance the expression ability of the model. The Head part uses a decoupled head structure to extract the location information and category information of the target respectively, and learns through different network branches, thereby improving the accuracy of the model.

[0042] 1.2. Lightweight convolution module DMAConv

[0043] In order to perform lightweight processing on the YOLOv8n network, the present invention uses the DWConv module to perform convolution operations on the input image. The difference between the DWConv module and the standard convolution is that its convolution kernel is in single-channel mode, and each channel of the input is independently convolved. Therefore, each convolution kernel only needs to process one channel, and the overall computational complexity is greatly reduced compared to the standard convolution. However, this also leads to a decrease in its ability to capture information between different channels, making it difficult to extract more complex features. The DWConv convolution structure is as follows: Figure 3 shown.

[0044] For the input feature map, assume that the number of channels is C in , the number of channels of the output feature map is C out , the size of the convolution kernel is KH ×K W , C out is the bias term of the output channel, then the parameter calculation formula for a feature extraction by standard convolution is:

[0045] (1)

[0046] In DWConv, each input channel is convolved using a convolution kernel independently, and the parameter calculation formula is:

[0047] (2)

[0048] Among them, C out1 and C out2 are the number of bias items of each output channel.

[0049] From the above two formulas, we can see that the number of parameters of standard convolution is proportional to the product of the number of input channels and the number of output channels, and the number of parameters is large, while the number of parameters of DWConv is only related to the number of input channels and the size of the convolution kernel, and the number of parameters is significantly reduced. Therefore, the use of the DWConv module will significantly reduce the complexity of the model.

[0050] In order to solve the problem that the channel information interaction may be weakened due to the above-mentioned DWConv module, the present invention specifically introduces the MLCA attention mechanism to reconstruct it. The structure is as follows Figure 4 As shown in the figure. After a DWConv, local features are generated through local pooling, and the local features are reshaped after global pooling to facilitate weight calculation. For each part of the input, the global and local attention weights are calculated separately, and then the two are weighted combined to ensure that the model can capture the details of the overall image. In order to make the model better adapt to input features of different scales, the EMA method is used to adaptively determine the size of the one-dimensional convolution kernel k according to the input.

[0051] (3)

[0052] Among them, c is the number of input channels of the module, b and g are hyperparameters for calculating the convolution kernel size. Since odd-sized convolution kernels are more suitable for the central symmetry of convolution operations, the convolution kernel sizes output by this formula are all odd numbers, which are represented by odd here.

[0053] The standard convolution (CBS module) of the YOLOv8n network consists of a standard convolution, a batch normalization operation, and a Silu activation function. In the Backbone of the improved YOLOv8n network of the present invention, the first two CBS modules are retained to obtain image features, and the remaining CBS modules are replaced by DMAConv modules.

[0054] 1.3. C2f lightweight module reconstruction

[0055] The C2f module used in the YOLOv8n network is an improved structure based on CSPNet, which optimizes feature extraction and computational efficiency through two convolutions, feature segmentation, and skip connections. In order to further achieve the lightweight of the network, the present invention refers to the idea of ​​GhostNet and proposes an improved GhostModule to replace the Bottleneck part in the C2f module to obtain the C2f-GhostDynamicConv module, which is used to replace the C2f module in the backbone and Neck of the YOLOv8n network.

[0056] Among them, the Ghost module decomposes the standard convolution into two parts. First, a small number of convolution kernels are used to generate the main feature map, and then group convolution is used to supplement the previous feature map by using linear operations to expand the features and increase the number of channels. The formula is as follows:

[0057] (4)

[0058] in, represents the i-th general feature map, Represents a simple feature map obtained by performing the jth linear transformation on a general feature map. Compared with the standard network, the model parameters are greatly reduced, which reduces the computational cost. The Ghost module structure is as follows Figure 5 shown.

[0059] On this basis, the present invention introduces the DynamicConv layer to replace the convolution operation in the Ghost module as an improved GhostModule, with the aim of reducing the overall model parameters while enhancing the flexibility and adaptability of the neural network. The original two-part feature generation process is retained, including the linear operation in the second stage, to keep the computational cost low.

[0060] Each DynamicConv-single (single-layer dynamic convolution) layer can be divided into three parts:

[0061] (1) Use adaptive average pooling (adaptive_avg_pool2d) to reduce the input feature map to a single value, which is then flattened into a one-dimensional vector.

[0062] (2) Pass the input through a fully connected layer (Linear), calculate the weight of each convolution kernel based on the input tensor, and determine the contribution of each kernel to the final output.

[0063] (3) The input feature map passes through the CondConv layer, where it is convolved with the weighted convolution kernel and the result is output.

[0064] After the dynamic convolution layer, the output is batch normalized and activated to generate the final output. The improved GhostModule module dynamically selects the convolution kernel and performs adaptive convolution operations according to the different input features, which enhances the expression ability of the model without increasing the depth and width of the network. The present invention combines it with the C2f module in the original network. The resulting C2f-GhostDynamicConv module not only greatly reduces the model parameters compared with the previous one, but also improves the adaptability and computational efficiency of the overall network. The C2f-GhostDynamicConv module structure is as follows: Figure 6 shown.

[0065] 1.4. Detection head module LSCDH based on shared parameter idea

[0066] There are three Detect modules in the Head part of the original YOLOv8n network, which are used to detect targets of different scales to improve the overall adaptability of the model to different data sets. Each Detect module can be divided into two branches, where the Reg branch is mainly used for bounding box regression, and the Cls branch is mainly used to determine category information. Each branch contains two CBS modules with 3×3 convolutions and a 1×1 Conv module, making the model slightly bloated. Although such a design can improve the performance and recognition accuracy of the model when targeting a data set with a large number of target types, it undoubtedly greatly increases the number of parameters and calculations in the detection head part of the model. Therefore, the detection head of YOLOv8n is optimized to reduce the overall parameters of the model and achieve a lightweight model.

[0067] The data set used in this invention has fewer categories, so it is not necessary to retain too many convolution modules in the head to extract features, which has limited effect on performance improvement. Therefore, this invention adopts the idea of ​​shared parameters to design the detection head LSCDH. Except for the first three 1×1 Conv_GN modules, other parts use shared convolution, which greatly reduces the number of parameters. The module structure is as follows Figure 7 As shown. In order to compensate for the accuracy loss caused by shared convolution, the Conv_GN module in the figure performs GroupNorm normalization after the convolution layer, which improves the positioning and classification performance of the detection head to a certain extent. In addition, the present invention also adds a Scale layer at the end of the LSCDH module to scale the features so that the model can adapt to targets of different scales. Through these improvements, the detection head designed by the present invention reduces the number of parameters and the amount of calculation while maintaining the accuracy of the model as much as possible.

[0068] In combination with steps 1.1-1.4, the present invention uses an improved YOLOv8n network as a yarn defect detection network (hereinafter referred to as DGL-YOLO network), such as Figure 2 As shown in the figure, in the backbone network, all CBS modules except the first two are replaced by DMAConv modules, dynamic convolution is used, and all C2f modules are replaced by C2f-GhostDynamiCconv modules, which not only achieves further lightweight processing but also improves the expressiveness of the network; in the neck, the CBS modules in the feature pyramid network and the path aggregation network are replaced by DMAConv modules, and the C2f modules are replaced by C2f-GhostDynamicConv modules; at the same time, the three Detect modules of the detection head are reconstructed by introducing the idea of ​​shared convolution, and the LSCDH detection head module is designed, which greatly reduces the model parameters.

[0069] 2. Model training

[0070] 2.1、Dataset establishment

[0071] The data set was collected from a yarn production plant in Zhejiang Province. The images in the data set were all taken by an industrial CCD camera. In order to achieve real-time online detection, a patrol robot equipped with a camera was used to patrol between the spinning positions, and a two-dimensional pan-tilt was installed on the top of the robot to shoot the yarn conditions in different production processes, and the image acquisition pixels were set to 640×640. In the computer, abnormal yarn pictures were selected from the collected pictures and annotated with LabelImg to produce a data set. The floating silk was marked as "P", the silk path abnormality was marked as "S", and the misclassified silk was marked as "F". There are a total of 2064 images, of which 1445 are training sets and 619 are test sets. The abnormal yarn production pictures are as follows: Figure 8 shown.

[0072] 2.2 Training and Testing Process

[0073] The labeled images in the training set are input into the DGL-YOLO network for training. First, the feature extraction is performed through the backbone network mainly composed of the DMAConv module, the C2f-GhostDynamicconv module and the SPPF module, and then the multi-scale feature fusion is performed using the Neck (neck) including the C2f-GhostDynamicconv module, and then the LSCDH detection head module generates the abnormal type candidate prediction box. According to the Loss function, the candidate prediction box is continuously optimized, and the training model obtains a weight closer to the label. The loss function of the present invention is consistent with the loss function of the basic Yolov8n network, mainly including positioning loss and classification loss. The positioning loss part mainly adopts the CIoU strategy. After constraining the bounding box by the center distance, aspect ratio, etc., the overlapping area, intersection-over-union ratio and other parameters between the prediction box and the real box are measured, and the corresponding matching degree is obtained. The formula is as follows:

[0074] (5)

[0075] (6)

[0076] in:

[0077] ρ2(b, bg): Euclidean distance between the center point of the predicted box and the true box;

[0078] c: the diagonal length of the minimum enclosing rectangle that encloses the predicted box and the true box;

[0079] α, v: control the consistency of aspect ratio.

[0080] The classification loss is used to measure the accuracy of target classification. The project mainly uses the binary cross entropy (BCE) algorithm to evaluate the difference between the predicted category and the true category. For each detection box, the model predicts the probability that the box belongs to a certain category. The classification loss function optimizes the classification part of the model by calculating the error between the predicted category probability and the true category. The formula is:

[0081] (7)

[0082] in:

[0083] C: the total number of target categories;

[0084] : The label of the true category (1 represents the target category, 0 represents the non-target category);

[0085] : The model predicts the probability of this category.

[0086] The training parameters are preset with a learning rate of 0.01, num_work set to 8, batch_size set to 32, and epoch set to 200. During the training process, the model parameters are iteratively optimized by continuously back-propagating the loss function value, and the training ends when the 200th epoch is completed.

[0087] The testing process is to put the labeled test set images into the trained model, generate candidate prediction boxes, and calculate the intersection of the candidate prediction boxes and the labeled boxes. When the intersection of the intersection of the two is greater than 0.5, it is a positive sample, and when it is less than 0.5, it is a negative sample. The mean average precision (mAP) is used as the evaluation indicator, and mAP0.5=90.1 is obtained, thus obtaining a DGL-YOLO network that can be used online.

[0088] 3. Use the trained DGL-YOLO network online

[0089] Use an industrial CCD camera to collect yarn production pictures with abnormalities, binarize them and scale them up to 640×640 pixels. Then input them into the DGL-YOLO network obtained in step 2, which can be used online. Load the model weight file for inference, generate yarn abnormality prediction candidate boxes, set the confidence threshold, remove low-confidence candidate boxes, and then use non-maximum suppression (NMS) for screening, so as to output yarn production abnormality detection pictures with abnormal locations and types. The overall process is shown in Fig. 9 shown.

[0090] experiment

[0091] 1. The experiment uses the data set of Example 1

[0092] 2. Evaluation indicators

[0093] The experimental evaluation indicators include parameter quantity, floating point calculation amount (FLOPs), precision, recall, average precision (AP), mean average precision (mAP) and frames per second (FPS). The formulas are shown in equations (8~11):

[0094] (8)

[0095] (9)

[0096] (10)

[0097] (11)

[0098] Among them, TP, FP, and FN represent the number of true samples that are correctly identified, the number of samples that are incorrectly identified, and the number of missing correct samples, respectively. represents the average precision of the i-th category.

[0099] 3. Comparative experiment

[0100] In order to verify the detection performance of the DGL-YOLO network proposed in the present invention, experiments were conducted under the same test set to compare the performance with other six mainstream target detection algorithms, and the results are shown in Table 1. By analyzing Table 1, it can be seen that the DGL-YOLO network proposed in the present invention reduces the number of parameters and floating-point calculations of the model while ensuring the detection accuracy, and also improves the average accuracy of the model to a certain extent.

[0101] Table 1 Performance comparison of mainstream target detection algorithms

[0102]

[0103] 4. Ablation experiment

[0104] In order to further verify the effectiveness of the DGL-YOLO model proposed in the present invention, the present invention conducted a series of ablation experiments based on YOLOv8n to evaluate the impact of different modules on network performance and lightweight characteristics. The experimental results are shown in Table 2. The improved algorithm has a more efficient network architecture, significantly reduces model parameters and computational costs, and improves model accuracy to a certain extent. The three modules proposed all help to reduce the number of parameters and computational costs to varying degrees. Among them, the C2f-GhostDynamicConv module achieves the most significant parameter reduction, which is 27.5% less than the basic model. However, this reduction also leads to a 1.5% decrease in the mAP0.5 value. It is worth noting that the introduction of the LSCD module increases the mAP0.5 value in Scenario 4, 6 and 8, with the highest increase reaching 0.7%. In addition, compared with the basic model, the inclusion of this module also achieves the highest accuracy improvement, reaching 1.6%. It can be seen that the improved algorithm in this paper achieves higher detection accuracy and faster detection speed with fewer parameters and computational complexity.

[0105] Table 2 DGL-YOLO ablation experiment results

[0106]

[0107] Scenario 1: YOLOv8n network

[0108] Scenario 2: Based on the YOLOv8n network, in Backbone, all CBS modules except the first two are replaced with DMAConv, and in Neck, the CBS modules in the feature pyramid network and the path aggregation network are replaced with DMAConv modules.

[0109] Scenario 3: Based on the YOLOv8n network, replace all C2f modules in the network with C2f-GhostDynamicConv modules.

[0110] Scenario 4: Based on the YOLOv8n network, in the Head, replace the three Detect modules with one LSCD-Head module.

[0111] Scenario 5: Based on the YOLOv8n network, in Backbone, all CBS modules except the first two are replaced with DMAConv; in Neck, all CBS modules in the feature pyramid network and path aggregation network are replaced with DMAConv modules; and all C2f modules in the network are replaced with C2f-GhostDynamicConv modules.

[0112] Scenario 6: Based on the YOLOv8n network, in Backbone, all CBS modules except the first two are replaced with DMAConv; in Neck, the CBS modules in the feature pyramid network and the path aggregation network are replaced with DMAConv modules; in Head, the three Detect modules are replaced with one LSCD-Head module.

[0113] Scenario 7: Based on the YOLOv8n network, all C2f modules in the network are replaced with C2f-GhostDynamicConv modules; in the Head, the three Detect modules are replaced with one LSCD-Head module.

[0114] Scenario 8: DGL-YOLO network of the present invention.

[0115] Fig.10 This is an example diagram of the detection effect of the DGL-YOLO network of the present invention on yarn defects in the production process. It can be seen that the improved algorithm proposed in the present invention has a very high confidence score in the identification of yarn abnormalities and can complete the task of real-time yarn detection. At the same time, since the DGL-YOLO network parameter volume of the present invention is only 0.95M, it has the characteristics of being lightweight and is suitable for deployment on inspection robots in yarn production lines.

[0116] Finally, it should be noted that the above examples are only some specific embodiments of the present invention. Obviously, the present invention is not limited to the above embodiments, and there are many variations. All variations that can be directly derived or associated with the content disclosed by a person skilled in the art should be considered as the protection scope of the present invention.

Claims

1. A lightweight yarn defect detection method based on an improved YOLOv8n network, characterized in that: The method includes collecting yarn images on the production line, preprocessing the collected yarn images in a computer, and then inputting the images into the offline trained DGL-YOLO network to output yarn defect detection images with abnormal positions and types; The DGL-YOLO network is based on the YOLOv8n network. All CBS modules except the first two in the Backbone of the YOLOv8n network are replaced by DMAConv modules, and all C2f modules are replaced by C2f-GhostDynamicConv modules; the CBS modules in the feature pyramid network and path aggregation network of the YOLOv8n network Neck are replaced by DMAConv modules, and the C2f modules are replaced by C2f-GhostDynamicConv modules; the Head adopts the LSCDH module; the DMAConv module is a convolution module based on DWConv convolution and fused with the MLCA attention mechanism: after the input feature passes through a DWConv convolution, the global and local attention weights are calculated respectively by local pooling and global pooling, and then the two are weighted combined, and the EMA method is used to adaptively determine the size of the one-dimensional convolution kernel k according to the input: (3) Wherein, c is the number of input channels, b and g are hyperparameters for calculating the convolution kernel size; the C2f-GhostDynamicConv module is: replacing the Bottleneck structure in the C2f module in the YOLOv8n network with the improved GhostModule; The improved GhostModule adopts the DynamicConv layer to replace the convolution operation in the Ghost module.

2. The lightweight yarn defect detection method based on the improved YOLOv8n network according to claim 1 is characterized in that: The offline training and testing process of the DGL-YOLO network is as follows: Collect yarn production pictures on the production line, pre-process the collected pictures on the computer, and manually mark the pictures with yarn defects and divide them into training set and test set; The images in the training set are input into the DGL-YOLO network. During the training process, the loss function value is calculated and the model parameters are iteratively optimized through backpropagation. The training ends after the preset number of epochs is reached. Then the test set is input into the DGL-YOLO network to calculate the intersection-union ratio and evaluation index of the candidate prediction box and the annotation box.

3. The lightweight yarn defect detection method based on the improved YOLOv8n network according to claim 2 is characterized in that: The preprocessing is to perform a binarization operation on the images and then scale each image to a uniform size.