A textile defect detection method and system based on improved YOLOv13
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JIANGSU UNIV
- Filing Date
- 2026-05-25
- Publication Date
- 2026-08-07
AI Technical Summary
[0011]本发明的目的在于克服现有纺织品瑕疵检测技术中存在的因复杂纹理背景干扰强、小目标特征弱以及下采样细节丢失所导致的检测精度低、误检漏检率高的技术问题,提供一种基于改进YOLOv13的纺织品瑕疵检测方法及系统,该方法能够在保留高频细节信息的同时增强全局上下文建模能力与多尺度特征融合能力,从而显著提升纺织品瑕疵检测的准确性与鲁棒性
[0051]本发明设计的小波残差下采样模块(WRDM),通过引入Haar离散小波变换与残差卷积并行处理,在特征图分辨率降低的同时有效保留了高频纹理、边缘突变和局部结构轮廓等细节信息。相比于传统步长卷积或池化下采样,该模块能够显著减少微小瑕疵和弱纹理缺陷在下采样过程中的特征衰减,从而提升模型对小目标、细粒度瑕疵的感知能力。
Smart Images

Figure CN122330124B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer vision and target detection technology, specifically relating to a textile defect detection method and system based on an improved YOLOv13, which is particularly suitable for the automatic detection and location of various defects on textile surfaces such as holes, stains, cuts, and stitch errors. Background Technology
[0002] Textile defect detection is a crucial step in ensuring product quality, improving production efficiency, and reducing manufacturing costs. Traditional manual visual inspection methods are greatly affected by subjective and objective factors such as the inspector's experience, fatigue level, and on-site environment, which easily leads to false positives and false negatives. Furthermore, the inspection speed is slow and the efficiency is low, making it difficult to meet the continuous, automated, and high-paced production demands of the modern textile industry.
[0003] Early textile defect detection technologies primarily relied on statistical, structural, and model-based methods, such as linear backprojection, gray-level co-occurrence matrix, local binary pattern recognition, and detection methods based on template correction, low-rank decomposition, and visual saliency. These methods typically depend on manually designed features to characterize defect areas and are effective in detecting regular textures and simple periodic patterns. However, when applied to scenarios with complex backgrounds, significant texture variations, or weak defect targets, these methods generally suffer from insufficient robustness and limited generalization ability, making them unsuitable for the detection needs of real-world industrial environments.
[0004] In recent years, with the development of deep learning technology, convolutional neural networks have been widely used in textile defect detection tasks, achieving significant improvements in detection accuracy and speed compared to traditional methods. Existing deep learning-based object detection algorithms are mainly divided into two-stage detectors and one-stage detectors. Two-stage detectors (such as R-CNN and Faster R-CNN) possess strong feature representation capabilities and high detection accuracy, but their model structure is complex and their inference speed is slow. One-stage detectors (such as SSD and the YOLO series) adopt an end-to-end detection approach, offering higher detection efficiency and better meeting the real-time requirements of textile production lines. Therefore, research on lightweight, high-precision textile defect detection based on the YOLO series has become an important current direction.
[0005] Specifically, existing research mainly improves model performance by introducing attention mechanisms, optimizing feature fusion networks, and improving loss functions. For example, some studies have introduced improved attention modules and designed adaptive memory fusion networks in the YOLOv5 backbone network to enhance the transmission of shallow localization information and alleviate aliasing effects in feature fusion. Other studies have proposed introducing a multi-branch discrete cosine attention mechanism in the feature extraction stage and constructing a scale-aggregated attention module in the feature fusion stage to improve false positives and false negatives in complex patterned backgrounds.
[0006] Nevertheless, the aforementioned existing methods still have the following shortcomings when facing real-world, complex textile testing scenarios:
[0007] First, textile surfaces often have repetitive textures and complex patterns, which makes the background and the local appearance of the defect area highly similar. Existing models are prone to misjudging the background texture as a defect or missing weak defects, resulting in a high rate of false detection and false detection.
[0008] Second, textile defects typically exhibit characteristics such as large scale variations, blurred edges, and low texture contrast. Conventional downsampling operations in existing models (such as stride convolution or pooling) can easily lead to the loss of high-frequency texture and edge detail information, weakening the model's ability to perceive small targets and weak texture defects.
[0009] Third, while multi-scale feature fusion can integrate semantic information at different levels to some extent, shallow details are easily diluted by higher-level semantic information, limiting the model's ability to comprehensively represent defects of different scales and irregular shapes. In particular, YOLOv13, currently the basic detection model, still faces problems such as loss of details due to downsampling, insufficient contextual modeling ability in complex backgrounds, and inadequate multi-scale feature fusion when applied to textile defect detection.
[0010] Therefore, how to provide a textile defect detection method that can effectively preserve texture details, enhance long-distance context modeling capabilities, and achieve joint enhancement of spatial and channel features during downsampling to overcome the shortcomings of the existing technology is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0011] The purpose of this invention is to overcome the technical problems of low detection accuracy and high false detection and false negative rates in existing textile defect detection technologies, which are caused by strong interference from complex texture backgrounds, weak features of small targets, and loss of downsampling details. This invention provides a textile defect detection method and system based on an improved YOLOv13. This method can enhance global context modeling capabilities and multi-scale feature fusion capabilities while retaining high-frequency detail information, thereby significantly improving the accuracy and robustness of textile defect detection.
[0012] To achieve the above-mentioned objectives, the present invention adopts the following technical solution:
[0013] A method for detecting textile defects based on an improved YOLOv13 includes the following steps:
[0014] Acquire images of the textiles to be inspected;
[0015] The textile image is input into a pre-built improved YOLOv13 detection model, which includes a backbone network, a neck network, and a detection head.
[0016] The backbone network is embedded with a wavelet residual downsampling module, which processes the input features through two parallel branches: the first branch performs Haar discrete wavelet transform on the input features to obtain multiple frequency subbands and performs channel recombination, and the second branch performs stride convolution downsampling on the input features; then the outputs of the two branches are fused and output as the downsampling result.
[0017] The neck network is embedded with an adaptive feature modulation aggregation module, which is used to enhance the multi-scale fusion features from the channel dimension and the spatial dimension respectively, and then adaptively aggregate the enhancement results of the two dimensions through cross-modulation.
[0018] Furthermore, after the backbone network or within the neck network, a hypergraph-based context enhancement module is embedded to sequentially perform hypergraph high-order relevance modeling and context anchoring attention weighting on the input features, and output the enhanced features.
[0019] The detection head outputs information about the type and location of defects.
[0020] Furthermore, the first branch in the wavelet residual downsampling module specifically performs the following operations:
[0021] Applying Haar discrete wavelet transform to the input features decomposes them into low-frequency subbands and high-frequency subbands in multiple directions;
[0022] All sub-band features are spliced along the channel dimension;
[0023] The concatenated features are locally encoded by a convolutional layer to obtain the wavelet branch output.
[0024] The second branch downsamples the input features through a convolutional layer with a stride greater than 1 to obtain the residual branch output;
[0025] The wavelet branch output and the residual branch output are added element by element to obtain the downsampling result.
[0026] Furthermore, the hypergraph-based context enhancement module specifically includes:
[0027] First, the spatial location of the input features is mapped to hypergraph vertices through hypergraph adaptive correlation enhancement operation, generating adaptive hyperedges and performing hypergraph convolution to obtain global high-order correlation enhancement features;
[0028] The higher-order related enhancement features are then enhanced with context anchoring: long-range context in the horizontal and vertical directions is extracted by average pooling and one-dimensional strip convolution, spatial attention weights are generated, and the higher-order related enhancement features are weighted element-wise using these weights.
[0029] Furthermore, in the context anchoring enhancement, the one-dimensional strip convolution includes mutually orthogonal horizontal strip depth convolution and vertical strip depth convolution, and the outputs of the two are fused and then used to generate the spatial attention weights through an activation function.
[0030] Furthermore, the adaptive feature modulation aggregation module includes parallel global channel branches and local spatial branches, as well as a cross-modulation unit;
[0031] The global channel branch is used to linearly map the input features into a query, key, and value matrix, and calculates the attention weights of each channel interaction through a sparse attention mechanism, sorts them from largest to smallest weight value, and retains the channel interactions that are ranked first.
[0032] The local spatial branch is used to extract local spatial features through a combination of depthwise convolution and pointwise convolution, and to generate spatial modulation weights by combining global average pooling.
[0033] The cross-modulation unit is used to cross-recalibrate the outputs of the global channel branch and the local spatial branch using the modulation weights generated by spatial interaction and channel interaction, and then add the two recalibrated features as the output of the adaptive feature modulation aggregation module.
[0034] Furthermore, the sparse attention mechanism adopts a TopK strategy, which retains only the channel interactions with the largest attention weight, while discarding the remaining channel interactions.
[0035] Furthermore, in the improved YOLOv13 detection model:
[0036] The wavelet residual downsampling module is set in the downsampling stage of the backbone network to preserve the texture and edge details of the textile image in the early stage of feature extraction.
[0037] The hypergraph-based context enhancement module is set after the backbone network or in the neck network to capture global high-order semantic associations.
[0038] The adaptive feature modulation aggregation module is set in the multi-scale feature fusion path of the neck network and is used to perform spatial-channel collaborative enhancement on the fused features.
[0039] The adaptive feature modulation aggregation module is set in the multi-scale feature fusion path of the neck network and is used to perform spatial-channel collaborative enhancement on the fused features.
[0040] Furthermore, it also includes the step of training the improved YOLOv13 detection model:
[0041] The image size was uniformly adjusted to a preset size, the learning rate was adjusted using a cosine annealing strategy, and the model was trained end-to-end using the SGD optimizer with detection accuracy as the optimization objective until the model converged. The textile image dataset used for training contained at least two defect categories, and the number of samples for each category was no less than 100.
[0042] The present invention provides a textile defect detection system based on an improved YOLOv13, comprising:
[0043] The image acquisition module is used to acquire images of the textiles to be detected.
[0044] A model storage module is used to store pre-built improved YOLOv13 detection models, the detection models including:
[0045] The backbone network is embedded with a wavelet residual downsampling module. The wavelet residual downsampling module includes a first branch and a second branch in parallel. The first branch is configured to perform Haar discrete wavelet transform and channel reconstruction on the input features. The second branch is configured to perform stride convolution downsampling on the input features. The outputs of the first branch and the second branch are fused as the downsampling result.
[0046] A neck network, in which an adaptive feature modulation aggregation module is embedded, the adaptive feature modulation aggregation module being configured to enhance multi-scale fused features from the channel dimension and spatial dimension respectively, and to perform adaptive aggregation through cross-modulation;
[0047] And a hypergraph-based context enhancement module located after the backbone network or in the neck network, wherein the hypergraph-based context enhancement module is configured to perform hypergraph high-order relevance modeling and context anchoring attention weighting on the input features sequentially;
[0048] The defect detection module is used to input the textile image into the improved YOLOv13 detection model and receive the defect category and location information output by the detection head.
[0049] Furthermore, in the wavelet residual downsampling module, the first branch specifically includes: a Haar wavelet transform unit, a channel splicing unit, and a first convolution unit; the second branch includes a second convolution unit with a stride greater than 1; and an element-wise addition unit, used to add the outputs of the two branches.
[0050] Compared with the prior art, the present invention has the following beneficial effects:
[0051] The wavelet residual downsampling module (WRDM) designed in this invention effectively preserves detailed information such as high-frequency texture, edge abrupt changes, and local structural contours by introducing Haar discrete wavelet transform and residual convolution in parallel processing, while reducing the resolution of the feature map. Compared with traditional stride convolution or pooling downsampling, this module can significantly reduce the feature attenuation of small imperfections and weak texture defects during the downsampling process, thereby improving the model's ability to perceive small targets and fine-grained defects.
[0052] The HyperGraph-based Context Enhancement Module (HyperCEM) designed in this invention mines many-to-many semantic dependencies across locations and scales through high-order hypergraph relevance modeling, and combines a context anchoring attention (CAA) mechanism to recalibrate long-range contexts. Compared to traditional attention mechanisms that can only model pairwise relationships, this module can more effectively distinguish subtle differences between real defects and repetitive texture backgrounds, significantly reducing the probability of false positives and false negatives against complex patterned backgrounds.
[0053] The Adaptive Feature Modulation Aggregation Module (AFMAM) designed in this invention uses a parallel global channel branch (emphasizing TopK sparse attention) and a local spatial branch (emphasizing convolutional self-attention), and employs a cross-modulation mechanism to mutually constrain and aggregate the two feature paths. This design can simultaneously enhance the local texture representation of defective regions and the response of key semantic channels, suppress background noise interference, and make the multi-scale fused features more compact and discriminative.
[0054] This invention organically integrates the three modules mentioned above into the YOLOv13 baseline model, forming a progressive optimization path from shallow detail preservation and mid-level context enhancement to deep feature modulation. On a public dataset containing four types of defects, this invention achieves an mAP@0.5 of 94.2%, a 3.4 percentage point improvement over the baseline model YOLOv13n. On a public dataset containing ten types of defects, this invention achieves an mAP@0.5 of 75.1%, also a 2.3 percentage point improvement over the second-best YOLOv13s method. Its detection performance surpasses mainstream models such as YOLOv8s, YOLOv9s, and YOLOv10s, and it exhibits good cross-dataset generalization ability.
[0055] While achieving a significant improvement in accuracy, this invention keeps the growth of model parameters and computational cost (GFLOPs) within an acceptable range (approximately 4.8M parameters and approximately 12.9G GFLOPs). It can run in real time on industrial equipment with medium computing power, providing reliable technical support for automated quality inspection and transformation and upgrading of the modern textile industry. Attached Figure Description
[0056] Figure 1 This is a schematic diagram of the overall network structure of the improved YOLOv13 detection model (WHA-YOLO) of this invention;
[0057] Figure 2 This is a schematic diagram of the internal structure of the wavelet residual downsampling module (WRDM) in this invention;
[0058] Figure 3 This is a schematic diagram of the internal structure of the HyperGraph-based Context Enhancement Module (HyperCEM) in this invention;
[0059] Figure 4 This is a schematic diagram of the internal structure of the Adaptive Feature Modulation Aggregation Module (AFMAM) in this invention;
[0060] Figure 5 This is a schematic diagram of four types of defect samples in the mini public textile defect dataset of this invention; (a) is a cut; (b) is a stain; (c) is a hole; (d) is a stitch error;
[0061] Figure 6 This is a schematic diagram of ten types of defect samples in the public textile defect dataset of this invention; (a) is general stain; (b) is woven-in fly waste defect; (c) is oil stain; (d) is hole; (e) is missing yarn in knitting; (f) is yarn knot; (g) is needle mark; (h) is loop mark; (i) is starting mark; (j) is stain.
[0062] Figure 7 The images show a comparison of the textile defect detection performance of the present invention on the mini public dataset, where (a) is the input image, (b) is the detection result of the YOLOv13n baseline model, and (c) is the detection result of the WHA-YOLO model of the present invention.
[0063] Figure 8 The images show a comparison of the textile defect detection performance of the present invention on the public dataset, where (a) is the input image, (b) is the detection result of the YOLOv13n baseline model, and (c) is the detection result of the WHA-YOLO model of the present invention. Detailed Implementation
[0064] In the following figures, the same reference numerals denote the same components or features. Figures 1 to 4 This is the core improvement of the present invention. Figures 5 to 8 Experimental data is presented to verify the technical effectiveness of this invention.
[0065] 1 WHA-YOLO Textile Defect Detection Algorithm
[0066] 1.1 WHA-YOLO Model
[0067] YOLOv13 mainly consists of an input terminal, a backbone network, a neck network, and a detection head, achieving a good balance between speed and accuracy in general object detection tasks. However, in textile defect detection scenarios, the original model still has three shortcomings: First, conventional downsampling operations easily lead to the loss of fine-grained texture and edge information; second, the rich repetitive textures on textile surfaces easily cause background interference; and third, the large differences in defect scale make it difficult for the local receptive field to simultaneously capture both detailed representation and global context. Therefore, this invention proposes three key modules—WRDM, HyperCEM, and AFMAM—based on YOLOv13 to construct the WHA-YOLO textile defect detection model, improving its defect detection accuracy in real and complex scenarios. The overall structure is as follows: Figure 1 As shown in Table 1, the meanings of the symbols are given.
[0068] Table 1 shows... Figure 1 List of symbol meanings:
[0069] ;
[0070] 1.2 WRDM Wavelet Residual Downsampling Module
[0071] To mitigate the degradation of texture details and edge information during downsampling caused by traditional stride convolution, this invention designs a wavelet residual downsampling module (WRDM) in the backbone network, the structure of which is as follows: Figure 2 As shown, HWDT stands for Haar wavelet discrete transform. This module borrows the bi-branch modeling idea of residual Haar discrete wavelet transform, combining model-driven wavelet priors with data-driven convolutional semantic modeling to enhance the preservation of defect details while reducing feature map resolution. The core idea of WRDM is to introduce directional priors using Haar discrete wavelet transform in the model-driven branch, and to supplement cross-channel semantic interactions using convolution in the residual branch, ultimately improving the completeness of feature representation through bi-branch fusion. Its WRDM definition is:
[0072]
[0073]
[0074]
[0075]
[0076] in, Represents the input features; X a The subband features are obtained after corresponding wavelet filtering, where a∈{ll,lh,hl,hh} represent low-frequency, horizontal high-frequency, vertical high-frequency, and diagonal high-frequency subbands, respectively; X w This is the feature map after stitching the four sub-bands along the channel dimension (Cat); Represents a Haar wavelet filter; Indicates channel splicing; This represents a 3×3 convolution operation with a stride of 1. This indicates a 3×3 convolution downsampling operation with a stride of 2; and These represent the outputs of the wavelet branch and the residual branch, respectively. This represents the final output feature of WRDM. This design allows WRDM to retain more high-frequency texture and edge details while reducing resolution, and supplements semantic information through residual convolution branches, thereby enhancing the ability to represent defects in complex texture backgrounds.
[0077] Specifically, WRDM consists of two parts: a wavelet branch and a residual branch. The wavelet branch first applies Haar discrete wavelet transform to the input features, decomposing them into low-frequency subbands and multiple high-frequency subbands. Because Haar wavelets have a clear directional expressive ability, they can preserve high-frequency information such as edge abrupt changes, texture variations, and local structural contours during downsampling, thus enhancing the model's ability to perceive fine-grained defects such as holes, stains, and linear imperfections. Subsequently, the features of each subband are reconstructed through channels, and local encoding is further completed through convolution operations to improve the representational compactness of the decomposed features.
[0078] The residual branch uses stride convolution to perform parallel downsampling of the input features. Unlike fixed wavelet filtering, this branch can achieve cross-channel semantic interaction while reducing spatial resolution, thus compensating for the shortcomings of the wavelet branch in high-level semantic modeling. In other words, the wavelet branch focuses more on structural priors and high-frequency detail preservation, while the residual branch focuses more on data-driven semantic abstraction; the two are functionally complementary.
[0079] In the fusion stage, WRDM fuses the wavelet branch output with the residual branch output to obtain a downsampling result that takes into account texture details, edge information, and semantic representation. Compared with ordinary pooling or single-path stride convolution, WRDM can retain more high-frequency information related to textile defect detection during feature compression, reducing feature attenuation of minor defects in the downsampling stage. At the same time, by introducing convolution branches, it enhances the discriminative representation capability against complex texture backgrounds, thus providing more reliable basic features for subsequent context modeling and multi-scale feature fusion.
[0080] 1.3 HyperCEM's Hypergraph-Based Context Enhancement Module
[0081] To improve the model's ability to detect textile defects against complex texture backgrounds, this invention designs a hypergraph-based context enhancement module, HyperCEM, whose structure is as follows: Figure 3 As shown, this module is based on the high-order correlation modeling idea of HyperACE (Hypergraph-based Adaptive Correlation Enhancement) and then introduces the CAA (Context Anchor Attention) mechanism to further re-label the context of the enhanced features, thereby achieving synergistic optimization of global high-order semantic association modeling and long-range contextual saliency enhancement. HyperACE in YOLOv13 overcomes the limitations of convolution and pairwise correlation modeling through adaptive hypergraph computation, enabling the mining of potential high-order correlations across locations and scales, achieving correlation-guided feature enhancement; while CAA utilizes average pooling and striped depthwise convolution to capture long-distance contextual dependencies with lower computational overhead and enhance the feature response of the central region.
[0082] Table 2 is... Figure 3 List of symbol meanings:
[0083] ;
[0084] Specifically, HyperCEM first receives input features from the backbone network or the neck network. The input features are then fed into the HyperACE branch for higher-order correlation modeling. Drawing inspiration from HyperACE's design, the input features are first projected into the latent space via channel mapping. Then, the spatial locations are unfolded into a set of vertices, and a continuous participation matrix is constructed using an adaptive hyperedge generation mechanism. This globally represents the degree of participation of each location in different hyperedges. Subsequently, hypergraph convolution is used to complete bidirectional information propagation from vertex to hyperedge and from hyperedge to vertex, obtaining higher-order correlation enhancement features. Unlike traditional convolution, which can only aggregate information within the local receptive field, and ordinary attention, which mainly models pairwise relationships, this process can explicitly model many-to-many higher-order semantic dependencies, making it more suitable for handling scenarios involving repetitive textures on textile surfaces, complex backgrounds, and the coexistence of multi-scale defects.
[0085] After obtaining high-order relevance enhancement features, the CAA module is further used for context anchoring enhancement. CAA first extracts local context representations through average pooling and 1×1 convolution, then approximates large-kernel convolutions with two mutually orthogonal strip depthwise convolutions to establish long-range dependencies in the horizontal and vertical directions at a lower cost. Subsequently, spatial attention weights are generated using the Sigmoid function, and the input features are weighted element-wise. The advantage of CAA is that it can introduce a wider range of contextual information without significantly increasing computational cost and enhance the discriminative representation of the central region. Its HyperCEM is defined as:
[0086]
[0087]
[0088]
[0089]
[0090]
[0091] in, X represents the higher-order correlation enhancement features after HyperACE modeling. in For input features; F pool The intermediate features are obtained after average pooling and 1×1 convolution; F h Features obtained through vertical strip convolution; This indicates the average pooling operation. and These represent the strip depthwise convolutions in the horizontal and vertical directions, respectively. This represents the Sigmoid activation function. Represents a context attention graph. Output features for HyperCEM.
[0092] Based on the above design, the overall idea of HyperCEM can be summarized as "relevance first, then filtering." HyperACE first mines potential high-order relationships between defects and background, defects themselves, and features at different scales globally, providing more comprehensive global semantic priors for feature representation. CAA then redistributes feature responses using long-range contextual information, highlighting key regions closely related to the defect target and suppressing irrelevant activations caused by repetitive textures and redundant backgrounds. In this way, HyperCEM not only retains the advantages of HyperACE in high-order relationship modeling but also compensates for its shortcomings in contextual saliency filtering, making the model more stable in perceiving weak textures, small scales, and low-contrast defects against complex fabric backgrounds.
[0093] HyperCEM offers two improvements over HyperACE alone: First, HyperACE focuses on establishing global high-order relationships between features, while CAA further captures information about relevant contexts that are more relevant. Second, HyperACE emphasizes cross-scale and cross-location information interaction, while CAA enhances its modeling ability for spatial directionality and long-range dependencies through strip convolution, making the two complementary. For textile defect detection tasks, this design can more effectively distinguish subtle differences between real defects and background textures, reducing false positives and false negatives caused by repetitive patterns, edge perturbations, and background similarity.
[0094] HyperCEM organically combines the high-order correlation modeling capabilities of HyperACE with the long-range context anchoring capabilities of CAA, realizing a progressive feature optimization process from global relational awareness to key region enhancement. This module can effectively improve the discriminative representation of defect regions against complex textile texture backgrounds, providing more robust and focused semantic features for subsequent detection heads.
[0095] 1.4 AFMAM Adaptive Feature Modulation Aggregation Module
[0096] To further enhance the model's ability to represent fine-grained defects, this invention introduces an Adaptive Feature Modulation Aggregation (AFMAM) module into the neck network, the structure of which is as follows: Figure 4As shown, the neck network plays a crucial role in multi-scale feature fusion and semantic transfer. However, in textile defect detection scenarios, repetitive textures, regular patterns, and weak contrast defects often lead to two types of problems: First, local textures and edge details are easily smoothed or diluted during layer-by-layer fusion, making it difficult to fully express fine-grained structures such as hole edges, stain outlines, and linear defects. Second, complex backgrounds generate a large number of redundant responses in the channel dimension, weakening the network's ability to focus on real defect areas. To address these issues, AFMAM is designed to further modulate and aggregate the fused features to enhance the discriminativeness and robustness of the feature representation.
[0097] Table 3 is... Figure 4 List of symbol meanings:
[0098] ;
[0099] The core of AFMAM is the AFM (Adaptive Feature Modulation) module, which collaboratively enhances input features from both channel and spatial dimensions. This method first models global dependencies along the channel dimension and uses a dynamic sparsity strategy to filter more valuable channel interaction information. Then, it refines spatial pixel relationships through a convolutional approximate self-attention mechanism, strengthening local structure and fine-grained detail representation. These two aspects correspond to two types of feature representations: the global channel branch and the local spatial branch, respectively, exhibiting significant complementarity. Based on this idea, this invention does not simply superimpose two existing modules but reconstructs them into a spatial and channel collaborative modulation mechanism suitable for textile defect detection: the spatial branch focuses on highlighting the local texture, edge contours, and structural anomalies of the defect region, while the channel branch focuses on filtering more discriminative feature responses from a global semantic perspective, thereby suppressing irrelevant noise in complex backgrounds. Its AFM definition is as follows:
[0100]
[0101]
[0102]
[0103]
[0104]
[0105] in, Represents input features; and F represents the channel branch and spatial branch mappings, respectively. c F s These are the intermediate features of the channel branch and the spatial branch, respectively; A cFor sparse channel attention weights; , , For the query, key, and value matrix in channel attention; This represents the TopK sparse selection operation; Q, K, V are the query, key, and value matrices generated by linear mapping of input features; d is the dimension of the attention head, and F... s ´ Features after spatial modulation; F c ´ These are the features after channel attention weighting; Ms, Mc: spatial modulation weights, channel modulation weights; fs, fc: spatial modulation function, channel modulation function (usually a 1×1 convolution); and These represent 3×3 depthwise convolution and 1×1 pointwise convolution, respectively. Indicates global average pooling; This represents the Sigmoid activation function; The symbol represents the GELU activation function; ⊙ represents element-wise multiplication; This is the final output feature of the AFM module. The process models global dependencies through channel branching, enhances local pixel representations through spatial branching, and then utilizes cross-modulation to achieve synergistic enhancement of spatial details and channel semantics.
[0106] Specifically, AFM first divides the input features into two branches. The global channel branch generates query, key, and value features through linear mapping and uses a TopK sparsity strategy to retain more important channel dependencies from dense attention relationships, thereby highlighting semantic channels more relevant to defect detection. This branch enhances the model's ability to utilize global semantic information and reduces redundant responses from complex texture backgrounds and repetitive patterns. The local spatial branch uses a convolutional structure to approximate spatial self-attention, modeling neighborhood pixel relationships through local convolution and combining it with global average pooling to extract spatial contextual information, thereby strengthening the perception of edge abrupt changes, texture anomalies, and local contour changes. This design allows the channel branch to focus on which semantic responses are more representative of true defects, while the spatial branch focuses on where the defects are located and how their local morphology changes, thus complementing each other functionally.
[0107] After completing the dual-branch feature extraction, AFM further generates modulation weights through spatial and channel interactions, performing cross-recalibration and adaptive aggregation on the two feature paths. Unlike direct addition or simple concatenation, this cross-modulation method enables the spatial branch to be constrained by global channel semantics, suppressing spurious responses caused solely by local texture similarity; simultaneously, it allows the channel branch to perceive supplementation from local structural details, enhancing its ability to focus on real defect regions. Finally, the modulated dual-branch features are added together to obtain an enhanced representation that combines local details and global semantics. This design allows AFMAM to simultaneously improve the expression of defect edges and the response intensity of key channels against complex texture backgrounds, thereby enhancing the model's robustness in detecting small targets, weak contrast targets, and fine-grained defects.
[0108] AFMAM is primarily a spatial and channel joint modulation and aggregation module for textile defect detection. It organically combines local detail enhancement with global semantic filtering, further suppressing background interference and highlighting key defect responses during the multi-scale feature fusion stage, providing a more compact, stable, and discriminative feature representation for subsequent detection heads.
[0109] 2. Dataset and Experimental Setup
[0110] 2.1 Dataset
[0111] This is a mini public textile defect dataset from https: / / app.roboflow.com / miaofish / projects. The dataset contains 1961 images across four common defect categories: cuts, holes, stains, and thread errors. The images are divided into training, validation, and test sets in a 7:2:1 ratio. Figure 5 The dataset displays images of four types of real data.
[0112] This dataset, from the same website, contains a public textile defect dataset. It includes 10 common defect categories: general contamination, fly contamination, oil spot, hole, knit yarn missing, knot, needle mark, loop mark, knit setup, and woven stain. A total of 5212 images are included, divided into training, validation, and test sets in a 7:2:1 ratio. Figure 6 The dataset displays images of 10 categories of real data.
[0113] 2.2 Experimental Setup
[0114] The experiments were conducted using the PyTorch 2.0.1 framework on an Intel Core i9-13900K processor and an NVIDIA RTX 4090 graphics card. The input image size was set to 640×640, the batch size to 16, the number of training epochs to 600, and the initial learning rate to 0.01. Cosine annealing was used for weight decay. The optimizer chosen was SGD with a momentum of 0.937 and a weight decay rate of 0.0005.
[0115] 2.3 Model Evaluation Indicators
[0116] This experiment uses multiple metrics to comprehensively evaluate the performance of the target detection model, including mAP@0.5 (mean average precision, accuracy at IoU of 0.5), mAP@0.5-0.95 (mean average precision, average precision in the IoU range of 0.5 to 0.95), number of parameters, and GFLOPs (Giga Floating-Point Operations per Second). Detailed explanations are as follows:
[0117] (1) mAP50 refers to the average precision of the detection results for all categories when the IoU threshold is set to 0.5. It is used to evaluate the accuracy of the model in target localization and classification. The higher the value of this index, the better the model's detection performance. mAP50 is determined by precision (P) and recall (R), and its calculation formula is as follows:
[0118]
[0119]
[0120] P represents the proportion of actual positive samples out of those predicted as positive, and R represents the proportion of actual positive samples that were correctly detected. This indicates the number of targets that were correctly detected. This indicates the number of items that were mistakenly identified as targets. This indicates the number of targets that were not detected.
[0121]
[0122]
[0123] Plotting R on the horizontal axis and P on the vertical axis, the two show an inverse relationship under different confidence thresholds, and the area under the curve is the mean precision (AP). P(R) is the precision-recall curve, and the average AP over all classes is taken to obtain mAP, where N is the total number of classes; it is used to measure the overall performance of the model in multi-class detection tasks.
[0124] (2) mAP50-95 is the average value calculated under multiple conditions with IoU thresholds ranging from 0.5 to 0.95 (step size of 0.05). Compared with mAP50 with a single threshold, this index can more comprehensively reflect the overall performance of the model under different positioning accuracy requirements.
[0125] (3) Parameters represent the total number of trainable parameters in a neural network, including weights and biases. This metric reflects the scale and storage requirements of the model. More parameters usually mean a more complex model structure and greater consumption of memory and computing resources.
[0126] (4) GFLOPs is used to measure the computational complexity of a model, representing the number of floating-point operations (in billions) required for the model to complete one forward inference. This metric directly reflects the model's demand for computing resources. The lower the GFLOPs, the smaller the computational overhead of the model, making it more suitable for deployment on devices with limited computing power (such as embedded or edge devices).
[0127] The present invention provides a textile defect detection system based on an improved YOLOv13, comprising:
[0128] The image acquisition module is used to acquire images of the textiles to be detected.
[0129] A model storage module is used to store pre-built improved YOLOv13 detection models, the detection models including:
[0130] The backbone network is embedded with a wavelet residual downsampling module. The wavelet residual downsampling module includes a first branch and a second branch in parallel. The first branch is configured to perform Haar discrete wavelet transform and channel reconstruction on the input features. The second branch is configured to perform stride convolution downsampling on the input features. The outputs of the first branch and the second branch are fused as the downsampling result.
[0131] A neck network, in which an adaptive feature modulation aggregation module is embedded, the adaptive feature modulation aggregation module being configured to enhance multi-scale fused features from the channel dimension and spatial dimension respectively, and to perform adaptive aggregation through cross-modulation;
[0132] And a hypergraph-based context enhancement module located after the backbone network or in the neck network, wherein the hypergraph-based context enhancement module is configured to perform hypergraph high-order relevance modeling and context anchoring attention weighting on the input features sequentially;
[0133] The defect detection module is used to input the textile image into the improved YOLOv13 detection model and receive the defect category and location information output by the detection head.
[0134] In the aforementioned wavelet residual downsampling module, the first branch specifically includes: a Haar wavelet transform unit, a channel splicing unit, and a first convolution unit; the second branch includes a second convolution unit with a stride greater than 1; and an element-wise addition unit, used to add the outputs of the two branches.
[0135] 3. Results and Analysis
[0136] 3.1 Ablation Experiment
[0137] To verify the effectiveness of the improved modules proposed in this invention, ablation experiments were conducted on the mini public textile defect dataset, and the results are shown in Table 4. Table 4 shows that the baseline model YOLOv13n has an mAP@0.5 of 90.8%. When WRDM, AFMAM, and HyperCEM were introduced respectively, the model's mAP@0.5 increased to 93.3%, 93.2%, and 93.4%, respectively, indicating that the three modules can improve the model's ability to detect textile defects from different perspectives.
[0138] Table 4 Ablation Experiment Results:
[0139] ;
[0140] As shown in the ablation experiments numbered 1 to 4 in Table 4, the introduction of WRDM significantly improved the model performance, indicating that preserving high-frequency texture and edge details during the downsampling stage is crucial in textile defect detection. Textile defects typically have characteristics such as small size, blurred boundaries, and abrupt local texture changes. Traditional stride convolution is prone to losing details during feature compression, while WRDM, through the collaborative modeling of wavelet branches and residual branches, retains more structural information related to defects while reducing feature map resolution, thus directly improving detection accuracy. HyperCEM's improvement was slightly higher than WRDM's, indicating that in complex texture backgrounds, relying solely on the receptive field of local convolution is insufficient to fully distinguish defects from the background. However, high-order correlation modeling based on hypergraphs combined with context anchoring mechanisms can more effectively capture semantic dependencies across regions and scales, thereby enhancing the model's ability to discriminate real defect regions. AFMAM also brought significant performance gains, indicating that joint modulation of spatial details and channel relationships in the multi-scale feature fusion stage helps to further highlight key defect responses and suppress background noise.
[0141] From the pairwise combination results of experiments 5 to 7 in Table 4, the combination of WRDM+AFMAM showed the best performance, achieving 94.0% mAP@0.5, higher than WRDM+HyperCEM's 93.7% and AFMAM+HyperCEM's 93.5%. This indicates that WRDM and AFMAM are functionally complementary. The former mainly addresses the detail preservation problem in the shallow feature extraction stage, while the latter primarily affects the feature modulation and aggregation process of the neck network. Both optimize the feature extraction and feature fusion stages respectively, thus forming a more complete performance gain chain when used together. In contrast, while HyperCEM enhances global context modeling capabilities, its role is more focused on semantic association modeling and less direct in preserving defect details than WRDM. Therefore, its performance improvement when combined with other modules is slightly smaller.
[0142] When all three modules are introduced simultaneously, the model's mAP@0.5 reaches 94.2%, an improvement of 3.4 percentage points over the baseline, making it the best result among all combinations. This indicates that the WRDM, HyperCEM, and AFMAM proposed in this invention are not simply superimposed, but rather form a progressive optimization path at three levels: detail preservation, context enhancement, and feature modulation aggregation. WRDM improves the ability to preserve shallow texture and edge information, HyperCEM strengthens global relationship modeling in complex backgrounds, and AFMAM further enhances the fused features through spatial-channel synergistic enhancement. The combined effect of these three modules enables the model to exhibit better detection performance in textile scenarios with small targets, weak textures, and complex backgrounds. It should be noted that the number of parameters in the complete model increases from 2.479 M to 4.832 M, indicating that the performance improvement is accompanied by a certain increase in complexity. However, considering the significant improvement in accuracy, this cost is still highly acceptable in industrial quality inspection scenarios.
[0143] 3.2 Comparative Analysis of Experimental Results
[0144] (1) Comparative analysis of experimental results on the mini public dataset
[0145] To verify the overall performance of the method of this invention, WHA-YOLO was compared with mainstream detection models such as YOLOv8, YOLOv9, YOLOv10, YOLOv11, YOLOv12, and YOLOv13. The experimental results are shown in Table 5. It can be seen that WHA-YOLO achieves 94.8% precision, 92.1% recall, and 94.2% mAP@0.5 on the mini public dataset, respectively, all outperforming the comparison models. This indicates that the method of this invention has better overall detection performance in textile defect detection tasks. Especially in the mAP@0.5 (overlap rate between predicted and ground truth boxes) metric, it improves by 2.9 percentage points compared to YOLOv13s' 91.3%; and by 1.7 and 2.0 percentage points compared to the better-performing YOLOv10s and YOLOv8s, respectively, demonstrating a significant advantage in localization and classification accuracy. Where Parameters / M represents the number of parameters, in millions, and GFLOPs / G represents Giga Floating-Point Operations, in billions of floating-point operations.
[0146] Table 5. Performance comparison of different models on the mini public dataset:
[0147] ;
[0148] From the perspectives of precision and recall, WHA-YOLO achieves a precision of 94.8%, significantly higher than the comparison models, indicating that the model can more effectively suppress false detections in complex contexts. Its recall reaches 92.1%, also higher than most models except YOLOv10s, demonstrating strong capabilities in reducing false negatives. This shows that the method presented in this chapter does not simply increase the confidence threshold to achieve higher precision, but rather achieves a good balance between false negative suppression and target recall. Considering the method design, WRDM's enhancement of detail preservation helps reduce false negatives due to minor flaws, HyperCEM's modeling of contextual relationships helps reduce misjudgments caused by background interference, and AFMAM further enhances the discriminative power of fused features. Therefore, the combined effect of these three factors leads to a simultaneous improvement in both overall model precision and recall.
[0149] From the perspective of model complexity, WHA-YOLO has 4.832 M parameters and 12.9 G G G, respectively, which is higher than YOLOv13n's 2.479 M parameters and 6.4 G G G G. This indicates that the model incurs a certain computational cost to achieve better detection performance. However, in terms of actual results, with an increase of approximately 2.35 M parameters and approximately 6.5 G ...
[0150] (2) Comparative analysis of experimental results on the public dataset
[0151] To further verify the model's generalization ability, this section conducted comparative experiments on the public textile defect dataset, and the results are shown in Table 6. It can be seen that WHA-YOLO achieves Precision, Recall, and mAP@0.5 of 77.5%, 73.5%, and 75.1% respectively on this dataset, outperforming all the comparison models. Specifically, compared to YOLOv13s, mAP@0.5 is improved by 2.3 percentage points; compared to models such as YOLOv8s, it also shows an improvement of approximately 2.5 percentage points. This indicates that the method in this chapter was not specifically optimized for the mini public dataset, but maintained good detection capabilities on the public dataset with more categories and more complex backgrounds, demonstrating a certain degree of generalization performance.
[0152] Table 6. Performance comparison of different models on the public dataset:
[0153] ;
[0154] Compared to the mini public dataset, the overall performance metrics on the public dataset are generally lower, mainly due to its larger number of categories, more complex defect morphologies, and greater variation in sample distribution. Despite this more complex data distribution, WHA-YOLO still maintains optimal performance, indicating that the method presented in this chapter has better adaptability to complex working conditions. In particular, the improvement in precision is significant, demonstrating the model's stronger ability to suppress pseudo-defect responses under complex backgrounds and multi-class interference conditions; Recall also shows a slight improvement, indicating improved ability to capture weak textures and fine-grained defects. Experimental results on both datasets demonstrate that the WHA-YOLO method not only performs superiorly on specific datasets but also exhibits good robustness and stability across datasets.
[0155] 3.3 Visual Result Analysis
[0156] To further analyze the model's ability to focus on defect areas, this section selects typical test samples and visually compares the detection results of YOLOv13n and WHA-YOLO, such as... Figure 7 and Figure 8 As shown, compared to the original YOLOv13n, WHA-YOLO's response to the defect region is more focused and complete, the predicted bounding box position matches the actual defect region better, and the confidence level is higher. This indicates that the improved method proposed in this chapter can more accurately capture the key features of the defect target and effectively suppress interference from complex background textures.
[0157] Specifically, such as Figure 7 In defect samples with blurred edges, small scale, or elongated shapes, YOLOv13n is prone to detection box offset, incomplete response, and even missed detections, while WHA-YOLO can more stably locate defect regions. This is mainly due to WRDM's preservation of more high-frequency textures and edge details during the downsampling stage, allowing the model to obtain more fundamental features conducive to defect recognition at a shallow level. Figure 8 For samples with repetitive background textures and high similarity between defective areas and the background, YOLOv13n is more susceptible to background interference, while WHA-YOLO shows a significant reduction in false activation areas. This indicates that HyperCEM effectively improves the model's ability to distinguish subtle differences between defects and the background through high-order relation modeling and contextual anchoring enhancement.
[0158] Furthermore, in samples with coexisting multi-scale targets or complex local details, WHA-YOLO's detection boxes are more compact, and its confidence level is more stable. This indicates that AFMAM effectively modulates spatial details and channel semantics during multi-scale feature fusion, further enhancing the response of key features. Therefore, WRDM, HyperCEM, and AFMAM demonstrate a clear synergistic effect in the visualization results: the former ensures that detailed information is not easily lost, the intermediate module strengthens global context discrimination, and the latter improves the focusing ability of fused features, ultimately enabling the model to obtain more accurate and stable defect detection results in complex textile scenarios.
[0159] To address the problems of easy loss of detailed information, insufficient contextual modeling, and weak feature discrimination ability in complex backgrounds in textile defect detection, this invention proposes an improved textile defect detection method, WHA-YOLO, based on YOLOv13. The main conclusions are as follows:
[0160] (1) A wavelet residual downsampling module WRDM was designed, which combines Haar discrete wavelet transform with residual convolution branch. During the downsampling process, texture details and edge structure are effectively preserved, which improves the model’s ability to perceive fine-grained defects.
[0161] (2) A hypergraph-based context enhancement module HyperCEM was proposed, and the CAA mechanism was combined to perform context recalibration. At the same time, an adaptive feature modulation aggregation module AFMAM was constructed to enhance multi-scale fusion features from two dimensions: spatial detail enhancement and channel semantic filtering, thereby improving the model's ability to distinguish weak textures, small scales and low contrast defects in complex backgrounds.
[0162] (3) Experimental results show that the proposed WHA-YOLO achieves an mAP@0.5 of 94.2% on the mini public dataset, which is 3.4 percentage points higher than the baseline model YOLOv13n; and an mAP@0.5 of 75.1% on the public dataset, which is also 2.3 percentage points higher than the second-best YOLOv13s method. This indicates that the proposed method can effectively improve the defect detection performance in complex textile scenarios and has certain theoretical significance and application value. Further research will be conducted on model lightweighting and industrial deployment optimization.
Claims
1. A method for detecting textile defects based on an improved YOLOv13, characterized in that, Includes the following steps: Acquire images of the textiles to be inspected; The textile image is input into a pre-built improved YOLOv13 detection model, which includes a backbone network, a neck network, and a detection head. The backbone network is embedded with a wavelet residual downsampling module, which processes the input features through two parallel branches: the first branch performs Haar discrete wavelet transform on the input features to obtain multiple frequency subbands and performs channel recombination, and the second branch performs stride convolution downsampling on the input features; then the outputs of the two branches are fused and output as the downsampling result. The neck network is embedded with an adaptive feature modulation aggregation module, which is used to enhance the multi-scale fusion features from the channel dimension and the spatial dimension respectively, and then adaptively aggregate the enhancement results of the two dimensions through cross-modulation. Furthermore, after the backbone network or within the neck network, a hypergraph-based context enhancement module is embedded to sequentially perform hypergraph high-order relevance modeling and context anchoring attention weighting on the input features, and output the enhanced features. The detection head outputs information about the type and location of defects. The first branch in the wavelet residual downsampling module performs the following operations: Applying Haar discrete wavelet transform to the input features decomposes them into low-frequency subbands and high-frequency subbands in multiple directions; All sub-band features are spliced along the channel dimension; The concatenated features are locally encoded by a convolutional layer to obtain the wavelet branch output. The second branch downsamples the input features through a convolutional layer with a stride greater than 1 to obtain the residual branch output; The wavelet branch output and the residual branch output are added element by element to obtain the downsampling result; The hypergraph-based context enhancement module specifically includes: First, the spatial location of the input features is mapped to hypergraph vertices through hypergraph adaptive correlation enhancement operation, generating adaptive hyperedges and performing hypergraph convolution to obtain global high-order correlation enhancement features; Then, context anchoring enhancement is performed on the higher-order related enhancement features: long-range context in the horizontal and vertical directions is extracted by average pooling and one-dimensional strip convolution, spatial attention weights are generated, and the higher-order related enhancement features are weighted element by element using these weights; The adaptive feature modulation aggregation module includes parallel global channel branches and local spatial branches, as well as a cross-modulation unit; The global channel branch is used to linearly map the input features into a query, key, and value matrix, and calculates the attention weights of each channel interaction through a sparse attention mechanism, sorts them from largest to smallest weight value, and retains the channel interactions that are ranked first. The local spatial branch is used to extract local spatial features through a combination of depthwise convolution and pointwise convolution, and to generate spatial modulation weights by combining global average pooling. The cross-modulation unit is used to cross-recalibrate the outputs of the global channel branch and the local spatial branch using the modulation weights generated by spatial interaction and channel interaction, and then add the two recalibrated features as the output of the adaptive feature modulation aggregation module.
2. The method according to claim 1, characterized in that, In the context anchoring enhancement, the one-dimensional strip convolution includes mutually orthogonal horizontal strip depth convolution and vertical strip depth convolution. The outputs of the two are fused and then used to generate the spatial attention weights through an activation function.
3. The method according to claim 1, characterized in that, The sparse attention mechanism adopts the TopK strategy, which retains only the channel interactions with the largest attention weight, while discarding the other channel interactions.
4. The method according to claim 1, characterized in that, In the improved YOLOv13 detection model: The wavelet residual downsampling module is set in the downsampling stage of the backbone network to preserve the texture and edge details of the textile image in the early stage of feature extraction. The hypergraph-based context enhancement module is set after the backbone network or in the neck network to capture global high-order semantic associations. The adaptive feature modulation aggregation module is set in the multi-scale feature fusion path of the neck network and is used to perform spatial-channel collaborative enhancement on the fused features.
5. The method according to claim 1, characterized in that, It also includes the step of training the improved YOLOv13 detection model: The image size was uniformly adjusted to a preset size, the learning rate was adjusted using a cosine annealing strategy, and the model was trained end-to-end using the SGD optimizer with detection accuracy as the optimization objective until the model converged. The textile image dataset used for training contained at least two defect categories, and the number of samples for each category was no less than 100.
6. A textile defect detection system based on an improved YOLOv13, used to implement the method described in any one of claims 1 to 5, characterized in that, include: The image acquisition module is used to acquire images of the textiles to be detected. A model storage module is used to store pre-built improved YOLOv13 detection models, the detection models including: The backbone network is embedded with a wavelet residual downsampling module. The wavelet residual downsampling module includes a first branch and a second branch in parallel. The first branch is configured to perform Haar discrete wavelet transform and channel reconstruction on the input features. The second branch is configured to perform stride convolution downsampling on the input features. The outputs of the first branch and the second branch are fused as the downsampling result. A neck network, in which an adaptive feature modulation aggregation module is embedded, the adaptive feature modulation aggregation module being configured to enhance multi-scale fused features from the channel dimension and spatial dimension respectively, and to perform adaptive aggregation through cross-modulation; And a hypergraph-based context enhancement module located after the backbone network or in the neck network, wherein the hypergraph-based context enhancement module is configured to perform hypergraph high-order relevance modeling and context anchoring attention weighting on the input features sequentially; The defect detection module is used to input the textile image into the improved YOLOv13 detection model and receive the defect category and location information output by the detection head.
7. The system according to claim 6, characterized in that, In the wavelet residual downsampling module, the first branch specifically includes: a Haar wavelet transform unit, a channel splicing unit, and a first convolution unit; the second branch includes a second convolution unit with a stride greater than 1; and an element-wise addition unit, used to add the outputs of the two branches.
Citation Information
Patent Citations
Cloth defect detection method based on deep learning
CN120219288A
Photovoltaic panel defect detection method fusing multi-scale wavelet and lightweight attention mechanism
CN121353789A