A textile fabric defect detection method based on an improved YOLOv11 model
By adding a small detection head to the YOLOv11 model and using SAHI model slicing, combined with loss function optimization, the problems of low efficiency and limited accuracy in textile defect detection were solved, achieving efficient and accurate textile defect detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUILIN UNIV OF ELECTRONIC TECH
- Filing Date
- 2024-12-31
- Publication Date
- 2026-06-09
AI Technical Summary
Existing methods for detecting defects in textiles suffer from low efficiency, limited accuracy, and high cost. They are particularly ineffective when dealing with complex textures and minute defects. The traditional YOLOv11 model consumes a lot of computational resources and slows down when processing large images.
A small detection head was added to the YOLOv11 model, and slicing was performed using the SAHI model. The model was optimized using bounding box regression loss, classification loss, and confidence loss. The model performance was evaluated using metrics such as precision, recall, and mean precision. Data augmentation and sample weight optimization were also incorporated.
It improves the accuracy and speed of textile defect detection, enables efficient detection of complex textures and minute defects, reduces computing resource consumption, and adapts to the real-time needs of textile production lines.
Smart Images

Figure CN119904435B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of textile defect detection in computer vision, specifically involving a textile defect detection method based on an improved YOLOv11 model. Background Technology
[0002] In today's fiercely competitive global textile industry, ensuring high-quality textiles is crucial for companies to survive in the market. Various defects may occur during the production process, such as holes, stains, skipped stitches, and color differences. These defects not only affect the appearance of the product but may also impact its performance and lifespan. Therefore, timely and accurate detection of textile defects is essential. Traditional textile defect detection mainly relies on manual visual inspection. However, this method has many problems. Manual inspection is inefficient and cannot meet the needs of large-scale production. With the continuous development of the textile industry and increasingly faster production speeds, manual inspection struggles to keep up. Secondly, the accuracy of manual inspection is greatly affected by factors such as the experience and fatigue level of the inspectors, easily leading to missed or false detections. Furthermore, manual inspection is costly, requiring companies to invest significant human and time resources. With technological advancements, some automated inspection methods are gradually being applied to textile defect detection. However, existing machine vision-based methods still have shortcomings in terms of detection accuracy and speed. Especially for complex textile patterns and textures, as well as minute defects, traditional inspection methods often fail to achieve satisfactory results.
[0003] In recent years, deep learning technology has achieved great success in image recognition and object detection. The YOLOv11 model, as an advanced object detection algorithm, boasts advantages such as high detection speed and high accuracy. However, directly applying it to textile defect detection also faces some challenges. On the one hand, textile defects are diverse in type and shape, and the texture and color variations of textiles are complex, placing higher demands on the model's generalization ability. On the other hand, in actual production, textile images may be large, and the traditional YOLOv11 model may experience high computational resource consumption and reduced detection speed when processing large images. Therefore, it is necessary to improve the YOLOv11 model to adapt to the specific needs of textile defect detection. By adding a small detection head and combining it with the SAHI model, the model's detection accuracy and efficiency for textile defects can be improved, providing more reliable technical support for quality control in the textile industry. Summary of the Invention
[0004] The purpose of this invention is to provide a textile defect detection method based on an improved YOLOv11 model to solve the problems existing in the prior art and improve the accuracy and recognition speed of textile defect detection.
[0005] To achieve the above objectives, the present invention provides the following solution: The present invention provides a textile defect detection method based on an improved YOLOv11 model, comprising the following steps:
[0006] Collect textile image samples, including normal textile images and textile images with defects, perform cropping, scaling, and normalization operations on the images, and label the defects to construct training and testing datasets.
[0007] A small detection head is added to the YOLOv11 model. The small detection head is set behind a smaller scale feature map and has a similar structure to the original detection head, but the parameters are adjusted to target the detection of tiny defects. At the same time, the SAHI model is introduced to slice large-size images.
[0008] The improved YOLOv11 model was trained using the training dataset. The loss function was used and the model parameters were adjusted through the backpropagation algorithm. Hyperparameters were set to prevent overfitting.
[0009] The trained model was tested using a test dataset to obtain model performance metrics, and optimizations were made based on the results.
[0010] The optimized model is applied to an actual textile defect detection production line to perform real-time detection on the collected textile images, output defect information, and mark or classify defective textiles.
[0011] In the data acquisition and preprocessing steps, the images are acquired by installing image acquisition devices on different stages and equipment in the textile production workshop to collect image samples of different types of textiles under different lighting conditions and production speeds.
[0012] Concatenate the feature maps of the third layer C3k2 in the YOLOv11 Backbone with the feature maps of the 17th layer Upsample, then input the concatenated feature maps into a C3k2 network, and finally input them into a Detector to obtain the YOLOv11-head4 model.
[0013] During detection, the image is first fed into the SAHI model, which divides the image into several regions using a sliding window. Each region is predicted separately, while inference is also performed on the entire image. Then, the prediction results of each region are merged with the prediction results of the entire image, and finally, NMS is used for filtering. This is then combined with the YOLOv11-head4 model to obtain an improved YOLOv11 model.
[0014] The loss function consists of bounding box regression loss (BoxLoss), classification loss (CLSLOSS), and confidence loss (DFL).
[0015] The bounding box regression loss is used to optimize the difference between the predicted bounding box and the true bounding box, and the formula is as follows:
[0016]
[0017] in, The size of the time grid, It is the number of bounding boxes predicted for each grid cell. Indicates the first In the grid cell, the th Does each bounding box have the responsibility of predicting the target? These are the coordinates of the center point of the bounding box. These are the width and height of the bounding box. These are weighting coefficients used to balance the losses of different parts.
[0018] Classification loss is typically calculated using cross-entropy loss, which optimizes the model's accuracy in predicting the target class. The formula is as follows:
[0019]
[0020] in, Indicates the grid size. Indicates the first Does each grid cell contain the target? The model predicts the first The target in each grid cell belongs to category The probability of.
[0021] Confidence loss is mainly used to address the class imbalance problem in object detection, and its formula is as follows:
[0022]
[0023] in, It is the sample size. It is the number of categories. It is the first Each sample belongs to The predicted probability, It is a balancing factor used to adjust the weights between positive and negative samples. It is a focusing parameter used to control the degree of attention given to difficult samples.
[0024] Model testing and evaluation consist of precision, recall, mean precision (mAP), and intersection-over-union ratio (IoU).
[0025] Precision is used to evaluate how many samples the model predicts as positive are correct. The formula is as follows:
[0026]
[0027] In this context, TP indicates that the true class of the sample is positive, and the model also identifies it as positive; FP indicates that the true class of the sample is negative, but the model identifies it as positive.
[0028] Recall rate is used to evaluate how many samples whose true positive values are correctly predicted by the model. The formula is as follows:
[0029]
[0030] In this context, TP indicates that the true class of the sample is positive, and the model also identifies it as positive; FN indicates that the true class of the sample is positive, but the model identifies it as negative.
[0031] Average precision is used to evaluate the average precision of a model for multi-class problems. The formula is as follows:
[0032]
[0033] Where m represents the number of categories, P i This represents the accuracy of the i-th category.
[0034] Io is used to evaluate the distance between the output box and the ground truth, and the formula is as follows:
[0035]
[0036] Here, A and B represent two validation boxes for the same object.
[0037] In the model testing and evaluation step, data augmentation is performed on samples of specific defect types in the training dataset based on the test results, and the sample weights are adjusted to optimize model performance. Attached Figure Description
[0038] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0039] Figure 1 This is a schematic diagram of the network structure of a textile defect detection method based on an improved YOLOv11 model according to the present invention.
[0040] Figure 2 This is a schematic diagram of a textile defect detection method based on an improved YOLOv11 model in an embodiment of the present invention. Specific implementation methods
[0041] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0042] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0043] This invention provides a method for detecting defects in textiles based on an improved YOLOv11 model, such as... Figure 2 As shown. Specifically includes:
[0044] Using several collected images of fabrics with defects, the defect categories were manually labeled, and all collected and augmented images were expanded into a fabric defect image dataset. Specifically, defects were labeled for each collected fabric image sequentially, and data augmentation processing was performed simultaneously. After processing, the images were uniformly summarized into a fabric defect image dataset. The specific operation was as follows: First, the minimum bounding rectangle in LabelImg software was used to label the category and location of each defect in each image. The target box must completely enclose each defect, and the target box was labeled as (class, xmin, ymin, xmax, ymax), where class represents the defect category, xmin and ymin represent the x and y coordinates of the top-left vertex of the target box, and xmax and ymax represent the x and y coordinates of the bottom-right vertex of the target box, respectively. After data augmentation processing, labeled and augmented fabric images were obtained, and the label XML file containing the categories was converted into YOLO label TXT format.
[0045] The third layer (C3k2) of the YOLOv11 backbone is concatenated with the feature map from the 17th layer (Upsampled). The concatenated feature map is then input into a C3k2 network, and finally into a Detector. During detection, the image is first fed into the SAHI model, which segments the image into several regions using a sliding window. Each region is predicted separately, while inference is performed on the entire image. The prediction results for each region are then merged with the prediction results for the entire image. Finally, NMS is used for filtering, and this is combined with the YOLOv11-head4 model to obtain an improved YOLOv11 model. During model training, a loss function is used to update the model. This loss function consists of bounding box regression loss, classification loss, and confidence loss.
[0046] The bounding box regression loss is used to optimize the difference between the predicted bounding box and the true bounding box, and the formula is as follows:
[0047]
[0048] This part calculates the center coordinates of the predicted bounding box. Center coordinates of the actual bounding box The mean square error between them. Only when the first... The first grid This portion of the loss is only calculated when a bounding box is responsible for predicting the target. This part calculates the mean square error between the square roots of the predicted bounding box's width and height and the square roots of the actual bounding box's width and height. Similarly, only when the... The first grid This portion of the loss is calculated only when a specific bounding box is responsible for predicting the target. Taking the square root of the width and height ensures that small and large bounding boxes have relatively fair weights in the loss calculation. The purpose of the bounding box loss function is to train the object detection model by minimizing the difference between the predicted and ground truth bounding boxes. It is typically set to a value greater than 1 because in object detection, accurately locating the object is more important than classification. By increasing the weight of the coordinate loss, the model can be made to focus more on the accuracy of the bounding box localization. This loss function is used in grid-based object detection models, and it helps the model learn how to accurately predict the position and size of the object during training.
[0049] Classification loss is typically calculated using cross-entropy loss, which optimizes the model's accuracy in predicting the target class. The formula is as follows:
[0050]
[0051] The purpose of a classification loss function is to measure the accuracy of a model in predicting the category of a target. By minimizing this loss function, the model can learn how to predict the category of a target more accurately. Mean squared error, as a loss function, effectively penalizes the deviation between the predicted probability and the true probability, prompting the model to make more accurate predictions.
[0052] Confidence loss is mainly used to address the class imbalance problem in object detection, and its formula is as follows:
[0053]
[0054] in the formula It is an exponential parameter used to adjust the shape of the loss function; for example, when dealing with imbalanced datasets, it can be adjusted by... Adjustments were made to emphasize the losses in a minority of categories. and It is a component of cross-entropy. The cross-entropy loss function measures the difference between the predicted probability distribution and the true probability distribution. By minimizing the cross-entropy loss, the model can better fit the data and improve classification accuracy.
[0055] During training, the model's loss and performance metrics are calculated on the validation set. Training stops when the model's precision, recall, and mean precision no longer improve over multiple consecutive validation periods. Precision is used to evaluate how many samples the model correctly predicts as positive; the formula is as follows:
[0056]
[0057] Recall rate is used to evaluate how many samples whose true positive values are correctly predicted by the model. The formula is as follows:
[0058]
[0059] Average precision is used to evaluate the average precision of a model for multi-class problems. The formula is as follows:
[0060]
[0061] Among them, the higher the Precision, the more correct defects are predicted in the defect prediction results when the model predicts the corresponding defect category; the higher the Recall, the higher the accuracy of the model in predicting defects and no defects; the higher the mAP, the better the model is applied in textile defect detection.
[0062] In practical applications, the improved YOLOv11 model is deployed in a textile defect detection system, which is connected to image acquisition equipment on the production line. As the textile moves along the production line, the image acquisition equipment captures images of the textile in real time and transmits them to the detection system. The detection system inputs the images into the model for processing, and the model outputs the detection results within a short time. For textiles with detected defects, the system marks them according to preset rules and controls the sorting equipment to sort the defective textiles to the corresponding processing areas, achieving automated textile defect detection and sorting.
[0063] Finally, it should be noted that the above-described embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the scope of the technology disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. All should be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for detecting textile defects based on an improved YOLOv11 model, characterized in that, Includes the following steps: Collect textile image samples, including normal textile images and textile images with defects, perform cropping, scaling, and normalization operations on the images, and label the defects to construct training and testing datasets. A small detection head is added to the YOLOv11 model. The small detection head is set after the small-scale feature map and has a similar structure to the original detection head, but the parameters are adjusted to detect tiny defects. At the same time, the SAHI model is introduced to slice the large-size image. The improved YOLOv11 model was trained using the training dataset. The loss function was used and the model parameters were adjusted through the backpropagation algorithm. Hyperparameters were set to prevent overfitting. The trained model was tested using a test dataset to obtain model performance metrics, and optimizations were made based on the results. The optimized model is applied to an actual textile defect detection production line to perform real-time detection on the collected textile images, output defect information, and mark or classify defective textiles. The method further includes concatenating the feature maps of the third layer C3k2 in the YOLOv11 backbone with the 17th layer Upsample, then inputting the concatenated feature maps into a C3k2 network, and finally into a Detect network to obtain the YOLOv11-head4 model. During detection, the image is first fed into the SAHI model, and the image is divided into several regions by a sliding window. Each region is predicted separately, and inference is also performed on the entire image. Then, the prediction results of each region are merged with the prediction results of the entire image, and finally filtered by NMS. The result is then combined with the YOLOv11-head4 model to obtain the improved YOLOv11 model.
2. The textile defect detection method based on the improved YOLOv11 model according to claim 1, characterized in that, In the data acquisition and preprocessing steps, the images are acquired by installing image acquisition devices on different stages and equipment in the textile production workshop to collect image samples of different types of textiles under different lighting conditions and production speeds.
3. The textile defect detection method based on the improved YOLOv11 model according to claim 1, characterized in that, The loss function consists of bounding box regression loss (BoxLoss), classification loss (CLSLOSS), and confidence loss (DFL); The bounding box regression loss is used to optimize the difference between the predicted bounding box and the true bounding box, and the formula is as follows: in, It is the size of the grid. It is the number of bounding boxes predicted for each grid cell. Indicates the first In the grid cell, the th Does each bounding box have the responsibility of predicting the target? These are the coordinates of the center point of the bounding box. These are the coordinates of the center point of the bounding box predicted by the model. These are the width and height of the bounding box. These are the width and height of the bounding box predicted by the model. These are weighting coefficients used to balance the losses of different parts; The classification loss is calculated using cross-entropy loss, which is used to optimize the accuracy of the model's prediction of the target class. The formula is as follows: in, Indicates the grid size. Indicates the first Does each grid cell contain the target? Indicates the first The target in each grid cell belongs to category The probability, The model predicts the first The target in each grid cell belongs to category The probability of; Confidence loss is used to address the class imbalance problem in object detection, and its formula is as follows: in, It is the sample size. It is the number of categories. It is the first Each sample belongs to The predicted probability, It is a balancing factor used to adjust the weights between positive and negative samples. It is a focusing parameter used to control the degree of attention given to difficult samples.
4. The textile defect detection method based on the improved YOLOv11 model according to claim 1, characterized in that, Model testing and evaluation consist of precision, recall, mean precision (mAP), and intersection-over-union ratio (IoU). Precision is used to evaluate how many samples the model predicts as positive are correct. The formula is as follows: Where TP indicates that the true class of the sample is positive and the model also identifies it as positive, while FP indicates that the true class of the sample is negative, but the model identifies it as positive. Recall rate is used to evaluate how many samples whose true positive values are correctly predicted by the model. The formula is as follows: Where TP indicates that the true class of the sample is positive and the model also identifies it as positive, while FN indicates that the true class of the sample is positive, but the model identifies it as negative. Average precision is used to evaluate the average precision of a model for multi-class problems. The formula is as follows: Where m represents the number of categories, P d This represents the precision of the d-th category; IoU is used to evaluate the distance between the output bounding box and the ground truth. The formula is as follows: Here, A and B represent two validation boxes for the same object.
5. The textile defect detection method based on the improved YOLOv11 model according to claim 1, characterized in that, In the model testing and evaluation step, data augmentation processing is performed on defect type samples in the training dataset based on the test results, and the sample weights are adjusted to optimize model performance.
6. The textile defect detection method based on the improved YOLOv11 model according to claim 1, characterized in that, The trained model parameters are fed into the detection model to build the detection system. During detection, the textiles to be detected are first transmitted to the model through the camera. The transmitted textile information is then preprocessed to make it conform to the model's input. The SAHI model is then used to cut the large image into multiple small samples. The cut small samples are then fed into the improved YOLOv11 model for detection. Finally, the category with the highest accuracy is output as the category of the detected textile.