Fabric defect detection method based on improved YOLOv8 model

By improving the YOLOv8 model, adding feature fusion module, attention module and shape loss function, the MSA-YOLOv8 model is formed, which solves the problems of low efficiency and low accuracy of fabric defect detection in the prior art, and achieves efficient and accurate defect detection.

CN120219837APending Publication Date: 2025-06-27TIANJIN POLYTECHNIC UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510297287.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-13
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

The prior art is difficult to detect complex and variable defects in fabrics quickly and accurately, resulting in low detection efficiency and low accuracy.

Method used

The improved YOLOv8 model is adopted, and the SSF feature fusion module, Multi-ScaleAttention module and Shape-IOU loss function are added to form the MSA-YOLOv8 model to improve the detection feature extraction ability and positioning accuracy.

Benefits of technology

It significantly improves the accuracy and efficiency of fabric defect detection, and achieves higher detection accuracy and feature extraction capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120219837A_ABST
    Figure CN120219837A_ABST
Patent Text Reader

Abstract

The invention discloses a fabric defect detection method based on an improved YOLOv8 model. The detection precision is improved by optimizing a YOLOv8 network; firstly, fabric defect images are collected, a data set is constructed, the images are classified and labeled, and a training set, a verification set and a test set are divided; then, a YOLOv8 model is improved, an SSF feature fusion module is introduced, and the feature extraction capability of complex fabric patterns is enhanced; a Multi-Scale Attention module is added, and a space and channel dual attention mechanism is combined, so that the feature expression ability is comprehensively improved; and a Shape-IOU loss function is adopted, and the regression precision is optimized by focusing the shape and the scale of the frame. The improved MSA-YOLOv8 model is trained through the training set and the verification set, finally, the performance of the model is verified through the test set, and a detection result with a defect marking box and confidence is output. Compared with the prior art, the method has the advantages that the fabric defect detection precision and the feature extraction capability are remarkably improved, and the detection accuracy is enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for detecting fabric defects, and particularly to a method for detecting fabric defects based on an improved YOLOv8 model. Background Art

[0002] In the process of fabric production, defect detection is an essential link, which can effectively improve the quality of textiles. According to statistics, due to the existence of surface defects on fabrics, the price of fabrics will drop by 45% - 65%. According to GBT24250 - 2009 and GBT 24117 - 2009 statistics, the types of knitted and woven fabric defects are no less than 75, while the current Tianchi 2018 dataset with the most types of defects only includes 46 categories and fails to fully cover all types of defects. There are a wide variety of fabric defects. If manual inspection is used to detect defects, it has high costs, low efficiency, is easily affected by the subjectivity of workers, and causes certain damage to the fabric. According to the feedback from textile factories, the accuracy of manual inspection is only about 70%. Therefore, how to quickly and accurately detect fabric defects has become an urgent problem to be solved. Thus, the present invention proposes a method for detecting fabric defects based on an improved YOLOv8, which can adapt to the complex and changeable requirements of defect detection and achieve higher detection accuracy and efficiency. Summary of the Invention

[0003] In view of the above defects or deficiencies in the prior art, it is desirable to provide a method for detecting fabric defects based on an improved YOLOv8 model.

[0004] A method for detecting fabric defects based on an improved YOLOv8 model provided by the present invention includes the following steps:

[0005] 1) Collect fabric defect images and establish a fabric defect dataset; label the defect areas on the fabric images according to the fabric defect categories to obtain the labeled defect position information;

[0006] 2) Divide the fabric defect dataset into a training set, a validation set, and a test set according to a ratio of 8:1:1 for subsequent model training and testing;

[0007] 3) Establish an improved YOLOv8 model, add an SSF feature fusion module, a Multi - ScaleAttention attention module, and a Shape - IOU loss function to obtain an improved MSA - YOLOv8 model;

[0008] 4) Input the training set and the validation set into the MSA - YOLOv8 model for training to obtain an optimized model, the best - YOLOv8 model;

[0009] 5) Input the fabric defect images in the test set into the trained best - YOLOv8 model for detection. After the detection is completed, a fabric defect image containing defect bounding boxes and the detected confidence levels is obtained.

[0010] Further, in step 1), the labelImg annotation software is used to annotate the fabric defect dataset, obtaining the true labels of each fabric defect image, as well as the width, height, and center point coordinates of the true annotation bounding boxes.

