A fabric defect detection method based on HCS-YOLOV5

By improving the HCS-YOLOV5 network model and enhancing its feature extraction and fusion capabilities, the problems of low efficiency and insufficient accuracy in traditional fabric defect detection have been solved, achieving efficient and accurate fabric defect detection.

CN115908382BActive Publication Date: 2026-02-10DONGHUA UNIV +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211641483.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-20
Publication Date
2026-02-10
Estimated Expiration
2042-12-20

AI Technical Summary

Technical Problem

Traditional fabric defect detection methods rely on manual visual inspection, which is costly, inefficient, and lacks robustness, making it difficult to meet actual production needs. Furthermore, the defect detection accuracy is low and the false negative rate is high.

Method used

A fabric defect detection method based on HCS-YOLOV5 is adopted. The feature extraction capability is enhanced by improving the ConvNeXtBlock and HASP modules of the backbone network, the SimAM attention mechanism module is introduced to enhance feature fusion, and the loss function is improved to improve the model convergence speed and detection accuracy.

Benefits of technology

It achieves high precision in fabric defect detection, with an average accuracy of 96.1%, significantly improving the detection capability for small-sized defects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115908382B_ABST
    Figure CN115908382B_ABST
Patent Text Reader

Abstract

The application discloses a kind of based on HCS-YOLOV5's fabric defect detection method, step 1, the resolution of 640×640 size of defective warp fabric image is collected;Step 2, using the defective warp fabric image obtained in step 1, using LabelImg carries out the labeling of defect area, establishes warp fabric defect data set, obtains training set, verification set, test set;Step 3, establish HCS-YOLOV5 network model;Step 4, using the HCS-YOLOV5 network model of step 3 establishment carries out training to data set;Step 5, input a fabric picture to be detected, using the HCS-YOLOV5 network model of step 4 training good carries out detection to the fabric picture to be detected, and outputs detection result;Step 6, using the test set of step 2 carries out evaluation to model.The application solves the problem of poor warp fabric defect detection effect in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of fabric defect detection technology, and particularly relates to a method for detecting defects in warp-knitted fabrics based on HCS-YOLOV5. Background Technology

[0002] The textile industry is a vital sector for people's livelihood in my country, playing a significant role in the country's economic and social development. Quality inspection of textiles is a crucial link in the textile industry chain, and defect detection is a critical stage within this process. However, the complexity of fabric textures and the diversity of defects increase the difficulty of fabric defect detection. Traditional fabric defect detection relies on manual visual inspection, which is costly, inefficient, and lacks robustness, failing to meet the demands of actual production. Numerous domestic and international scholars have conducted research on fabric surface defect detection. Traditional methods require the subjective design of characteristic parameters, resulting in significant labor and time consumption. Furthermore, they struggle to separate defects from the texture, leading to low detection accuracy and a high rate of missed detections. Summary of the Invention

[0003] The purpose of this invention is to provide a fabric defect detection method based on HCS-YOLOV5, which solves the problem of poor detection effect on warp-knitted fabric defects in the prior art.

[0004] The technical solution adopted in this invention is as follows.

[0005] A fabric defect detection method based on HCS-YOLOV5 includes the following steps:

[0006] Step 1: Acquire images of the defective warp-knitted fabric with a resolution of 640×640.

[0007] Step 2: Using the defective warp-knitted fabric images obtained in Step 1, label the defective areas using LabelImg to establish a warp-knitted fabric defect dataset, and obtain the training set, validation set, and test set.

[0008] Step 3: Establish the HCS-YOLOV5 network model;

[0009] Step 4: Train the dataset using the HCS-YOLOV5 network model established in Step 3;

[0010] Step 5: Input a fabric image to be detected, use the HCS-YOLOV5 network model trained in Step 4 to detect the fabric image, and output the detection results.

[0011] Step 6: Evaluate the model using the test set obtained in Step 2.

[0012] The beneficial effects of this invention are as follows.

