A cotton fabric defect detection method based on improved YOLOv8s
By improving the YOLOv8s network and introducing the SPDConv module, BRA-SPPF module, small target detection layer, and NWD-EIoU loss function, the problems of missed detection and false detection of small, weak, and multi-scale defects in cotton fabric defect detection are solved, and efficient cotton fabric defect detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JIANGNAN UNIV
- Filing Date
- 2024-06-07
- Publication Date
- 2026-07-03
AI Technical Summary
Existing cotton fabric defect detection technologies are prone to missed or false detections when detecting tiny, weak, and multi-scale defects, and their detection efficiency is low, making it difficult to meet industrial needs.
An improved YOLOv8s network was adopted, which optimizes the network structure by introducing the SPDConv module, the BRA-SPPF module, the small target detection layer, and the NWD-EIoU loss function to improve feature extraction and detection accuracy.
It significantly improves the detection accuracy of tiny, weak, and multi-scale defects, enhances the overall performance of the cotton fabric defect detection model, and meets industrial testing requirements.
Smart Images

Figure CN118587186B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a cotton fabric defect detection method based on an improved YOLOv8s, belonging to the field of cotton fabric defect detection technology. Background Technology
[0002] my country's cotton textile industry has maintained its position as the world's largest exporter of cotton fabrics for 18 consecutive years, holding a prominent position in the global market and serving as a vital component of my country's industrial economy. The quality of cotton fabric is a crucial aspect of the cotton textile industry chain, with surface defects directly determining the quality of the fabric. Therefore, defect detection is a critical step in cotton fabric production. Currently, most companies use manual visual inspection, which has several drawbacks: 1. It requires highly experienced inspectors; 2. It has low inspection efficiency, small defects are easily overlooked, and prolonged work can lead to missed or false detections; 3. Workers are prone to visual fatigue after long hours; 4. Labor resources, which require significant physical exertion, are becoming increasingly scarce. Therefore, manual inspection is insufficient to meet actual production requirements.
[0003] With the rapid development of artificial intelligence technology, many studies have applied object detection networks to cotton fabric defect detection. Object detection can perform classification and localization, and is mainly divided into two types of detection models: one is two-stage detection, which has the advantage of high detection accuracy; the other is single-stage detection, which has the advantage of faster detection speed. Although current deep learning-based cotton fabric defect detection methods have improved in speed, accuracy, and adaptability, they are prone to missed detections and false detections when dealing with tiny, weak, and multi-scale defects, failing to achieve satisfactory detection results. Summary of the Invention
[0004] To address the problem of poor detection performance for minute, weak defects with large differences in target size in existing cotton fabric defect detection technologies, this invention provides a cotton fabric defect detection method based on an improved YOLOv8s, the technical solution of which is as follows:
[0005] The first objective of this invention is to provide a method for detecting defects in cotton fabric, comprising:
[0006] Step 1: Obtain the image of the cotton fabric to be detected;
[0007] Step 2: Use the improved YOLOv8s network to perform defect detection on the cotton fabric image to be detected, and obtain the final detection result;
[0008] The construction of the improved YOLOv8s network involves replacing the last standard convolution in the backbone network and all standard convolutions in the neck network of the YOLOv8s network model with SPDConv modules.
[0009] Optionally, the construction of the improved YOLOv8s network further includes: introducing the SPPF module in the backbone network of the YOLOv8s network model into the two-layer routing attention mechanism BRA, and placing the BRA module after the first convolution in the SPPF module.
[0010] Optionally, the construction of the improved YOLOv8s network also includes adding a special detection head for small targets to the original three detection heads of the YOLOv8s network model, with the output feature map size being 160×120.
[0011] Optionally, the construction of the improved YOLOv8s network further includes: changing the original localization regression loss function CIoU of the YOLOv8s network model to the NWD-EIoU loss function, wherein the NWD-EIoU loss function is a combination of the NWD loss function and EIoU, and the combination method is shown in the following formula;
[0012] Loss=α·EIoU+(1-α)·NWD
[0013] In the formula, α is the weighting percentage of EIoU.
[0014] Optionally, the weighting percentage α is set to 0.8.
[0015] Optionally, the cotton fabric defects include: broken warp, holes, stains, cotton grains, and seams.
[0016] Optionally, the training process of the improved YOLOv8s network includes: classifying and labeling the collected cotton fabric images using the Labelimg data labeling tool; after labeling, converting the label files from XML format to TXT format; and dividing the dataset into training and validation sets according to the proportion.
[0017] A second objective of this invention is to provide a cotton fabric defect detection system, comprising:
[0018] Image acquisition device, used to acquire images of the cotton fabric to be inspected;
[0019] The defect detection module is configured to perform defect detection on the cotton fabric image using the improved YOLOv8s network as described in any of the above.
[0020] The output display module is configured to output and display the defect detection results.
[0021] Optionally, the image acquisition device includes a CCD camera and a lens.
[0022] A third objective of the present invention is to provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the cotton fabric defect detection method as described in any of the preceding claims.
[0023] The beneficial effects of this invention are:
[0024] The cotton fabric defect detection method of the present invention introduces SPDConv modules into the backbone network and the neck network, and conducts trade-offs and analyses on the position and number of SPDConv modules. Experimental results show that the introduction of SPDConv modules in the present invention can effectively improve the feature extraction capability of low resolution and small targets, thereby improving the detection accuracy of tiny and weak targets and enhancing the overall detection performance of the cotton fabric defect detection model.
[0025] In one embodiment of the present invention, a BRA-SPPF module is further introduced into the YOLOv8s backbone network. By integrating the BRA module into the SPPF module, better content awareness is achieved, while also saving complex computational load. Therefore, the BRA-SPPF module effectively improves the detection performance of targets at different scales while avoiding high computational complexity.
[0026] In one embodiment of the present invention, a small target detection layer is further added, which can enhance the model's ability to perceive small targets, thereby reducing the occurrence of missed detections and false detections of small targets.
[0027] In one embodiment of the present invention, the NWD loss function and EIoU are further combined to construct the NWD-EIoU loss function, which reduces the sensitivity to features of various scales, effectively balances the differences between targets, and thus improves the detection accuracy of targets at different scales.
[0028] This invention improves upon the YOLOv8s network model to construct a defect detection model suitable for cotton fabrics. This model can improve the detection accuracy of tiny, weak defects with large scale differences and enhance the overall performance of the cotton fabric defect detection model. Attached Figure Description
[0029] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying 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.
[0030] Figure 1 This is a flowchart of a cotton fabric defect detection method based on an improved YOLOv8s according to the present invention.
[0031] Figure 2 This is a structural diagram of a cotton fabric defect detection model based on an improved YOLOv8s according to the present invention.
[0032] Figure 3 This is a schematic diagram of the SPDConv module in this invention.
[0033] Figure 4 This is a schematic diagram of the structure of the BRA-SPPF module in this invention.
[0034] Figure 5 This is a schematic diagram of the BRA module.
[0035] Figure 6 This is a diagram showing the types of defects in this invention.
[0036] Figure 7 The image shows the detection results of cotton fabric defects based on the location and number of SPDConv modules.
[0037] Figure 8 The image shows the detection results of various network models for cotton fabric defects. Detailed Implementation
[0038] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.
[0039] Example 1:
[0040] This embodiment provides a method for detecting defects in cotton fabric, including:
[0041] Step 1: Obtain the image of the cotton fabric to be detected;
[0042] Step 2: Use the improved YOLOv8s network to perform defect detection on the cotton fabric image to be inspected, and obtain the final detection result;
[0043] The improved YOLOv8s network construction involves replacing the last standard convolution in the backbone network and all standard convolutions in the neck network of the YOLOv8s network model with SPDConv modules.
[0044] Example 2:
[0045] This embodiment provides a cotton fabric defect detection method based on an improved YOLOv8s. (See also...) Figure 1 The method includes:
[0046] Step 1: Classify cotton fabric defects into broken warp, holes, stains, cotton particles, and seams. Collect cotton fabric defect images according to the defect classification, and complete the annotation, format conversion, and dataset division.
[0047] Step 2: Improve the original YOLOv8 network model based on SPDConv, BRA module, small target detection head, NWD loss function and EIoU loss function to construct a cotton fabric defect detection model;
[0048] Step 3: Train the dataset using the improved YOLOv8s to obtain a trained cotton fabric defect detection model;
[0049] Step 4: Input the image to be detected into the trained cotton fabric defect detection model to perform defect detection on the target cotton fabric and obtain the final detection result.
[0050] Among them, the original YOLOv8 network model was improved to construct a cotton fabric defect detection model. The improved network structure is as follows: Figure 2 As shown, the improvements include: (1) replacing the last convolution of the backbone network and all convolutions of the neck network of the YOLOv8 network model with SPDConv modules; (2) introducing the BRA module into the SPPF module of the YOLOv8 network model and adding BRA after the standard convolution of SPPF; (3) adding a detection layer to the YOLOv8 network model, which is a 160×120 small target layer used to detect cotton fabric defects of 4×3 and above; (4) replacing the loss function of the YOLOv8 network model with the NWD-EIoU loss function, which is a combination of the NWD loss function and EIoU.
[0051] The original YOLOv8 model was divided into five different sizes (n, s, m, l, and x) based on specific needs. The network structure mainly consisted of three parts: the backbone network, the neck network, and the detection head. The basic building block of the backbone network was the C2f module, which could extract better feature information with fewer parameters. The neck network achieved multi-scale feature fusion through a PAN-FPN structure. The detection head used a decoupled head structure to separate the target detection and classification tasks. The YOLOv8 network model adjusted the input image size to 640×480×3, and the output image sizes after detection were 80×60×128, 40×30×256, and 20×15×512, respectively. When the cotton fabric image was compressed to 20×15×512, the feature information of small target defects was easily lost, and most of the small target information after deep convolution was submerged, resulting in poor small target detection performance. In addition, YOLOv8s uses CIoU as its localization regression loss function. This loss function is more sensitive to the positional deviation of small targets, while cotton fabric defects have large scale differences. Therefore, CIoU loss function is not suitable for detecting multi-scale targets such as cotton fabric defects.
[0052] Therefore, in order to improve the detection accuracy of tiny, weak, and multi-scale defects, this embodiment makes the above-mentioned improvements to the YOLOv8s network model. The improved network model is as follows: Figure 2 As shown.
[0053] First, to address the issue of poor detection performance for small and weak targets, the SPDConv module was introduced.
[0054] The CBS layer of the original YOLOv8s network is a strided convolution, which easily loses detailed features during feature learning and performs poorly in detecting low-resolution and small objects. Some stains appear as subtle defects with little difference from the textured background, and after image compression, they are considered low-resolution images. Joints, cotton fibers, and holes in cotton fabric are mostly tiny defects, and the original YOLOv8s network performs poorly in detecting these types of defects. Therefore, the SPDConv module is introduced into the backbone and neck network, replacing the last convolution of the backbone network and all convolutions of the neck network with SPDConv. Compared to ordinary convolutions, the SPDConv module can retain more feature information and effectively improve the feature extraction capability for small targets.
[0055] Specifically, such as Figure 3 As shown, the SPDConv module consists of a spatial-to-depth layer (SPDlayer) and a convolutional layer with a stride of 1 (NS-Conv), making it more sensitive to small targets and low-resolution images. First, the input S×S×C1 original feature map is segmented using a point-by-point sampling method, resulting in scale×scale features of size [missing information]. The feature map is a downsampled version of the original input feature map. Then, all sub-feature maps are concatenated along the dimensional channels to obtain a size of [size missing]. The feature map is then processed. Finally, dimensionality reduction is performed using 1×1 convolution to preserve as much discriminative information as possible from the feature map, resulting in a shape of [size missing]. The final feature map. In this embodiment of the invention, scale is set to 2. As can be seen from the above steps, the SPDConv module retains the features of small targets as much as possible, which can effectively improve the detection effect of low-resolution targets and small targets.
[0056] Secondly, in order to address the poor performance of the original YOLOv8s network in multi-scale target detection, the BRA module was introduced to construct a new module, BRA-SPPF.
[0057] The YOLOv8s backbone network increases the receptive field and enriches feature information through the SPPF module. SPPF is a spatial pyramid pooling structure improved based on SPP, extracting features at different scales through traditional convolution and three max pooling layers. Although the SPPF module can achieve the fusion of global and local information, feature extraction is only achieved through simple max pooling operations, which may lead to the loss of some feature information and the occurrence of false positives and false negatives. To further extract feature information and alleviate the false negative phenomenon caused by the large scale difference of cotton fabric defects, a bi-level routing attention module (BRA) is introduced into the SPPF module. The BRA module is added after the standard convolution, resulting in a new module BRA-SPPF, as shown below. Figure 4 As shown, the BRA-SPPF module filters out irrelevant background information from the network, focusing more on the effective cotton fabric defect features while saving on parameters and computation, thus achieving better multi-scale feature extraction and improving the richness of the feature map.
[0058] Specifically, such as Figure 5 As shown, the BRA module is a dynamic, query-aware sparse attention mechanism. Its core idea is to filter out most irrelevant key-value pairs at the coarse-grained region level, retaining only a small subset of routing regions, and then applying fine-grained token-to-token interactions within the union of these routing regions. The specific steps are as follows:
[0059] (1) First, the input feature map of H×L is divided into S×S non-overlapping regions, and then linearly mapped to obtain the query tensor Q, key tensor K, and value tensor V:
[0060] Q = X r W q K = X r W k V = X r W v
[0061] (2) Then, the attention weights are calculated on the coarse-grained tokens, and only the Topk regions are taken as relevant regions to participate in the fine-grained calculations:
[0062] A r =Q r (K r ) T I r =topkIndex(A r )
[0063] (3) Finally, I is collected using the gather algorithm. rThe topk coarse-grained region is used as both key and value in the final computation. To enhance locality, a depthwise convolution is applied to the values:
[0064] K g =gather(K,I) r V g =gather(V,I) r )
[0065] O = Attention(Q,K) g V g )+LCE(V)
[0066] The BRA module is responsible for capturing global contextual information and local information through the interaction between coarse-grained and fine-grained regions, respectively, which improves the information extraction at different scales of the feature map. The BRA module directly filters out most irrelevant regions through sparsity operations, avoiding the problems of excessive computation and parameters, and achieving high performance with relatively low computational cost.
[0067] Next, in order to further improve the detection capability of small targets, a small target detection layer is added in the neck feature fusion network stage.
[0068] The neck network of the YOLOv8s network employs a three-layer feature map design. For an input of 640×480×3, after feature fusion, three different feature maps are output: 80×60, 40×30, and 20×15, used to detect targets of 8×6, 16×12, and 32×24, respectively. Large-scale feature maps have smaller receptive fields, containing more target locations and local feature details, making them suitable for detecting small targets. Conversely, smaller-scale feature maps have larger receptive fields and richer semantic information, but local details are less pronounced, making them suitable for detecting medium to large targets. However, cotton fabric defects vary in size, often appearing as tiny, subtle defects similar to the textured background. The largest feature map in the original YOLOv8s network is 80×60, which is insufficient for cotton fabric defect detection, easily leading to missed or false detections of tiny defects. Therefore, it is necessary to add a small target detection layer in the neck feature fusion stage, concatenating the 160×120 feature map output from the backbone network with the upsampled neck network, for detecting cotton fabric defects of 4×3 and above. The construction of a 160×120 small target layer enables YOLOv8s to capture the detailed features of cotton fabric defects through smaller sensors. By using four detection layers of different scales for feature fusion, it effectively utilizes the semantic information and fine-grained details at each level, thereby reducing the risk of missing or misidentifying small target defects and making the identification and localization of tiny and weak defects more accurate.
[0069] Finally, to address the issue of poor performance of the original loss function of YOLOv8s in detecting multi-scale targets, an NWD-EIoU loss function was constructed.
[0070] The loss function of the YOLOv8s network consists of bounding box regression loss CIoU+DFL and classification loss VFL. CIoU is calculated by combining the loss of the predicted bounding box with the loss of the ground truth bounding box, taking into account center distance, aspect ratio, and overlap area. However, aspect ratio cannot reflect the actual difference in side length, while EIoU can. The calculation formula is as follows:
[0071]
[0072] In the formula, IoU (Intersection over Union) represents the intersection ratio between the predicted bounding box and the ground truth bounding box; b, w, and h represent the center coordinates, width, and height of the predicted bounding box, respectively; ρ(·) represents the Euclidean distance between the predicted bounding box and the ground truth bounding box; w c and h c Let b represent the width and height of the smallest bounding box composed of the ground truth box and the predicted box, respectively; gt w gt and h gt These represent the center coordinates, width, and height of the actual bounding box, respectively.
[0073] The sensitivity of EIoU to targets of different scales varies greatly. Small targets are more sensitive to positional shifts, leading to a significant decrease in IoU. For medium to large targets, the same positional shift results in only a small change in IoU. To address this issue, a NWD bounding box regression loss, which is insensitive to the positional shifts of small targets, is introduced. This loss function first models the bounding box as a two-dimensional Gaussian distribution, and then uses a normalized Wasserstein distance to measure boundary similarity. The calculation formula is as follows:
[0074]
[0075] This method can measure similarity regardless of whether the two boxes overlap, and it is insensitive to objects of different scales. Therefore, NWD is well-suited for measuring the similarity between predicted and labeled boxes of small objects.
[0076] Cotton fabric defects vary in size. Directly replacing EIoU with NWD would impair the detection performance of large targets. Therefore, EIoU, which is suitable for medium to large target detection, and NWD, which is suitable for small target detection, are combined. The combination method is as follows:
[0077] Loss=α·EIoU+(1-α)·NWD
[0078]
[0079] In the formula, W2 2 (N a N b (cx) is a distance metric with a value range of [0, +∞]. a ,cy a ,w a ,h a ) and B = (cx b ,cy b ,w b ,h b ) are Gaussian distributions N a and N b D is the number of defect categories in the dataset, Loss is the regression loss function, and α is the weighting of EIoU.
[0080] The above is a detailed explanation of step 2. Steps 1, 3 and 4 will be explained in detail below.
[0081] like Figure 6 As shown, the defects in this embodiment of the invention are broken warp threads, holes, stains, cotton fibers, and seams. These defects are the five most frequently occurring types selected based on actual factory surveys. The fabrics used are all solid-color fabrics, and cotton fabrics with different textures and thread counts are selected. The textures include thin thread, thick thread, plain weave, and twill weave. Among them, broken warp threads are long and thin defects, cotton fibers, seams, and holes are mostly small defects that are difficult to detect with the naked eye, and a few stain defects are slight defects with little difference from the texture background.
[0082] To facilitate verification of the effectiveness of the method of the present invention, this embodiment uses acquisition hardware devices such as CCD cameras and lenses to construct a cotton fabric defect dataset with an image resolution of 1294×964 and a total of 2136 images. After acquisition, defects are labeled using Label Img and corresponding XML file information is generated.
[0083] The training platform for this experiment was Ubuntu 20.04.4LTS, utilizing the GPU acceleration of an NVIDIA GeForce RTX3090, based on PyTorch 1.8.1, and using CUDA 11.1 for computational acceleration. The batch size for training was set to 16, the epoch to 300, the initial learning rate to 0.01, and the input image size to 640×480×3.
[0084] To verify the effectiveness of the improved model, this embodiment selects five common evaluation metrics for object detection, specifically:
[0085] (1) Average Precision (AP): The average recognition accuracy for each category;
[0086] (2) Mean Average Precision (mAP): The average recognition accuracy of all categories;
[0087] (3) FPS (Frames per second), the number of frames transmitted per second by the model, that is, the number of images that can be detected per second;
[0088] (4) Precision P, calculated using the following formula:
[0089]
[0090] (5) Recall R (Recall), the formula for which is as follows:
[0091]
[0092] In the formula, TP is the number of positive samples that are correctly detected, FP is the number of negative samples that are incorrectly detected as positive samples, and FN is the number of positive samples that are incorrectly detected as negative samples.
[0093] To verify the effectiveness of the NWD-EIoU loss function introduced in this embodiment and to explore its impact on cotton fabric defect detection performance, the influence of changing the α value on detection performance was analyzed, and the optimal combination of NWD and EIoU was obtained. The experimental results corresponding to different α values are shown in Table 1.
[0094] Table 1: Detection results for different α values
[0095]
[0096] As shown in Table 1, the value of the weight α has a significant impact on the final detection results. As the weight α increases, the mAP value also gradually rises. When the weight α is 0.8, a balance is reached for the dataset with large scale differences in this embodiment, resulting in the best detection performance. When α is 1, it indicates that the loss function is only EIoU, and the detection performance is not optimal. Therefore, the addition of the NWD loss function allows for better measurement of the similarity between the predicted and labeled boxes of small objects, which is beneficial for the detection of multi-scale objects. Therefore, in this embodiment, the weight α is set to 0.8.
[0097] To verify that the current position and number of SPDConv modules are optimal, the impact of replacing different convolutions on detection performance was analyzed, and the experimental results are shown in Table 2. Experiment 2 shows that when all convolutions in the neck network are replaced with SPDConv, the detection performance of each defect is significantly improved, with an mAP increase of 12.5%. Experiment 3 shows that when only the convolutions in the 7th layer of the backbone network are replaced, the detection performance of each defect is slightly improved, with only a 0.3% improvement for broken meridians. When all convolutions in the backbone network are replaced with SPDConv, the detection performance of broken meridians decreases significantly, with an AP of only 35.8%. Experiments 5, 6, and 7 show that the deeper the replaced convolutional layers, the higher the AP and mAP values. Furthermore, when Experiment 7 simultaneously replaces the last convolutional layer of the backbone network and all convolutions in the neck network, all defect detection results are significantly improved, achieving the optimal experimental results. The above experimental results show that focusing too much on small, weak targets in shallow networks can actually impair detection performance. This is mainly because shallow networks are easily affected by background information such as cotton fabric texture, and the SPDConv module ignores medium and large targets. Among these, the detection performance of broken warp defects, which are large, slender targets, fluctuates the most.
[0098] Table 2: Detection results of SPDConv modules at different locations and with different numbers
[0099]
[0100] To more intuitively observe the impact of the location and quantity of SPDConv on the experimental results, some detection results from experiments 4, 5, 6, and 7 are compared, such as... Figure 7 As shown in the figure, replacing all convolutions in the backbone with SPDConv in Experiment 4 not only resulted in missed and false detections of small targets such as stains, cotton particles, and joints, but also in missed detections and incomplete detection boxes for broken wires. Experiments 5, 6, and 7 show that the detection and localization accuracy for each type of defect improves with increasing network layers after the convolutions are replaced.
[0101] To verify the effectiveness of the improved YOLOv8s network model in this embodiment, the impact of SPDConv, BRA module, small target detection head, and NWD-EIoU loss function on the accuracy and speed of the network model was analyzed. Ablation experiments were conducted under the same parameters, and the results are shown in Table 3. Experiments 2, 4, and 6 verified that the SPDConv module and small target detection layer are adept at detecting tiny and weak targets. Experiments 3 and 7 showed that the BRA module can effectively solve the problem of large differences in defect scale, improving the detection capability of small targets while also enhancing the ability to capture the features of slender, broken targets. After using NWD-EIoU, mAP@0.5 and FPS increased by 11.6% and 24.4, respectively, indicating a good effect on balancing sample scale differences and detection speed. The addition of the small target detection head led to a slight decrease in model detection speed, but overall, the detection accuracy improved by 16.5%, and the ability to capture tiny and weak objects was improved, effectively solving the problem of detecting targets with large scale differences.
[0102] Table 3 Ablation Experiment Results
[0103]
[0104] To further verify the superiority and effectiveness of the improved YOLOv8s network model in this embodiment, experiments were conducted on a self-made cotton fabric defect dataset using Faster-RCNN, RT-DETR-L, YOLOv3, YOLOv5s, YOLOv6s, YOLOv7, YOLOv8s, and the algorithm of this embodiment, under the same parameters. The four metrics of accuracy (P), recall (R), mAP@0.5, and FPS were compared, and the comparison results are shown in Table 4.
[0105] Table 4: Comparison Results of Different Algorithms
[0106]
[0107] Compared to Faster-RCNN, RT-DETR-L, YOLOv3, and YOLOv7, the improved YOLOv8s shows significant improvements in all metrics. Compared to YOLOv5s, YOLOv6s, and YOLOv8s, although the FPS decreases slightly, other metrics are greatly improved. Specifically, compared to the original YOLOv8s network, mAP@0.5 is improved by 16.5%, precision by 11.9%, and recall by 8.8%. Although the FPS of this embodiment algorithm is slightly lower, it still meets the requirements for real-time detection. The results show that the improved YOLOv8s has better detection performance than other models, with significant advantages in detecting targets with large scale differences and small, weak targets. While meeting the real-time detection requirements of factories, it significantly improves the model's detection performance, which is beneficial for cotton fabric defect detection.
[0108] To visually illustrate the detection performance of the improved YOLOv8s network model, a direct comparison of some detection results before and after the improvement is presented, such as... Figure 8 As shown in the comparison images, (b1) shows a hole that resembles a stain, (b2) misdetects a hole as a stain, and (b3) correctly detects a hole; (d2) misses a weak cotton particle defect, while (d3) detects it accurately; (a3), (c3), and (e3) show a significant improvement in detection accuracy compared to the original YOLOv8s. The results indicate that the improved network of this invention enhances its ability to extract features at different scales and improves its ability to distinguish between different categories.
[0109] Some steps in the embodiments of the present invention can be implemented using software, and the corresponding software program can be stored in a readable storage medium, such as an optical disc or a hard disk.
[0110] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for detecting defects in cotton fabric, characterized in that, The method includes: Step 1: Obtain the image of the cotton fabric to be detected; Step 2: Use the improved YOLOv8s network to perform defect detection on the cotton fabric image to be detected, and obtain the final detection result; The construction of the improved YOLOv8s network includes replacing the last standard convolution in the backbone network and all standard convolutions in the neck network of the YOLOv8s network model with SPDConv modules. The construction of the improved YOLOv8s network also includes: introducing a two-layer routing attention mechanism (BRA) into the SPPF module in the backbone network of the YOLOv8s network model, placing the BRA module after the first convolution in the SPPF module, and inputting the output of the BRA module into the next layer and the Concat layer respectively.
2. The cotton fabric defect detection method according to claim 1, characterized in that, The construction of the improved YOLOv8s network also includes adding a special detection head for small targets to the original three detection heads of the YOLOv8s network model, with the output feature map size being 160×120.
3. The cotton fabric defect detection method according to claim 1, characterized in that, The construction of the improved YOLOv8s network also includes: changing the original localization regression loss function CIoU of the YOLOv8s network model to the NWD-EIoU loss function, wherein the NWD-EIoU loss function is a combination of the NWD loss function and EIoU, and the combination method is shown in the following formula; In the formula, This represents the weighting percentage of EIoU.
4. The cotton fabric defect detection method according to claim 3, characterized in that, The weight percentage The value is 0.
8.
5. The cotton fabric defect detection method according to claim 1, characterized in that, The defects in the cotton fabric include: broken warp threads, holes, stains, cotton grains, and seams.
6. The cotton fabric defect detection method according to claim 1, characterized in that, The training process of the improved YOLOv8s network includes: using the Labelimg data annotation tool to classify and label the collected cotton fabric images; after the annotation is completed, converting the label files from XML format to TXT format; and dividing the dataset into training set and validation set according to the proportion.
7. A cotton fabric defect detection system, characterized in that, The system includes: Image acquisition device, used to acquire images of the cotton fabric to be inspected; The defect detection module is configured to perform defect detection on the cotton fabric image using the improved YOLOv8s network as described in any one of claims 1-6; The output display module is configured to output and display the defect detection results.
8. The cotton fabric defect detection system according to claim 7, characterized in that, The image acquisition device includes a CCD camera and a lens.
9. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the cotton fabric defect detection method as described in any one of claims 1 to 6.