[0011] Further, the fabric defect categories in step 1) include six categories, namely DaiSha (stagnant yarn), DuanSha (broken yarn), PoDong (hole), MianQiu (cotton ball), TuoSha (slipped yarn), and WuZi (stain).

[0012] Further, the MSA - YOLOv8 model in step 3) sequentially includes four parts: an input end, a Backbone, a Neck, and a Prediction. The specific composition is as follows:

[0013] a) Input end:

[0014] The input end includes Mosaic data augmentation, adaptive anchor box calculation, and adaptive image scaling functions;

[0015] b) Backbone: The Backbone is mainly composed of Conv, C2f_Multi - Scale Attention, and SPPF; among them, the C2f_Multi - Scale Attention module contains a feature processing basic component, a multi - scale feature extraction component, and a feature enhancement and attention component. Through the synergistic effect of the three, the all - round enhancement of features is realized, effectively improving the model's perception ability of fabric texture features;

[0016] c) Neck:

[0017] The Neck part introduces the SSF feature fusion module on the basis of the original feature pyramid network; this module is composed of a serialized feature fusion sub - module and a triple feature encoding sub - module. Among them, the serialized feature fusion sub - module is responsible for realizing the intelligent fusion and recalibration of cross - scale features, and the triple feature encoding sub - module performs the serialized encoding and enhancement of multi - level features, jointly constructing a hierarchical feature extraction and fusion system, effectively improving the model's detection performance for fabric defects;

[0018] d) Prediction:

[0019] Bounding box loss function: In the Prediction part, the traditional IoU loss function is improved to the Shape-IoU loss function, and the positioning accuracy is improved by introducing a shape perception mechanism.

[0020] Furthermore, in step 4), before training with the improved YOLOv8, first pre-train with the fabric defect dataset to determine the best number of iterations that best fits the fabric dataset: place the fabric defect dataset in the YOLOv8 model for training iterations, and finally determine that the best number of iterations is 300; then input the fabric defect images and labels of the training set and validation set into the MSA-YOLOv8 model established in step 3) for training, set the epoch to 300 and the batchsize to 16 according to the pre-training results and computer performance; finally obtain the iteratively optimized best-YOLOv8 model, confusion matrix and label distribution analysis of the dataset.

[0021] Furthermore, in step 5), use the best-YOLOv8 model to detect the fabric defect images in the test set, and finally output the detection results and detection speed of each fabric defect image.

[0022] Compared with the prior art, the beneficial effects of the present invention are:

[0023] The fabric defect detection method based on the improved YOLOv8 model of the present invention adds a Multi-Scale Attention mechanism on the basis of YOLOv8 and integrates it into the C2f module function of the backbone part, enabling the mobile network to enhance the feature expression ability through multi-path parallel processing. It innovatively combines the channel mixing, dynamic modulation and feature reconstruction mechanisms to form a complete feature optimization link, realizing the all-round enhancement of features; it not only obtains the information between channels, but also considers the direction-related position information, which helps the model better locate and identify targets and can be simply inserted into the core structure of the mobile network; compared with the original YOLOv8, it greatly improves the detection efficiency and detection accuracy of fabric defects, bringing the possibility of efficient detection of fabric defects in factories.

[0024] It should be understood that the content described in the Summary of the Invention section is not intended to limit the key or important features of the embodiments of the present invention, nor is it used to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] By reading the detailed description of the non-limiting embodiments with reference to the following drawings, other features, objects and advantages of the present invention will become more apparent:

[0026] Figure 1 This is the flow chart of the network structure of the present invention based on the improved YOLOv8 algorithm;

[0027] Figure 2 This is the schematic diagram of the MSA-YOLOv8 model structure;

[0028] Figure 3 This is the structure diagram of the multi-scale attention (MSA);

[0029] Figure 4 This is the schematic diagram of the overall architecture of the MSA-YOLOv8 model;

[0030] Figure 5 This is the detection effect diagram of the MSA-YOLOv8 model (dai sha);

[0031] Figure 6 This is the detection effect diagram of the MSA-YOLOv8 model (tuo sha). Specific embodiments

[0032] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the related invention, rather than limiting the invention. Additionally, it should be noted that for the sake of description, only the parts related to the invention are shown in the drawings.

[0033] It should be noted that, without conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other. The present invention will be described in detail below with reference to the drawings and embodiments.