[0013] This invention discloses a fabric defect detection method based on HCS-YOLOV5. First, the ConvNeXtBlock module is used to improve the CSP module in the backbone extraction network, enhancing the feature extraction capability of the backbone network while increasing the semantic information of each pixel. A HASP module is introduced into the backbone extraction network to enhance the receptive field and capture of global feature details, reducing the loss of detailed information during feature extraction. Second, an S-PANet network structure is proposed, incorporating a SimAM attention mechanism module to enhance the model's focus on defect regions in warp-knitted fabrics during feature fusion, improving the detection accuracy of small-sized defects. Finally, the loss function is improved to accelerate model convergence. The final average detection accuracy reaches 96.1%. Attached Figure Description

[0014] Figure 1 This is a flowchart of a fabric defect detection method based on HCS-YOLOV5 according to the present invention;

[0015] Figure 2 This is an algorithm flowchart of a fabric defect detection method based on HCS-YOLOV5 according to the present invention;

[0016] Figure 3 This is a schematic diagram of the HASP module structure in a fabric defect detection method based on HCS-YOLOV5 according to the present invention.

[0017] Figure 4 This is a schematic diagram of the CNB module structure in a fabric defect detection method based on HCS-YOLOV5 according to the present invention.

[0018] Figure 5 This is an image of the fabric to be detected in Example 1 of the fabric defect detection method based on HCS-YOLOV5 of the present invention;

[0019] Figure 6 This is a diagram showing the detection results of Example 1 in the fabric defect detection method based on HCS-YOLOV5 of the present invention;

[0020] Figure 7 This is a bar chart showing the defect detection accuracy of a warp-knitted fabric dataset in a fabric defect detection method based on HCS-YOLOV5 according to the present invention. Detailed Implementation

[0021] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.

[0022] This invention provides a fabric defect detection method based on HCS-YOLOV5, such as... Figures 1-4 This includes the following steps:

[0023] Step 1: Acquire images of the defective warp-knitted fabric with a resolution of 640×640.

[0024] Step 2: Using the defective warp-knitted fabric images obtained in Step 1, label the defective areas using LabelImg to establish a warp-knitted fabric defect dataset, and obtain the training set, validation set, and test set.

[0025] Step 3: Establish the HCS-YOLOV5 network model;

[0026] Step 4: Train the dataset using the HCS-YOLOV5 network model established in Step 3;

[0027] Step 5: Input a fabric image to be detected, use the HCS-YOLOV5 network model trained in Step 4 to detect the fabric image, and output the detection results.

[0028] Step 6: Evaluate the model using the test set obtained in Step 2.

[0029] Example 1,

[0030] Perform step 1 to acquire an image of the defective warp-knitted fabric with a resolution of 640×640;

[0031] Step 1 is implemented as follows: Collect defective warp-knitted fabric images with a resolution of 640×640. Specifically, use an industrial camera fixed on a well-lit production line to acquire fabric images and adjust the image size to 640×640. The images include three types of defects: broken yarn, broken needle, and missed needle. The dataset contains 4000 images, all uniformly named in the format ######.png.

[0032] Perform step 2, using the defective warp-knitted fabric image obtained in step 1, use LabelImg to annotate the defective areas, establish a warp-knitted fabric defect dataset, and obtain the training set, validation set, and test set;

[0033] Step 2 is implemented as follows: Use the LabelImg annotation tool to mark the defect information of the defective warp-knitted fabric image obtained in Step 1. The marking content mainly includes the input defect sample, the coordinate information of manually selecting the defect with the upper left corner of the image as the reference, as well as the image size and storage path information. The ######.xml format file generated by the marking information corresponds to the ######.jpg format file. Divide the training set into 3200 training samples, the validation set into 400 validation samples, and the test set into 400 test samples according to the ratio of 8:1:1.

[0034] Step 3 is executed to establish the HCS-YOLOv5 network model; the specific implementation process is as follows:

