Lightweight fabric surface defect detection method and device
By introducing ADown, StarBlock and PC_Detect into the YOLOv8 model, a lightweight fabric defect detection model is constructed, which solves the problems of low fabric defect detection efficiency and insufficient accuracy in the prior art, and achieves more efficient and accurate fabric defect detection.
Patent Information
- Application Number
- CN202411198685.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2025-02-07
AI Technical Summary
The existing fabric defect detection methods are inefficient and insufficiently accurate. Especially when dealing with scenes with complex textures and rich patterns, the YOLO model will have problems such as inaccurate positioning and difficulty in detecting small objects.
A lightweight fabric surface defect detection method is proposed. By introducing ADown to replace the downsampling Conv in backbone and neck in YOLOv8 model, combining StarBlock and efficient PC_Detect detection heads, an improved convolutional lightweight detection model is constructed.
It improves the efficiency and accuracy of fabric defect detection, reduces the amount of model calculation and parameter, and significantly improves the detection effect of small targets and complex scenarios.
Smart Images

Figure CN119399093A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of target detection, and in particular to a lightweight fabric surface defect detection method and device. Background Art
[0002] Fabric defect detection is a visual inspection task applied in the textile industry, which aims to identify and classify defects that may occur in fabrics during the production process. The presence of fabric defects not only damages the appearance, firmness and service life of the product, but may also cause a 45% to 65% reduction in product prices, and even damage the company's reputation and cause product unsalability. Therefore, effective detection of fabric surface defects is an indispensable step in the textile production process.
[0003] In the past, this kind of detection work mainly relied on manual visual inspection, but this method is inefficient and has an accuracy rate of only 70%. The current mainstream detection methods can be mainly divided into fabric defect detection methods based on traditional image processing algorithms and fabric defect detection methods based on deep learning algorithms. Traditional fabric defect detection methods rely on prior knowledge to define an artificial template to extract image features. The process is cumbersome and it is difficult to separate defects from textures, resulting in low defect detection accuracy and high missed detection rate. In recent years, deep learning has developed rapidly. Fabric defect detection based on deep learning has overcome the shortcomings of traditional methods. The model not only has strong detection capabilities, but also has strong applicability and robustness.
[0004] Fabrics usually have complex textures and patterns. The YOLO model will have problems with inaccurate positioning and difficulty in detecting small objects when dealing with scenes with complex textures and rich patterns. Summary of the invention
[0005] In response to the above-mentioned technical problems, the present technical solution provides a lightweight fabric surface defect detection method and device, which can realize fabric surface defect detection, improve detection efficiency, reduce model calculation amount and improve detection accuracy, and can effectively solve the above-mentioned problems.
[0006] The present invention is achieved through the following technical solutions: A lightweight fabric surface defect detection method, the method comprising the steps of: Step 1: Collect images of fabric defects and build a sample set; Step 2: Perform data preprocessing on the sample set obtained in step 1, expand the sample set by scaling, rotating, flipping, and random color preprocessing methods of the fabric image, and obtain a data set; then divide the data set into a training set, a validation set, and a test set in proportion; Step 3: Build an improved convolutional lightweight fabric defect detection model: Step 3.1: Use ADown to replace the downsampling Conv in backbone and neck; Step 3.2: Introduce StarBlock into the backbone part C2f to form the C2f_Star module; Step 3.3: Design PC_Detect using Pconv and 1×1conv in the head part; Step 3.4: Get the built YOLOv8+ADown+C2f_Star+PC_Detect detection network model; Step 4: Input the training set obtained in step 2 into the improved convolution lightweight model obtained in step 3 for training; and verify it through the verification set to obtain the optimal weight model for fabric defect detection; Step 5: Update the weights through multiple trainings, use the optimal training model weights and detect the fabric defect images to be detected in the test set obtained in step 2; Step 6: Input the fabric images to be tested in the test set into the optimal weight model for fabric defect detection and output the detection results.
[0007] Furthermore, the sample set described in step 1 or step 2 comes from multiple resources, including fabric images in the TILDA database, fabric data images provided by the Alibaba platform and a textile company in Guangdong.
[0008] Furthermore, the specific operation method of performing data preprocessing on the sample set obtained in step 1 described in step 2 is as follows: changing the image naming format in the TILDA database from .png to a unified format ending in .jpg; converting the image data defect_Images and annotation information json file in the Alibaba Cloud dataset into corresponding GT frame information, and combining the image and label information into a dataset; using Labimg to annotate the specific location information of the defects on the images provided by the textile company; performing pixel transformation on the images by randomly changing the brightness, contrast, and randomly flipping only for the categories with a smaller number in the combined dataset, so that the data achieves a balance between classes, and divides the dataset according to the proportion.
[0009] Furthermore, the specific operation of step 3.1 is as follows: in the backbone, all Conv after C2f are replaced by ADown, which can be used for downsampling between different layers of the feature map. In the neck part, ADown is used to replace Conv.
[0010] Furthermore, in step 3.2, StarBlock is introduced into C2f of the backbone part to form C2f_Star module; The overall operation method is: in the feature extraction backbone network, use StarnetBlock in Starnet to replace the Bottleneck module in C2f; replace the C2f modules in the sixth and eighth layers of the backbone network with C2f_Star modules.
[0011] Furthermore, the step 3.3 is to introduce Pconv and 1×1conv in the detection network head, and the implementation process is: in the detection network head part, use Pconv and 1×1conv to replace two 3×3conv to form PC_Detect, which can greatly reduce the number of parameters and calculations.
[0012] A lightweight fabric surface defect detection device comprises a memory and a processor; the memory is used to store a computer program that can be run on the processor; the processor is used to execute the steps of the above-mentioned lightweight fabric surface defect detection method when running the computer program.
[0013] A storage medium stores a computer program, and when the computer program is executed by at least one processor, the steps of the above-mentioned lightweight fabric defect detection method are implemented. Beneficial Effects
[0014] The lightweight fabric surface defect detection method and device proposed in the present invention have the following beneficial effects compared with the prior art: The lightweight fabric defect detection model proposed in the present invention uses ADown to replace the downsampling Conv in the backbone and neck based on YOLOv8s. In the backbone, ADown can be used to downsample between different layers of the feature map, and in the neck part, it helps to further refine the resolution of the feature map to achieve more accurate target detection; Cf_Star is used in the backbone to replace the deep C2f, and StarBlock achieves richer feature representation through star operations, integrating ADown, StarBlock and efficient detection heads; in feature extraction, the characteristic ADown module of ADown reduces the complexity of the model by reducing the number of parameters, which helps to improve the operating efficiency of the model, especially in resource-constrained environments. Although ADown aims to reduce the spatial resolution of the feature map, its design also focuses on retaining as much image information as possible so that the model can perform fabric defect detection more accurately. In the backbone of feature extraction, C2f_Star is used to replace the deep C2f. StarBlock in C2f_Star realizes richer feature representation through star operation, which can significantly improve the detection effect. In the detection network, the detection head Detect is replaced with a more efficient PC_Detect detection head to reduce computational complexity and memory access while improving accuracy. In fabric defect tasks, especially for small targets and complex scenes, the detection effect can be significantly improved. In the head part, using Pconv (Partial Conv) and 1×1conv to design PC_Detect can significantly reduce the amount of calculation and parameters of the model on the basis of meeting real-time detection, thereby improving detection efficiency and fabric quality. The present invention realizes efficient fabric defect detection, which not only improves the model detection accuracy while meeting the requirements of industrial real-time detection, but also reduces the amount of model calculation and parameters. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 The figure is a schematic block diagram of the overall process of the method in the present invention.
[0016] Figure 2 This is a schematic diagram of the overall structure of the lightweight and improved YOLOv8 in the present invention.
[0017] Figure 3 This is the StarBlock module diagram introduced in the feature extraction part of the present invention.
[0018] Figure 4 This is the PC_Detect structure diagram after the improvement of the head part in the present invention.
[0019] Figure 5 It is a PR comparison diagram before and after the improvement in the present invention. DETAILED DESCRIPTION
[0020] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. The described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Under the premise of not departing from the design concept of the present invention, various modifications and improvements made by ordinary persons in the art to the technical solutions of the present invention should all fall within the protection scope of the present invention. Example 1
[0021] like Figure 1 As shown, a lightweight fabric surface defect detection method comprises the steps of: Step 1: Collect images of fabric defects and combine some fabric images in the TILDA fabric database, some images on the Alibaba platform, and images collected from a textile factory in Guangdong to build a sample set.
[0022] Step 2: First, perform data preprocessing on the sample set obtained in step 1. The annotation format of the collected sample set is not suitable for yolo and needs to be converted. Use the conversion code to change the image naming format in the TILDA database from ending with .png to a unified format ending with .jpg; according to the image data defect_Images and annotation information json file in the Alibaba Cloud dataset, convert it into the corresponding GT box information, and obtain the image and label information to combine into a dataset.
[0023] Then, for the categories with fewer numbers in the combined data set, the pixels of the images are transformed by randomly changing the brightness, contrast, and random flipping to balance the data between categories. The main thing is to use Labimg to annotate the specific location information of the defects on the images provided by the textile company; and expand the data set by preprocessing the fabric images by scaling, rotating, flipping, and randomizing the colors.
[0024] The fabric images with defects in the dataset are divided into five categories, namely holes, stains, yarn faults, knots and broken warps. Holes include cut holes and puncture holes, stains include oil stains and color stains, and yarn faults include broken yarns, broken warps, and yarn banding.
[0025] Finally, the dataset is divided into training set, validation set and test set according to the ratio; the fabric defect image dataset is divided according to the preset ratio to obtain the training set and validation set. The training set is mainly used to train the parameters of the fabric defect detection network model, and the test set is mainly used to verify the accuracy of the fabric defect detection network model and whether it can be used in actual scenarios.
[0026] Step 3: Build an improved convolutional lightweight fabric defect detection model. The detection model structure is as follows: Figure 2 As shown. The following three adjustments are made to the original YOLOv8 model: First, based on YOLOv8, ADown is introduced in the backbone and neck; secondly, StarBlock is introduced in the backbone part C2f to form the C2f_Star module; finally, lightweight PC_Detect is introduced in the head part using PConv (Partial Conv) and 1×1Conv. The specific operation methods include: Step 3.1: Use ADown to replace the downsampling Conv in backbone and neck; The specific operation of step 3.1 is as follows: In the backbone, all Conv after C2f are replaced by ADown, which can be used for downsampling between different layers of the feature map. In the neck part, ADown is used to replace Conv.
[0027] The ADown module downsamples and extracts features from the input feature map through pooling and convolution operations. First, a two-dimensional average pooling operation is performed on the input tensor x to reduce the size of the input feature map; then the tensor is partitioned, and the pooled tensor is divided into two parts along the channel dimension, named x1 and x2, respectively. Then convolution and maximum pooling operations are performed, and x1 passes through a 3×3 convolution layer for feature extraction and downsampling. x2 first passes through a 3×3 maximum pooling layer for downsampling, and then passes through an x1 convolution layer for further feature extraction; finally, the processed x1 and x2 are spliced in the channel dimension to form the final output feature map.
[0028] Step 3.2: Introduce StarBlock into the backbone part C2f to form the C2f_Star module. The specific operation method is: in the feature extraction backbone network, use the StarBlock module in Starnet to replace the Bottleneck module in C2f; replace the C2f modules in the sixth and eighth layers of the backbone network with C2f_Star modules.
[0029] StarBlock modules such as Figure 3As shown in the figure, the StarBlock module efficiently extracts and fuses image features through a series of convolution operations and nonlinear transformations. First, the input feature map is passed through a depthwise separable convolution layer with a convolution kernel size of 7 to extract local information. Then, the feature map is passed to two 1x1 convolution layers in parallel, nonlinearly transformed by the ReLU6 activation function, and multiplied element by element. Subsequently, the feature map is further processed by another 1x1 convolution layer and a depthwise separable convolution layer with a convolution kernel size of 7. Finally, the processed feature map is added to the original input through a residual connection, which enhances the training stability and feature representation ability of the model.
[0030] Step 3.3: Design PC_Detect using Pconv and 1×1conv in the head part; the implementation process is: in the head part of the detection network, use Pconv and 1×1conv to replace two 3×3conv to form PC_Detect. The improved PC_Detect structure is as follows Figure 4 shown.
[0031] PC_Detect uses Pconv and 1×1conv to replace the two 3×3conv in Detect in the head part of the detection network. PConv uses the redundancy of feature maps to reduce calculations and memory access. Specifically, PConv only applies conventional convolution to a part of the input channels for spatial feature extraction, while keeping the remaining channels unchanged. After passing through the PConv module, the number of channels is reduced by 1×1 convolution to reduce the amount of calculation, and finally the convolution is converted to the corresponding number of channels to calculate the loss. Using Pconv and 1×1conv to replace two 3×3conv can reduce computational complexity and memory access. The resulting PC_Detect can greatly reduce the number of parameters and calculations while maintaining accuracy.
[0032] Step 3.4: Get the built YOLOv8+ADown+C2f_Star+PC_Detect detection network model.
[0033] Step 4: Input the training set obtained in step 2 into the improved convolution lightweight model obtained in step 3 for training; do not use pre-trained weights during training, set the training epoch to 300, and the batch size to 16. Verify with the validation set to obtain the optimal weight model for fabric defect detection.
[0034] Step 5: Update the weights through multiple trainings, use the optimal training model weights and detect the fabric defect images to be detected in the test set obtained in step 2.
[0035] Step 6: Input the fabric images to be tested in the test set into the optimal weight model for fabric defect detection, judge the extracted features, accurately identify and locate the defect position; and output the test results.
[0036] In order to demonstrate the performance of the proposed method, the fabric defect detection network is used to train the processed fabric defect dataset to verify the effectiveness of each module. The experimental results are shown in Table 1. Model A (yolov8s) is used as the baseline. The evaluation index results include accuracy (Precision, P), recall (Recall, R), average precision when IoU is 0.5 (mAP@0.5), parameter amount (Parameter), FLOPS and weight size (Size). The best results are bolded.
[0037] From the table below, we can see that model G performs best in all indicators, with significant improvements in P / %, R / % and mAP@0.5, and significant reductions in parameters, FLOPs and weights. The above ablation experiments verify the effectiveness of each module and prove that all three modules can reduce the number of parameters and computation.
[0038] like Figure 5 As shown in the figure, the improved model reduces the number of parameters by 36%, the amount of calculation by 47%, the weight size by 34%, and the model mAP@0.5 by 2.3%.
[0039] Table 1 Experimental results statistics Example 2
[0040] A lightweight fabric surface defect detection device comprises a memory and a processor; the memory is used to store a computer program that can be run on the processor; the processor is used to execute the steps of a lightweight fabric surface defect detection method described in Example 1 when running the computer program. Example 3
[0041] A storage medium having a computer program stored thereon, wherein when the computer program is executed by at least one processor, the steps of the lightweight fabric defect detection method described in Example 1 are implemented.
[0042] The above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with the technology to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the protection scope of the present invention. Any equivalent transformation or modification made according to the spirit of the present invention should be included in the present invention.
Claims
1. A lightweight fabric surface defect detection method, characterized in that: The method comprises the steps of: Step 1: Collect images of fabric defects and build a sample set; Step 2: Perform data preprocessing on the sample set obtained in step 1, expand the sample set by scaling, rotating, flipping, and random color preprocessing methods of the fabric image, and obtain a data set; then divide the data set into a training set, a validation set, and a test set in proportion; Step 3: Build an improved convolutional lightweight fabric defect detection model: Step 3.1: Use ADown to replace the downsampling Conv in backbone and neck; Step 3.2: Introduce StarBlock into the backbone part C2f to form the C2f_Star module; Step 3.3: Design PC_Detect using Pconv and 1×1conv in the head part; Step 3.4: Get the built YOLOv8+ADown +C2f_Star+PC_Detect detection network model; Step 4: Input the training set obtained in step 2 into the improved convolution lightweight model obtained in step 3 for training; and verify it through the verification set to obtain the optimal weight model for fabric defect detection; Step 5: Update the weights through multiple trainings, use the optimal training model weights and detect the fabric defect images to be detected in the test set obtained in step 2; Step 6: Input the fabric images to be tested in the test set into the optimal weight model for fabric defect detection and output the detection results.
2. A lightweight fabric surface defect detection method according to claim 1, characterized in that: The sample set described in step 1 or step 2 comes from multiple resources, including fabric images in the TILDA database, Alibaba platform and fabric data images provided by a textile company in Guangdong.
3. A lightweight fabric surface defect detection method according to claim 2, characterized in that: The specific operation method of data preprocessing for the sample set obtained in step 1 described in step 2 is as follows: the image naming format in the TILDA database is changed from .png to a unified format ending in .jpg; according to the image data defect_Images and annotation information json file in the Alibaba Cloud dataset, it is converted into the corresponding GT box information to obtain the image and label information combined into a dataset; the images provided by the textile company are annotated with the specific location information of the defects using Labimg; only for the categories with a small number in the combined dataset, the image is pixel transformed by randomly changing the brightness, contrast, and random flipping methods to achieve a balance between classes of data, and the dataset is divided according to the proportion.
4. A lightweight fabric surface defect detection method according to claim 1, characterized in that: The specific operation of step 3.1 is as follows: In the backbone, all Conv after C2f are replaced by ADown, which can be used for downsampling between different layers of the feature map. In the neck part, ADown is used to replace Conv.
5. The lightweight fabric surface defect detection method according to claim 1, characterized in that: In step 3.2, StarBlock is introduced into the backbone part C2f to form the C2f_Star module. The specific operation method is as follows: in the feature extraction backbone network, StarnetBlock in Starnet is used to replace the Bottleneck module in C2f; the C2f modules in the sixth and eighth layers of the backbone network are replaced with C2f_Star modules.
6. A lightweight fabric surface defect detection method according to claim 1, characterized in that: The step 3.3 is to introduce Pconv and 1×1conv into the detection network head, and the implementation process is: in the detection network head part, use Pconv and 1×1conv to replace two 3×3conv to form PC_Detect, which can greatly reduce the number of parameters and calculations.
7. A lightweight fabric surface defect detection device, comprising a memory and a processor; characterized in that: The memory is used to store a computer program that can be run on a processor; the processor is used to execute the steps of a lightweight fabric surface defect detection method as described in any one of claims 1 to 6 when running the computer program.
8. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by at least one processor, the steps of the lightweight fabric defect detection method as described in any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Light-weight-based tire flaw detection method
CN120182785A
Textile defect detection method based on improved double backbone architecture network
CN121391855A
Textile defect detection method based on improved double-backbone architecture network
CN121391855B