[0034] A fabric defect detection method based on an improved YOLOv8 model of the present invention improves the detection accuracy by optimizing the YOLOv8 network; First, fabric defect images are collected and a data set is constructed, the images are classified and labeled, and the training set, validation set, and test set are divided; Subsequently, the YOLOv8 model is improved by introducing an SSF feature fusion module to enhance the feature extraction ability of complex fabric patterns; A Multi-Scale Attention attention module is added to combine the spatial and channel dual attention mechanisms to comprehensively improve the feature expression ability; The Shape-IOU loss function is adopted to optimize the regression accuracy by focusing on the border shape and scale; The improved MSA-YOLOv8 model is trained through the training set and validation set, and finally the performance of the model is verified using the test set, and the detection results with defect annotation boxes and confidence levels are output; Compared with the prior art, the present invention significantly improves the accuracy of fabric defect detection and the feature extraction ability, and enhances the detection accuracy.

[0035] Please refer to Figures 1 to 6, an embodiment of the present invention provides a fabric defect detection method based on an improved YOLOv8 model, including the following steps:

[0036] 1) Collect a certain number of fabric defect images to establish a fabric defect dataset; label the defect areas on the fabric defect images according to the fabric defect categories to obtain the labeled defect position information;

[0037] Use the labelImg annotation software to annotate the fabric defect dataset to obtain the true label of each fabric defect image and the width, height and center point coordinates of the true annotation box; specifically, use the labelimg annotation software to annotate the dataset, and the annotated fabric defect data is in the standard VOC format to obtain a.xml format label file; then convert the.xml file to a.txt file to obtain the true label of each picture and the width, height and center point coordinates of the true annotation box;

[0038] Among them, fabric defects include six categories: DaiSha (stagnant yarn), DuanSha (broken yarn), PoDong (hole), MianQiu (cotton ball), TuoSha (slipped yarn) and WuZi (stain);

[0039] The total number of samples is 2323 target boxes, and the picture size is standardized to 510×512 pixels. The category distribution is as follows:

[0040] TuoSha (slipped yarn): 672 (28.9%); WuZi (stain): 578 (24.9%); DaiSha (stagnant yarn): 422 (18.2%); DuanSha (broken yarn): 337 (14.5%); MianQiu (cotton ball): 202 (8.7%) and PoDong (hole): 112 (4.8%);

[0041] 2) Divide the fabric defect dataset into a training set, a validation set and a test set according to the ratio of 8:1:1 for subsequent model training and testing;

[0042] Divide the fabric defect images and their corresponding labels according to the ratio of 8:1:1;

[0043] 3) Establish an improved YOLOv8 model, add an SSF feature fusion module, a Multi-ScaleAttention attention module and a Shape-IOU loss function to obtain an improved MSA-YOLOv8 model;

[0044] In a preferred embodiment, the MSA-YOLOv8 model sequentially includes four parts: an input end, a Backbone, a Neck and a Prediction. The specific composition is as follows:

[0045] a) Input:

[0046] The input end includes basic functions such as Mosaic data enhancement, adaptive anchor box calculation, and adaptive image scaling. These basic functions together ensure the basic input processing capabilities of the model.

[0047] Mosaic data enhancement solves the problem of uneven object size distribution in the dataset by randomly scaling, cropping, and splicing four images;

[0048] Adaptive anchor box calculation optimizes the setting of anchors through clustering algorithm;

[0049] Adaptive image scaling solves the problem of different input image sizes by minimizing padding.

[0050] b) Backbone: Backbone is mainly composed of Conv, C2f_Multi-Scale Attention and SPPF. Among them, the C2f_Multi-Scale Attention module includes feature processing basic components, multi-scale feature extraction components and feature enhancement and attention components. Through the synergy of the three and the design of dual attention mechanism (spatial and channel), the full-scale enhancement of features is achieved, which effectively improves the model's perception of fabric texture features.

[0051] This module improves the feature expression capability through multi-path parallel processing, innovatively combines channel mixing, dynamic modulation and feature reconstruction mechanisms to form a complete feature optimization link, effectively improving the model's perception of fabric texture features; the SPPF structure realizes the feature map-level fusion of local features and global features;

[0052] In particular, a Multi-Scale Attention module is added to the C2f layer of the Backbone part, so that the input is processed by the Multi-Scale Attention mechanism and then passed to the C2f layer. The feature expression capability is improved through multi-path parallel processing, and the channel mixing, dynamic modulation and feature reconstruction mechanisms are innovatively combined to form a complete feature optimization link. A dual attention mechanism (spatial and channel) is designed to achieve all-round feature enhancement.

[0053] The specific structure of the Multi-ScaleAttention module includes:

[0054] Feature processing basic components:

[0055] Contains ChannelMixer (efficient channel mixer): realizes information interaction and feature reorganization between channels;

[0056] Dynamic Modulator (Dynamic Feature Modulator): Adaptively adjusts the importance of feature channels;

[0057] Feature Reconstruction Module: Reconstructs and optimizes feature representations;

[0058] Multi-scale Feature Extraction Component: Large-Kernel Attention (Large Kernel Attention Mechanism): Expands the receptive field and captures long-range dependencies;

[0059] Feature Enhancement and Attention Component:

[0060] Contains two sub-modules: Feature Enhancement Module: Enhances the feature representation ability; Spatial_Channel Attention (Spatial Channel Attention).

[0061] The specific process is as follows:

[0062] 1. Feature Processing Basic Component:

[0063] The input feature map is denoted as X ∈ R C×H×W , where C is the number of channels, and H and W are the height and width of the feature map.

[0064] a) Channel Mixer (Efficient Channel Mixer):

[0065] F mix (X) = σ(BN(W p ·X) ⊙ DW(X))

[0066] b) Dynamic Modulator (Dynamic Feature Modulator):

[0067] P = AvgPool(X) ∈ R C×1×1 M(X) = W2(σ(W1(P)))Scale, Shift

[0068] = Split(M(X))F dm (X) = F mix (X) · (Scale + 1) + Shift

[0069] c) Feature Reconstruction Module:

[0070] F rec (X) = W4(σ(BN(W3(F dm (X)))))

[0071] 2. Multi-scale Feature Extraction Component

[0072] Large-Kernel Attention:

[0073] F lk (X) = σ(W6(BN(DW7(F rec (X)))))))

[0074] 3. Feature Enhancement and Attention Components

[0075] a) Feature Enhancement Module:

[0076] F fe (X) = W8(GELU(BN(W7(F lk (X)))))

[0077] b) Spatial Attention:

[0078] A s (X) = Sigmoid(Conv7(σ(BN(W9(F fe (X))))))

[0079] where: A s ∈R 1×H×W

[0080] c) Channel Attention:

[0081] P c = AvgPool(F fe (X)) A c (X) = Sigmoid(W 11 (σ(W 10 (P c ))))

[0082] where: A c ∈R C×1×1

[0083] Calculation of the final output feature: Y = F fe (X)·A s (X)·A c (X) + X

[0084] The feature transformation of the whole process can be summarized as:

[0085] Feature processing stage: F1(X) = F rec (F dm (F mix (X)))

[0086] Feature extraction stage: F2(X) = F lk (F da (X))

[0087] Feature enhancement stage: F3(X) = F fe (X)·A s (X)·A c (X)

[0088] Explanation of all variables: σ: activation function, BN: batch normalization, W p : point convolution weight, ⊙: Hadamard product (element-wise product), DW: depthwise separable convolution

[0089] c) Neck:

[0090] The Neck part introduces the SSF feature fusion module on the basis of the original feature pyramid network; this module consists of a serialized feature fusion sub-module (SSFF) and a triple feature encoding sub-module (TFE). Among them, the serialized feature fusion sub-module (SSFF) is responsible for realizing the intelligent fusion and recalibration of cross-scale features, and the triple feature encoding sub-module (TFE) performs the serialized encoding and enhancement of multi-level features, jointly constructing a hierarchical feature extraction and fusion system, effectively improving the detection performance of the model for fabric defects;

[0091] d) Prediction:

[0092] Bounding box loss function: The Prediction part improves the traditional IoU loss function to the Shape-IoU loss function. By introducing a shape perception mechanism, it better considers the shape features of the target bounding box, thereby improving the localization accuracy of the model and making the detection results more accurate.

[0093] 4) Input the training set and validation set into the MSA-YOLOv8 model for training to obtain the optimized model, the best-YOLOv8 model;

[0094] Before training with the improved YOLOv8 model, first pre-train with the fabric defect dataset to determine the best number of iterations that best fits the fabric defect dataset: Put the fabric defect dataset in the YOLOv8 model for training iteration, and finally determine that the best number of iterations is 300; then input the pictures and labels of the training set and validation set into the MSA-YOLOv8 model established in step 3) for training. Set epoch to 300 and batchsize to 16 according to the pre-training results and computer performance; finally, obtain the iteratively optimized best model, that is, the best-YOLOv8 model, confusion matrix, and label distribution analysis of the dataset.