[0035] Step 31: Establish the HCDarkNet feature extraction network. The HCDarkNet feature extraction network is based on the original CSPDarkNet, with the addition of a hybrid atrous space pyramid (HASP) module and a ConvNeXtBlock (CNB) module. This enhances the feature extraction network's ability to extract multi-scale feature information while also improving its semantic information representation capabilities. The HCDarkNet feature extraction network first downsamples the input feature map by 4 times, and then passes it through the HASP module. Its output feature map can extract multi-scale feature information, enhancing the receptive field and capturing global feature details, and reducing the loss of detail information during feature extraction. Then, it passes through 4 downsampling layers, each downsampling the feature map by 2 times. At the same time, each downsampling layer is followed by a CNB module. Each pixel of its output feature map can realize the detection of defect targets, and at the same time, it increases the semantic information of each pixel. The 4 downsampling layers are stacked consecutively to obtain feature maps that are downsampled by 8 times, 16 times, and 32 times from the input image, respectively, which are used as input information for the feature fusion network.

[0036] Step 32: The path aggregation network aims to enhance the positional information of the top-level feature map through bottom-up paths. Since shallow feature information is significantly lost after multiple layers of propagation, the SimAM attention mechanism is used to enhance the weights of defective regions, reduce feature information loss, improve the fusion accuracy of strong semantic information at the top level and strong positional information at the bottom level, and enhance the detection capability of the warp-knitted fabric defect detection algorithm for targets of different sizes.

[0037] Step 33: The main part of the Head consists of three Detect detectors, which are the process of detecting objects using grid-based anchors on feature maps of three scales: 80x80, 40x40, and 20x20. The feature maps are divided into grids according to their size, and three anchors with different aspect ratios are pre-set for each grid on each feature map to predict and regress the target. Prediction is performed on each grid on the feature map, and the predicted information is compared with the true information. The closer the predicted information is to the true information, the smaller the loss function value. The loss function is implemented as follows:

[0038] 1) Confidence loss function and classification loss function:

[0039] The confidence loss function alleviates the problem of severe imbalance between positive and negative samples and difficulty in detecting small target defects in single-stage target detection. It balances the relationship between the number of difficult and easy samples and positive and negative samples (i.e. whether the fabric has defects) and the number of large and small fabric defects (the ratio of the fabric defect size to the input image size). Formula (1) is the confidence loss function.

[0040] L obj = -ylogp-(1-y)log(1-p) (5)

[0041] In the above formula, y is the true value of the target contained in the anchor, and p is its corresponding predicted value;

[0042] 2) Classification loss function:

[0043] The classification loss function increases the weight of small target defects, balances the proportion of large and small targets in the loss function, and makes it pay more attention to the detection of small targets. Formula (2) is the classification loss function.

[0044] L cls = -ylogp-(1-y)log(1-p) (6)

[0045] In the above formula, y is the true value of the target contained in the anchor, and p is its corresponding predicted value;

[0046] 3) Rectangular box loss function:

[0047] The rectangular box loss function is based on the penalty term of CIOU. The aspect ratio influence factor is separated to calculate the length and width of the target box and the anchor box respectively. The loss function includes three parts: overlap loss, center distance loss, and width and height loss. The first two parts continue the method in CIOU, but the width and height loss directly minimizes the difference between the width and height of the target box and the anchor box, which makes the convergence speed faster and improves the regression ability of small target bounding boxes. Formula (3) is the bounding box regression loss function.

[0048]

[0049] In the above formula, B p and B gt These are the coordinates of the center points of the predicted bounding box and the ground truth bounding box, respectively, ρ 2 (B p B gt w represents the Euclidean distance between the center points of the predicted bounding box and the ground truth bounding box. c h c w represents the width and height of the smallest outer rectangle of the predicted bounding box and the target bounding box, respectively. p w gt h represents the width and height of the predicted bounding box, respectively. p h gt These are the width and height of the actual bounding box, respectively;

[0050] 4) Total loss function:

[0051] The total loss function is the sum of the confidence loss function, the classification loss function, and the bounding box loss function. Formula (4) is the total loss function.

[0052] L=αL cls +δL obj +μL eiou (8)

[0053] In the above formula, α, δ, and μ are used to balance the proportions of confidence loss, category loss, and bounding box regression loss in the total loss.

[0054] Perform step 4, and train the dataset using the HCS-YOLOV5 network model established in step 3;

[0055] Step 4 is implemented as follows: The HCS-YOLOV5 network is trained using the training set divided in Step 2. The training set images and the labeled files of the training set are used as the training path. The training is iterated for 300 epochs. The training input is 640x640, and the number of input images is 8 each time. A weight file will be output after training.

