Textile defect detection method based on improved YOLOv11 model
By adding a small detection head to the YOLOv11 model and combining the SAHI model, textile defect detection is improved, and the problem of insufficient detection accuracy and speed in the prior art is solved, achieving more efficient and accurate textile defect detection.
Patent Information
- Application Number
- CN202411985686.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2044-12-31
AI Technical Summary
The prior art has insufficient detection accuracy and speed in textile defect detection, especially in complex patterns and textures and detection of micro defects, which are difficult to achieve satisfactory results.
Add a small detection head on the YOLOv11 model and slice large-size images with SAHI model to improve the detection accuracy and efficiency of textile defects by the model.
Through the improved YOLOv11 model, the accuracy and recognition speed of textile defect detection are significantly improved, and complex patterns and textures and tiny defects can be detected more accurately, providing more reliable quality control support.
Smart Images

Figure CN119904435A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of textile defect detection in computer vision, and in particular relates to a textile defect detection method based on an improved YOLOv11 model. Background Art
[0002] In today's fiercely competitive global textile industry, ensuring the high quality of textiles is the key for enterprises to gain a foothold in the market. Various types of defects may occur in textiles during the production process, such as holes, stains, jumpers, color differences, etc. These defects not only affect the appearance of the product, but may also affect its performance and service life. Therefore, it is crucial to detect defects in textiles in a timely and accurate manner. Traditional textile defect detection mainly relies on manual visual inspection. However, this method has many problems. Manual inspection is inefficient and difficult to meet the needs of large-scale production. With the continuous development of the textile industry, the production speed is getting faster and faster, and manual inspection is difficult to keep up with the production rhythm. Secondly, the accuracy of manual inspection is greatly affected by factors such as the experience and fatigue of the inspectors, and it is easy to miss and misdetect. In addition, the cost of manual inspection is high, and enterprises need to invest a lot of manpower and time resources. With the advancement of science and technology, some automated detection methods have gradually been applied to the field of textile defect detection. However, the existing machine vision-based methods still have shortcomings in detection accuracy and speed. Especially for some complex textile patterns and textures, as well as tiny defects, traditional detection methods often fail to achieve satisfactory results.
[0003] In recent years, deep learning technology has achieved great success in the field of image recognition and target detection. As an advanced target detection algorithm, the YOLOv11 model has the advantages of fast detection speed and high accuracy. However, when it is directly applied to textile defect detection, it also faces some challenges. On the one hand, textile defects are diverse in type and form, and the texture and color of textiles change in a complex way, which puts higher requirements on the generalization ability of the model. On the other hand, in actual production, the image size of textiles may be large. When processing large-size images, the traditional YOLOv11 model may have problems such as high consumption of computing resources and decreased detection speed. In view of this, it is necessary to improve the YOLOv11 model to meet the special needs of textile defect detection. By adding a small detection head and combining the SAHI model, the detection accuracy and efficiency of the model for textile defects are improved, providing more reliable technical support for quality control in the textile industry. Summary of the invention
[0004] The purpose of the present invention is to provide a textile defect detection method based on an improved YOLOv11 model to solve the problems existing in the above-mentioned prior art and improve the accuracy and recognition speed of textile defect detection.
[0005] To achieve the above object, 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, crop, scale, and normalize the images, annotate the defects, and construct training data sets and test data sets;
[0007] A small detection head is added based on the YOLOv11 model. The small detection head is set after the smaller scale feature map and has a similar structure to the original detection head, but the parameters are adjusted to detect small defects. At the same time, the SAHI model is introduced to slice the large-size image.
[0008] Use the training data set to train the improved YOLOv11 model, use a suitable loss function and adjust the model parameters through the back propagation algorithm, and set appropriate hyperparameters to prevent overfitting;
[0009] Use the test data set to test the trained model, obtain the model performance indicators and make optimization adjustments based on the results;
[0010] The optimized model is applied to the 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 step, the method of acquiring images is to install image acquisition devices on different links and equipment in the textile production workshop to acquire image samples of different types of textiles under different lighting conditions and production speeds.
[0012] Concat the third layer C3k2 in the Backbone of YOLOv11 with the feature map of the 17th layer Upsample, then input the concatenated feature map into a C3k2 network, and finally input it into a Detect to obtain the YOLOv11-head4 model;
[0013] During detection, the image is first passed to the SAHI model, and the image is divided into several regions through a sliding window. Each region is predicted separately, and the whole image is also inferred. Then the prediction results of each region are merged with the prediction results of the whole image, and finally filtered with NMS, and combined with the YOLOv11-head4 model to obtain the 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] Where S is the size of the grid, B is the number of bounding boxes predicted for each grid cell, Indicates whether the jth bounding box in the i-th grid cell is responsible for predicting the target, x, y are the coordinates of the center point of the bounding box, w, h are the width and height of the bounding box, λ coord is the weight coefficient used to balance the losses of different parts.
[0018] Classification loss is usually calculated using cross entropy loss, which is used to optimize the accuracy of the model's prediction of the target category. The formula is as follows:
[0019]
[0020] Where S represents the grid size, Indicates whether the i-th grid cell contains the target, p i (c) represents the probability predicted by the model that the object in the i-th grid cell belongs to category c.
[0021] Confidence loss is mainly used to solve the category imbalance problem in target detection. The formula is as follows:
[0022]
[0023] Among them, N is the number of samples, C is the number of categories, and p ic is the predicted probability that the ith sample belongs to c, α is the balancing factor used to adjust the weights between positive and negative samples, and γ is the focusing parameter used to control the degree of attention paid to difficult samples.
[0024] Model testing and evaluation consists of precision, recall, average precision (mAP) and intersection over union (IoU).
[0025] Precision is used to evaluate how many of the samples predicted by the model as positive are correct. The formula is as follows:
[0026]
[0027] Among them, TP means that the true category of the sample is positive, and the result of model recognition is also positive, and FP means that the true category of the sample is negative, but the model recognizes it as positive.
[0028] The recall rate is used to evaluate how many of the truly positive samples of the model are correctly predicted. The formula is as follows:
[0029]
[0030] Among them, TP means that the true category of the sample is positive, and the result of model recognition is also positive, and FN means that the true category of the sample is positive, but the model recognizes it as negative.
[0031] The average precision is used to evaluate the average precision of the model for multi-category problems. The formula is as follows:
[0032]
[0033] Among them, m represents the number of categories, P i Represents the accuracy of the i-th category.
[0034] Io is used to evaluate the distance between the output box and the ground-truth. The formula is as follows:
[0035]
[0036] Among them, A and B represent two verification boxes for the same object.
[0037] In the model testing and evaluation step, data enhancement processing is performed on samples of specific defect types in the training data set according to the test results, and the sample weights are adjusted to optimize the model performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0039] Figure 1 A schematic diagram of the network structure of a textile defect detection method based on an improved YOLOv11 model of the present invention;
[0040] Figure 2 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 following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0042] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0043] The present invention provides a textile defect detection method based on an improved YOLOv11 model, such as Figure 2 Specifically including:
[0044] Using several fabric images with defects collected, the defect categories are manually annotated, and all the collected images and enhanced images are expanded into a fabric defect image dataset. Specifically, each collected fabric image is annotated with defects in turn, and data enhancement processing is performed at the same time. After processing, they are uniformly summarized as a fabric defect image dataset. The specific operation is as follows: first, the minimum circumscribed rectangular box in the LabelImg software is used to annotate the category and position of each defect in each image. The target box must completely frame each defect. The target box is marked as (class, xmin, ymin, xmax, ymax), class represents the category of the defect, xmin and ymin represent the x-coordinate and y-coordinate of the upper left corner vertex of the target box, respectively, and xmax and ymax represent the x-coordinate and y-coordinate of the lower right corner vertex of the target box. After data enhancement processing, the annotated enhanced fabric image is obtained, and the label xml file that saves the category is converted into the yolo label txt format.
[0045] Concat the third layer C3k2 in the Backbone of YOLOv11 with the feature map of the 17th layer Upsample, then input the concatenated feature map into a C3k2 network, and finally into a Detect. During detection, the image is first passed to the SAHI model, and the image is divided into several regions through a sliding window. Each region is predicted separately, and the entire image is also inferred. Then the prediction results of each region are merged with the prediction results of the entire image, and finally filtered with NMS, and combined with the YOLOv11-head4 model to obtain the improved YOLOv11 model. When training the model, the loss function is used to update the model. The 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 (x i ,y i ) and the center coordinates of the true bounding box This part of the loss is calculated only when the j-th bounding box of the i-th grid is responsible for predicting the object. This part calculates the mean square error between the square root of the width and height of the predicted bounding box and the square root of the width and height of the true bounding box. Again, this part of the loss is only calculated when the jth bounding box of the i-th grid is responsible for predicting the object. The square root of the width and height is taken here to give small and large bounding boxes relatively fair weight 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 bounding box and the true bounding box. λ coord Usually 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 pay more attention to the accuracy of the bounding box positioning. This loss function is used in grid-based object detection models, which helps the model learn how to accurately predict the location and size of the object during training.
[0049] Classification loss is usually calculated using cross entropy loss, which is used to optimize the accuracy of the model's prediction of the target category. The formula is as follows:
[0050]
[0051] The purpose of the classification loss function is to measure the accuracy of the model in predicting the target category. By minimizing this loss function, the model can learn how to more accurately predict the category to which the target belongs. The mean square error as a loss function can effectively penalize 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 solve the category imbalance problem in target detection. The formula is as follows:
[0053]
[0054] In the formula, γ is an exponential parameter used to adjust the shape of the loss function. For example, when dealing with an unbalanced data set, γ can be adjusted to emphasize the loss of the minority class. ic ) and log(1-p ic ) is part of the 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 the accuracy of classification.
[0055] During the training process, the loss value and performance indicators of the model are calculated on the validation set. When the model performance indicators of accuracy, recall rate, and average precision no longer improve over multiple consecutive validation cycles, the training is stopped. Accuracy is used to evaluate how many of the samples predicted as positive by the model are correct. The formula is as follows:
[0056]
[0057] The recall rate is used to evaluate how many of the truly positive samples of the model are correctly predicted. The formula is as follows:
[0058]
[0059] The average precision is used to evaluate the average precision of the model for multi-category problems. The formula is as follows:
[0060]
[0061] Among them, the higher the Precision, the more correct defects are in the predicted defect results when the model predicts the corresponding defect category; the higher the Recall, the higher the accuracy of the model's prediction of defects and no defects; the higher the mAP, the better the application effect of the model in textile defect detection.
[0062] In actual detection applications, the improved YOLOv11 model is deployed in a textile defect detection system, which is connected to the image acquisition device on the production line. When the textile moves on the production line, the image acquisition device collects textile images in real time and transmits them to the detection system. The detection system inputs the image into the model for processing, and the model outputs the detection results in a short time. For textiles with defects detected, the system marks them according to preset rules and controls the sorting equipment to sort the defective textiles to the corresponding processing area, realizing automated textile defect detection and sorting.
[0063] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. They should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A textile defect detection method based on an improved YOLOv11 model, characterized in that: The following steps are involved: Collect textile image samples, including normal textile images and textile images with defects, crop, scale, and normalize the images, annotate the defects, and construct training data sets and test data sets; A small detection head is added based on the YOLOv11 model. The small detection head is set after the smaller scale feature map and has a similar structure to the original detection head, but the parameters are adjusted to detect small defects. At the same time, the SAHI model is introduced to slice the large-size image. Use the training data set to train the improved YOLOv11 model, use a suitable loss function and adjust the model parameters through the back propagation algorithm, and set appropriate hyperparameters to prevent overfitting; Use the test data set to test the trained model, obtain the model performance indicators and make optimization adjustments based on the results; The optimized model is applied to the 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.
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 step, the method of acquiring images is to install image acquisition devices on different links and equipment in the textile production workshop to acquire 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: Concat the third layer C3k2 in the Backbone of YOLOv11 with the feature map of the 17th layer Upsample, then input the concatenated feature map into a C3k2 network, and finally input it into a Detect to obtain the YOLOv11-head4 model; During detection, the image is first passed to the SAHI model, and the image is divided into several regions through a sliding window. Each region is predicted separately, and the whole image is also inferred. Then the prediction results of each region are merged with the prediction results of the whole image, and finally filtered with NMS, and combined with the YOLOv11-head4 model to obtain the improved YOLOv11 model.
4. 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: Where S is the size of the grid, B is the number of bounding boxes predicted for each grid cell, Indicates whether the jth bounding box in the i-th grid cell is responsible for predicting the target, x, y are the coordinates of the center point of the bounding box, w, h are the width and height of the bounding box, λ coord is the weight coefficient used to balance the losses of different parts. Classification loss is usually calculated using cross entropy loss, which is used to optimize the accuracy of the model's prediction of the target category. The formula is as follows: Where S represents the grid size, Indicates whether the i-th grid cell contains the target, p i (c) represents the probability predicted by the model that the object in the i-th grid cell belongs to category c. Confidence loss is mainly used to solve the category imbalance problem in target detection. The formula is as follows: Among them, N is the number of samples, C is the number of categories, and p ic is the predicted probability that the ith sample belongs to c, α is the balancing factor used to adjust the weights between positive and negative samples, and γ is the focusing parameter used to control the degree of attention paid to difficult samples.
5. The textile defect detection method based on the improved YOLOv11 model according to claim 1, characterized in that: The model test and evaluation consists of precision (Precision), recall (Recall), average precision (mAP) and intersection over union (IoU). Precision is used to evaluate how many of the samples predicted by the model as positive are correct. The formula is as follows: Among them, TP means that the true category of the sample is positive, and the result of model recognition is also positive, and FP means that the true category of the sample is negative, but the model recognizes it as positive. The recall rate is used to evaluate how many of the truly positive samples of the model are correctly predicted. The formula is as follows: Among them, TP means that the true category of the sample is positive, and the result of model recognition is also positive, and FN means that the true category of the sample is positive, but the model recognizes it as negative. The average precision is used to evaluate the average precision of the model for multi-category problems. The formula is as follows: Among them, m represents the number of categories, P i Represents the accuracy of the i-th category. Io is used to evaluate the distance between the output box and the ground-truth. The formula is as follows: Among them, A and B represent two verification boxes for the same object.
6. 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 enhancement processing is performed on samples of specific defect types in the training data set according to the test results and the sample weights are adjusted to optimize the model performance.
7. The textile defect detection method based on the improved YOLOv11 model according to claim 1, characterized in that: The trained model parameters are passed into the detection model to build the detection system. During the detection, the detected textile needs to be passed into the model through the camera, and then the input textile information is preprocessed to make it consistent with the model input. Then, the SAHI model is used to cut the large image into multiple small samples, and the cut small samples are passed into the improved YOLOv11 model for detection. Finally, the category with the highest accuracy is output as the category of the detected textile.
Citation Information
Patent Citations
Litchi late autumn shoot detection method based on improved YOLOV5 algorithm and processing terminal
CN115546195A
Green orange detection method based on self-supervised comparative learning and computer device
CN119169472A
Automated defect classification and detection
EP4266246A1
Systems and methods for improved image processing
WO2024211962A1