[0095] 5) Input the fabric defect images in the test set into the trained best - YOLOv8 model for detection. After the detection is completed, a fabric defect image containing defect bounding boxes and the detected confidence levels is obtained, and the detection effect and detection speed of each picture are output.

[0096] Finally, we use the designed code to calculate the mAP value, missed detection rate, etc. of the detection results to visualize the detection data.

[0097] Table 1 Comparison of the detection results of two models for four types of defects

[0098]

[0099]

[0100] As can be seen from Table 1, the method of the present invention can achieve the detection of various types of fabric defects. Compared with the YOLOv8 model without the attention mechanism, the mAP has increased by 3.8%, achieving a higher detection accuracy.

[0101] In the description of this specification, terms such as "connection", "installation", "fixation", etc. should be understood in a broad sense. For example, "connection" can be a fixed connection, a detachable connection, or an integral connection; it can be directly connected or indirectly connected through an intermediate medium. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood according to specific circumstances.

[0102] In the description of this specification, the description of terms such as "one embodiment", "some embodiments", etc. means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of this application. In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples.

[0103] The above are only the preferred embodiments of this application and are not used to limit this application. For those skilled in the art, this application can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this application shall be included in the protection scope of this application.

Claims

1. A fabric defect detection method based on an improved YOLOv8 model, characterized in that: The steps include: 1) Collecting fabric defect images and establishing a fabric defect data set; marking defect areas on the fabric images according to fabric defect categories to obtain marked defect location information; 2) dividing the fabric defect dataset into a training set, a validation set, and a test set in a ratio of 8:1:1 for subsequent model training and testing; 3) Establish an improved YOLOv8 model, add the SSF feature fusion module, Multi-ScaleAttention module and Shape-IOU loss function, and obtain the improved MSA-YOLOv8 model; 4) Inputting the training set and the validation set into the MSA-YOLOv8 model for training to obtain an optimized model best-YOLOv8 model; 5) The fabric defect image of the test set is input into the best-YOLOv8 model obtained after training for detection. After the detection is completed, the fabric defect image containing the defect annotation box and the confidence obtained by the detection is obtained.

2. The fabric defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: In the step 1), the fabric defect dataset is labeled using labelImg labeling software to obtain the true label of each fabric defect image and the width, height and center point coordinates of the true labeling box.

3. The fabric defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: The fabric defect categories in the step 1) include six categories, namely, dull yarn, broken yarn, hole, cotton ball, loose yarn and stain.

4. The fabric defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: The MSA-YOLOv8 model in step 3) includes four parts: input end, Backbone, Neck and Prediction, and the specific composition is as follows: a) Input: The input end includes Mosaic data enhancement, adaptive anchor box calculation, and adaptive image scaling functions; b) Backbone: Backbone is mainly composed of Conv, C2f_Multi-ScaleAttention and SPPF. Among them, the C2f_Multi-ScaleAttention module includes feature processing basic components, multi-scale feature extraction components and feature enhancement and attention components. Through the synergy of the three, all-round feature enhancement is achieved, which effectively improves the model's perception of fabric texture features. c) Neck: The Neck part introduces the SSF feature fusion module based on the original feature pyramid network; this module consists of a serialized feature fusion submodule and a triple feature encoding submodule. The serialized feature fusion submodule is responsible for realizing the intelligent fusion and recalibration of cross-scale features, while the triple feature encoding submodule performs serialized encoding and enhancement of multi-level features, jointly constructing a hierarchical feature extraction and fusion system, which effectively improves the model's detection performance for fabric defects. d)Prediction: Boundingbox loss function: The Prediction part improves the traditional IoU loss function into the Shape-IoU loss function, and improves the positioning accuracy by introducing the shape perception mechanism.

5. The fabric defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: In the step 4), before training with the improved YOLOv8, the fabric defect dataset is first pre-trained to determine the best number of iterations that best fits the fabric dataset: the fabric defect dataset is placed in the YOLOv8 model for training iterations, and finally the best number of iterations is determined to be 300; then the fabric defect images and labels of the training set and the validation set are input into the MSA-YOLOv8 model established in step 3) for training, and the epoch is set to 300 and the batchsize is set to 16 according to the pre-training results and computer performance; finally, the iteratively optimized best-YOLOv8 model, confusion matrix, and label distribution analysis of the dataset are obtained.

6. The fabric defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: In the step 5), the fabric defect images in the test set are detected by the best-YOLOv8 model, and finally the detection result and detection speed of each fabric defect image are output.