[0056] Perform step 5, and input an image of the fabric to be detected, such as... Figure 5 As shown, the HCS-YOLOV5 network model trained in step 4 is used to detect the fabric image to be detected, and the detection results are output.

[0057] Step 5 is implemented as follows: An image to be detected is input. After feature extraction and 32x downsampling by the backbone extraction network, three effective feature layers are generated. These layers are then used as input to the path aggregation network. After upsampling, attention mechanism operation, and concatenation fusion in the path aggregation network, the images are input to three detectors. The loss function predicts the location and category of defects in the image. The final output is a bounding box with classification category and confidence level, outlining the defect region in the image. The output detection result is... Figure 6 The output defect categories are broken needles and broken yarns.

[0058] Perform step 6 to evaluate the model using the test set obtained in step 2;

[0059] Step 6 is implemented as follows: In order to evaluate the detection performance of the warp-knitted fabric defect detection model for different defect types, the AP index is selected to evaluate the detection accuracy of the model for each type of defect, the mAP index is selected to comprehensively evaluate the detection accuracy of the model for all types of defects, and the R index is selected to evaluate the false negative rate of the model for all types of defects. The evaluation of the warp-knitted fabric defect detection model is completed.

[0060] Figure 7 This is a bar chart showing the detection accuracy of three types of defects in a self-built warp-knitted fabric dataset. The chart represents the average detection accuracy for broken needles, broken yarns, and missing needles, with average accuracies of 96.4%, 94.6%, and 97.3%, respectively, and a mAP of 96.1%. Figure 7 It can be seen that the present invention has high detection accuracy for different types of defects in warp-knitted fabrics.

Claims

1. A fabric defect detection method based on HCS-YOLOV5, characterized in that, Includes the following steps: Step 1: Acquire images of the defective warp-knitted fabric with a resolution of 640×640; Step 2: Using the defective warp-knitted fabric images obtained in Step 1, label the defective regions using LabelImg to establish a warp-knitted fabric defect dataset, resulting in a training set, a validation set, and a test set; Step 3: Establish the HCS-YOLOV5 network model; Implement according to the following process: Step 31: Establish the HCDarkNet feature extraction network. The HCDarkNet feature extraction network is based on the original CSPDarkNet, with the addition of a hybrid atrous space pyramid (HASP) module and a ConvNeXtBlock (CNB) module. This enhances the feature extraction network's ability to extract multi-scale feature information while also improving its semantic information expression capabilities. The HCDarkNet feature extraction network first downsamples the input feature map by 4 times, and then passes it through the hybrid atrous space pyramid module. Its output feature map can extract multi-scale feature information, enhancing the receptive field and capturing global feature details, and reducing the loss of detail information during feature extraction. Then, it passes through 4 downsampling layers, each downsampling the feature map by 2 times. At the same time, each downsampling layer is followed by a ConvNeXtBlock module. Each pixel of its output feature map can realize the detection of defect targets, and at the same time, it increases the semantic information of each pixel. The 4 downsampling layers are stacked consecutively to obtain feature maps that are downsampled by 8 times, 16 times, and 32 times from the input image, respectively, as input information for the feature fusion network. Step 32: The path aggregation network aims to enhance the positional information of the top-level feature map through bottom-up paths, and uses the SimAM attention mechanism to enhance the weights of defective regions and reduce the loss of feature information; Step 33: The main part of the Head consists of three Detect detectors, which are the process of using grid-based anchors to detect targets on feature maps of three scales: 80x80, 40x40, and 20x20. The feature maps are divided into grids according to their size, and three anchors with different aspect ratios are preset for each grid on each feature map to predict and regress the target. The prediction is performed on each grid on the feature map, and the predicted information is compared with the real information. The closer the predicted information is to the real information, the smaller the loss function value. Step 4: Train the dataset using the HCS-YOLOV5 network model established in Step 3; Step 5: Input a fabric image to be detected, use the HCS-YOLOV5 network model trained in Step 4 to detect the fabric image, and output the detection results. Step 6: Evaluate the network model using the test set obtained in Step 2.

2. The fabric defect detection method based on HCS-YOLOV5 as described in claim 1, characterized in that, In step 1, images of defective warp-knitted fabrics with a resolution of 640×640 are acquired. Specifically, the following steps are taken: an industrial camera fixed on a well-lit production line is used to acquire fabric images, and the image size is adjusted to 640×640. The images include three types of defects: broken yarn, broken needle, and missed needle. The dataset contains 4,000 images, all uniformly named in the format ######.png.

3. The fabric defect detection method based on HCS-YOLOV5 as described in claim 2, characterized in that, Step 2 is implemented according to the following process: The LabelImg annotation tool is used to mark the defect information of the defective warp-knitted fabric image obtained in Step 1. The marking content includes the input defect sample, and at the same time, the coordinate information of the defect generated by manually selecting the defect with the upper left corner of the image as the reference, as well as the image size and storage path information. The ######.xml format file generated by the marking information is matched with the ######.png format file. The training set is divided into 3200 training samples, the validation set into 400 validation samples, and the test set into 400 test samples in a ratio of 8:1:

1.

4. The fabric defect detection method based on HCS-YOLOV5 as described in claim 3, characterized in that, The loss function is implemented according to the following procedure: 1) Confidence loss function: The confidence loss function alleviates the problem of severe imbalance in the ratio of positive and negative samples and difficulty in detecting small target defects in single-stage target detection. It weighs the relationship between the number of difficult and easy samples and the number of positive and negative samples and the number of large and small fabric defect targets. Formula (1) is the confidence loss function. L obj =-ylogp-(1-y)log(1-p) (1) In the above formula, y is the true value of the target contained in the anchor, and p is its corresponding predicted value; 2) Classification loss function: The classification loss function increases the weight of small target defects, balances the proportion of large and small targets in the loss function, and pays more attention to the detection of small targets. Formula (2) is the classification loss function. L cls =-ylogp-(1-y)log(1-p) (2) In the above formula, y is the true value of the target contained in the anchor, and p is its corresponding predicted value; 3) Rectangular box loss function: The rectangular box loss function is based on the penalty term of CIOU, which separates the aspect ratio influence factor to calculate the length and width of the target box and the anchor box respectively. The loss function includes three parts: overlap loss, center distance loss, and width and height loss. The first two parts continue the method in CIOU, but the width and height loss directly minimizes the difference between the width and height of the target box and the anchor box. Formula (3) is the bounding box regression loss function. In the above formula, B p and B gt These are the coordinates of the center points of the predicted bounding box and the ground truth bounding box, respectively, ρ 2 (B p B gt w represents the Euclidean distance between the center points of the predicted bounding box and the ground truth bounding box. c h c w represents the width and height of the smallest outer rectangle of the predicted bounding box and the target bounding box, respectively. p w gt h represents the width and height of the predicted bounding box, respectively. p h gt These are the width and height of the actual bounding box, respectively; 4) Total loss function: The total loss function is the sum of the confidence loss function, the classification loss function, and the bounding box loss function. Formula (4) is the total loss function. L=αL cls +δL obj +μL eiou (4) In the above formula, α, δ, and μ are used to balance the proportions of confidence loss, category loss, and bounding box regression loss in the total loss.

5. The fabric defect detection method based on HCS-YOLOV5 as described in claim 1, characterized in that, The output of step 4 is a rectangular box with classification category and confidence level, which outlines the defect area in the image to be detected.

6. The fabric defect detection method based on HCS-YOLOV5 as described in claim 1, characterized in that, Step 5 is implemented according to the following process: In order to evaluate the detection performance of the warp-knitted fabric defect detection model for different defect types, the AP index is selected to evaluate the detection accuracy of the model for each type of defect, the mAP index is selected to comprehensively evaluate the detection accuracy of the model for various types of defects, and the R index is selected to evaluate the false negative rate of the model for various types of defects, thus completing the evaluation of the warp-knitted fabric defect detection model.

Citation Information

Patent Citations

  • Digital printed fabric defect detection method based on deep neural network

    CN112270722A

  • Efficient flaw detection method for complex scene

    CN115049619A