Weakly supervised fabric defect detection method based on semantic uncertainty region enhancement
By introducing a contrastive learning module for semantically uncertain regions and a dynamic adaptive Gaussian denoising module, the problems of weak feature response and noise interference in fabric defect detection are solved, achieving high-precision and low-cost fabric defect detection, which is suitable for complex texture backgrounds and low-sample scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ZHONGYUAN ENGINEERING COLLEGE
- Filing Date
- 2026-04-21
- Publication Date
- 2026-06-09
AI Technical Summary
Existing fabric defect detection methods suffer from weak feature response, incomplete foreground coverage, and severe noise interference in the presence of tiny defects, slender defects, and complex texture backgrounds. Furthermore, the data construction cost is high and it is difficult to promote the methods that rely on fully supervised training mode with pixel-level fine annotation.
We adopt a weakly supervised detection method based on semantic uncertainty region enhancement, and introduce a contrastive learning module (SUCL) and a dynamic adaptive Gaussian denoising module (DAGD) for semantic uncertainty regions. The detection model is constructed under image-level category labeling. By focusing on defect edges and potential foreground regions through the contrastive learning mechanism, we can suppress false label noise and improve detection accuracy and stability.
Achieving high-precision fabric defect localization by relying solely on image-level annotation significantly reduces annotation costs, enhances the ability to perceive tiny and slender defects, reduces missed detections, and improves the reliability and stability of detection results. It is suitable for complex texture backgrounds and low-sample scenarios.
Smart Images

Figure CN122175962A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of target detection, and more particularly to a method for detecting fabric defects. Background Technology
[0002] With the rapid development of the textile industry and the widespread application of globalized production models, defect detection and screening are crucial for ensuring product quality and brand reputation during textile production. Textile defects are diverse, including loose threads, broken fibers, stains, misweaving, and defective fibers. Traditional manual inspection methods are not only labor-intensive but also significantly influenced by subjective factors, easily leading to missed detections and misjudgments, making them insufficient to meet the efficiency and accuracy requirements of modern large-scale production. Compared to traditional visual inspection technologies, deep learning-based detection methods offer significant advantages in terms of efficiency and accuracy. However, the complex texture structure of textile surfaces, the diverse types of defects, and the significant differences between different textiles present numerous challenges to the practical application of deep learning algorithms. To meet the demands for high efficiency and accuracy, further research on textile defect detection methods is needed.
[0003] In recent years, computer vision and deep learning technologies have been widely applied in the field of textile defect detection. Detection models based on convolutional neural networks (CNNs) and self-attention mechanisms have achieved good results in various visual tasks, improving the level of automation in detection to some extent. However, textile surfaces typically have highly repetitive and complex texture structures, and defects often exhibit characteristics such as being small, elongated, and having low contrast, closely resembling or even partially overlapping with the background texture. This makes it difficult for models to accurately distinguish foreground defects from background areas during feature extraction. Furthermore, the spatial distribution of different types of defects is significantly uneven, further increasing the difficulty of detection. More importantly, most existing high-precision detection methods rely on pixel-level fine annotation for fully supervised training. Due to the complex morphology, blurred boundaries, and diverse types of fabric defects, pixel-level annotation is not only time-consuming and labor-intensive but also requires a high level of expertise from the annotators, resulting in extremely high data construction costs and severely restricting the widespread application of models in real-world industrial scenarios.
[0004] To reduce annotation costs, weakly supervised detection methods have gradually become a research hotspot. These methods typically rely solely on image-level labels for training, generating pseudo-labels through mechanisms such as class activation maps to locate defect regions. However, under weak supervision, the model often only activates the most salient discriminant regions, failing to cover the complete defect structure, especially elongated or low-contrast defect regions, which are easily overlooked. Simultaneously, due to the lack of precise supervision signals, the generated pseudo-labels often contain significant noise, and semantic uncertainty exists in boundary regions, thus affecting model training stability and detection accuracy. Therefore, how to effectively mine potential foreground information in semantically uncertain regions, suppress pseudo-label noise, improve the completeness and accuracy of defect localization, and significantly reduce manual annotation costs under weak supervision relying solely on image-level annotation has become an urgent technical problem to be solved. Summary of the Invention
[0005] To address the technical challenges of existing fabric defect detection methods, such as weak feature response, incomplete foreground coverage, and severe noise interference in the face of minute defects, elongated defects, and complex textures, especially given the high data construction costs and difficulties in generalization under fully supervised training models relying on pixel-level fine annotation, this invention proposes a weakly supervised fabric defect detection method based on semantic uncertainty region enhancement. This method constructs a detection model relying solely on image-level category annotations, without requiring pixel-level fine annotations. By introducing a contrastive learning module based on semantic uncertainty regions (SUCL), it refines the modeling of semantically ambiguous, poorly defined, and easily confused regions with the background in the class activation map. This module focuses on defect edge regions, weak response regions, and potential foreground regions. Through a contrastive learning mechanism, it constrains the consistency and discriminativeness of feature representations in different regions, thereby compensating for the problem of incomplete foreground activation under weak supervision, enhancing the model's ability to perceive minute and elongated defects, and mitigating missed detections caused by weak features and background interference. Meanwhile, this invention introduces a Dynamic Adaptive Gaussian Denoising (DAGD) module to address the problems of false labels easily containing noise and high semantic uncertainty in boundary regions during weakly supervised training. Based on the dynamic changes in the feature distribution of defect regions, it adaptively identifies and suppresses noise information generated during the detection process, reducing the interference of false detection regions on the model training and inference stages, and improving the stability and reliability of detection results.
[0006] To achieve the above objectives, the technical solution of the present invention is implemented as follows:
[0007] A weakly supervised fabric defect detection method based on semantic uncertainty region enhancement, comprising the following steps:
[0008] S1: Obtain the fabric defect image dataset, perform image-level category annotation only on the fabric images, divide the annotated fabric defect image dataset into a training set and a test set, and preprocess the training set;
[0009] S2: Construct a defect detection network model; the defect detection network model includes a connected backbone network and a segmentation detection head. During training, it also includes an auxiliary classifier connected to the backbone network. A contrastive learning module based on semantic uncertainty regions is introduced between the auxiliary classifier and the backbone network. During training, a dynamic adaptive Gaussian denoising module is introduced into the segmentation detection head.
[0010] S3: Train and validate the fabric defect detection network model using the training set and test set to obtain the trained fabric defect detection network model.
[0011] S4: Use the trained fabric defect detection network model to detect defects in fabric images in the test set and output the fabric defect localization result map.
[0012] Furthermore, the backbone network adopts a Transformer-based ViT-B network, which includes a first Transformer Block to a twelfth Transformer Block connected in sequence, used to extract global feature representations of the original fabric image layer by layer.
[0013] The auxiliary classifier is used to classify the features of the eleventh intermediate layer of the ViT-B network and generate an auxiliary class activation response map.
[0014] The segmentation detection head is used to classify the global feature representation and output a fabric defect location result map.
[0015] Furthermore, the contrastive learning module based on semantic uncertainty regions is used to obtain a comprehensive semantic uncertainty map by fusing the class discrimination response, spatial gradient response, and class distribution information of the class activation response map. A two-dimensional Gaussian kernel function is introduced into the comprehensive semantic uncertainty map for smoothing to obtain uncertainty scores for each region. A sampling probability distribution of candidate regions is constructed based on the uncertainty scores of each region. Positive / negative sample regions are selected from the original fabric image and cropped according to the sampling probability distribution of the candidate regions to obtain a set of positive / negative samples. Positive / negative sample pseudo-labels are constructed. The local feature representations corresponding to the positive / negative samples are extracted using the ViT-base visual feature extraction network. Contrastive learning constraints are performed based on the global feature representations and local feature representations.
[0016] Furthermore, a comprehensive semantic uncertainty map is obtained by fusing the class discrimination response, spatial gradient response, and class distribution information of the class activation feature map, including:
[0017] Step 1: Utilize the set low threshold and high threshold Activate the response graph of the class The region is divided into a background region, an uncertain region, and a foreground region. Different response intensity intervals corresponding to the background region, uncertain region, and foreground region are mapped to corresponding uncertainty measures. As the category discrimination response:
[0018] ;
[0019] St2, calculate the class activation response graphs respectively. Horizontal first-order difference and the first-order difference in the vertical direction Extract the first-order difference vector And calculate the magnitude of the first-order difference vector. ; for the magnitude of the first-order difference vector Normalization is performed to obtain the spatial gradient response. ;
[0020] St3, for each pixel position in the class activation response map M Response values under different defect categories c Normalization is performed to obtain the corresponding category response distribution. And calculate the category distribution uncertainty metric based on the category response distribution. :
[0021] ;
[0022] in, For the number of defect categories, For defect category indexing, A constant to prevent abnormal logarithmic operations;
[0023] St4, responding by class distinction Spatial gradient response and category distribution uncertainty measure Weighted fusion yields the final comprehensive semantic uncertainty graph. .
[0024] Furthermore, a two-dimensional Gaussian kernel function is introduced into the comprehensive semantic uncertainty map for smoothing to obtain the uncertainty score of each region. This includes: smoothing the comprehensive semantic uncertainty map using a two-dimensional Gaussian kernel function and obtaining the score using pixel coordinates. The first one is obtained by cropping from the comprehensive semantic uncertainty graph centered on the first one. Candidate regions According to the candidate region Position of each pixel The comprehensive semantic uncertainty value at the location Calculate the corresponding regional uncertainty score :
[0025]
[0026] in, This represents a two-dimensional Gaussian kernel function.
[0027] Furthermore, a sampling probability distribution of candidate regions is constructed based on the uncertainty scores of each region. Positive / negative sample regions are then selected from the original fabric image based on this distribution and cropped to obtain a set of positive / negative samples. Finally, pseudo-labels for the positive / negative samples are constructed, including:
[0028] A. Calculate the sampling probability distribution of the positive sample:
[0029]
[0030] in, This is a parameter used to adjust the smoothness of the probability distribution. For the candidate region set;
[0031] B. Calculate the negative sample sampling probability distribution:
[0032]
[0033] in, To satisfy the background determination constraints The set of regions, which is the candidate region set. Subset;
[0034] C. Based on the positive / negative sample sampling probability distribution, crop out local regions from the original fabric image to obtain positive / negative sample sets, and construct sample pseudo-labels based on the selected positive and negative sample sets:
[0035] ;
[0036] in, , These are the positive sample set and the negative sample set, respectively.
[0037] Furthermore, a contrastive learning constraint is performed based on the global feature representation and the local feature representation, including:
[0038] The local feature representation is input into the MLP local mapper to obtain the local uncertainty features, and the global feature representation is input into the MLP global mapper to obtain the global semantic features. The MLP global mapper is updated using an exponential moving average. , Momentum factor For global mapper parameters, For local mapper parameters; local mapper parameters The similarity relationship between global semantic features and local uncertainty features is discriminatively constrained by introducing InfoNCE contrastive loss, and updated through backpropagation; the formula for calculating the contrastive loss is as follows:
[0039] ;
[0040] in, The number of positive samples obtained from the sampling. For temperature coefficient, For global semantic features, and This represents the local uncertainty characteristics of positive and negative samples.
[0041] Furthermore, the dynamic Gaussian adaptive denoising module is used to adjust the high threshold using a dynamic threshold adjustment strategy based on cosine annealing attenuation. It performs dynamic adjustments; it is also used to remove high-noise-probability pixels in the segmentation detection head prediction distribution using a Gaussian mixture model-based denoising strategy.
[0042] Furthermore, a dynamic threshold adjustment strategy based on cosine annealing attenuation is used to adjust the high threshold. The method for dynamic adjustment is as follows:
[0043] ;
[0044] in, Indicates the current iteration number. This represents the total number of training iterations.
[0045] Furthermore, methods for removing high-noise-probability pixels from the segmentation detection head's prediction distribution using a Gaussian mixture model-based denoising strategy include:
[0046] STEP 1: Calculate the predicted class distribution for each pixel b in the input fabric image. Pixel-level cross-entropy loss between pseudo-labels generated from the class activation response map:
[0047]
[0048] in, Represents the cross-entropy loss function. For pixels Category distribution , Pseudo-labels generated for class activation response maps ;
[0049] STEP2 models the pixel-level cross-entropy loss distribution by fitting a two-component Gaussian mixture model. The loss distribution function is:
[0050] ;
[0051] in, Indicates a Gaussian distribution. , , These represent the percentage, mean, and variance of clean clusters, respectively. , , These represent the proportion, mean, and variance of the noise clusters, respectively.
[0052] STEP3, Calculate pixels Posterior probability of belonging to noise component :
[0053] ;
[0054] STEP 4: Determine the separability of the loss distribution by evaluating the distance between the means of the clean Gaussian component and the noisy Gaussian component, and then... (The sentence is incomplete and requires more context to be translated accurately.) and noise determination constraints Enable noise filtering mechanism to identify and remove sets of pixels with high noise probability. :
[0055] ;
[0056] in, , These are the noise posterior probability threshold and the mean threshold, respectively.
[0057] The beneficial effects of this invention are as follows: The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement proposed in this invention achieves high-precision localization and identification of fabric defects by relying only on image-level category labeling without requiring pixel-level fine annotation. This significantly reduces the manual annotation cost in the data construction process and improves the scalability and engineering application value of the method in practical industrial scenarios. By introducing a contrastive learning module based on semantic uncertainty region (SUCL), this invention performs fine modeling on semantically ambiguous, unclear-boundary, and easily confused regions with background textures in fabric images. It can effectively focus on defect edge regions, weak response regions, and potential foreground regions, compensating for the problem of incomplete foreground region coverage under weak supervision. This mechanism significantly enhances the model's ability to perceive small defects and slender defects, reducing missed detections due to insufficient feature response. At the same time, by constraining the consistency and differentiating the feature expressions of different regions, it enhances the discrimination ability between defect regions and complex backgrounds, effectively reducing the false detection rate and improving detection accuracy and stability. Furthermore, this invention introduces a Dynamic Adaptive Gaussian Denoising (DAGD) module to address the issues of noise-inducing pseudo-labels and erroneous responses in semantically uncertain regions during weakly supervised training. Based on the dynamic changes in the feature distribution of defect regions, it adaptively identifies and suppresses noise information, reducing the interference of pseudo-responses on model training and inference processes, and improving the reliability and consistency of detection results. In practical industrial applications with few samples, imbalanced defect categories, and complex texture backgrounds, the method of this invention still maintains high detection accuracy and good robustness. Compared to fully supervised methods that rely on pixel-level fine annotation, this invention significantly reduces annotation costs while maintaining detection efficiency and performance, possessing higher engineering practical value and industrial application potential. Attached Figure Description
[0058] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the 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.
[0059] Figure 1 This is a flowchart of the weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to the present invention.
[0060] Figure 2 This is the defect detection network model of the present invention.
[0061] Figure 3 This is a design diagram of the contrastive learning module based on semantically uncertain regions of the present invention.
[0062] Figure 4The visualization results of this invention are shown in (a) and (b) respectively. (a) is a dataset of patterned fabrics and (b) is a dataset of plain weave fabrics. Detailed Implementation
[0063] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0064] A weakly supervised fabric defect detection method based on semantic uncertainty region enhancement, such as Figure 1 As shown, the steps include:
[0065] S1: Obtain the fabric defect image dataset, perform image-level category annotation only on the fabric images, divide the annotated fabric defect image dataset into a training set and a test set, and preprocess the training set.
[0066] In this embodiment, a self-built plain weave fabric dataset and a patterned fabric dataset were obtained. The plain weave fabric dataset includes 2200 training images and 500 test images. The images contain slender defects and micro-defects with low contrast to the texture background, and the defect types include five categories: indentation, crease, yarn loosening, stains, and holes. The patterned fabric dataset includes 5948 training images and 500 test images. Its background texture structure is complex, and the defect morphology is irregular. The defect types include six categories: yarn loosening, yarn breakage, yarn binding, cotton balls, holes, and stains. The plain weave fabric dataset is characterized by a high proportion of low-contrast defects, a large number of micro-defects, and a large proportion of linear defects, while the patterned fabric dataset is characterized by strong texture interference, diverse defect categories, and complex morphological changes.
[0067] Image-level category labeling is performed only on the fabric images: only two types of information are labeled: whether the image contains defects and the category to which the defects belong.
[0068] The method for preprocessing the dataset is as follows:
[0069] For the plain weave fabric dataset, considering its relatively regular texture structure but low contrast between defects and background, data augmentation operations are performed on the training set of the original fabric images by horizontal and vertical flipping. This expands the number of samples while maintaining the semantic information of defects, enriching the distribution of defects in different spatial locations and arrangement directions, thereby improving sample diversity and reducing the risk of overfitting during model training. For the patterned fabric dataset, considering its complex background texture and diverse directional changes, the training set of the original fabric images is rotated and expanded at three different angles. By constructing equivalent training samples in different directions, the robustness and generalization ability of the model to complex texture direction changes and irregular defect morphologies are improved, thereby enhancing the overall fabric defect detection performance.
[0070] S2: Construct a defect detection network model; such as Figure 2 As shown, the defect detection network model includes a backbone network and a segmentation detection head connected together. During training, an auxiliary classifier connected to the backbone network is also included. A contrastive learning module based on semantic uncertainty regions is introduced between the auxiliary classifier and the backbone network to solve the problems of insufficient activation of defect edges and easy omission of small defects. During training, a dynamic adaptive Gaussian denoising module is introduced into the segmentation detection head to solve the noise interference caused by complex fabric background texture to defect localization.
[0071] Specifically, the defect detection network model adopts the ViT-base (ViT-B) visual feature extraction network based on Transformer, which includes 12 Transformer Blocks connected in sequence, used to extract the global feature representation of the original fabric image layer by layer.
[0072] Specifically, the segmentation detection head adopts a multi-scale convolutional module structure, including a LargeFOV module and a DenseASPP convolutional module, which are used to classify the global feature representation and output the fabric defect location result map.
[0073] Specifically, the auxiliary classifier adopts a standard convolutional classifier structure, including a 1×1 convolutional layer, a global average pooling layer, and a fully connected layer, which is used to classify the intermediate layer features of the ViT-base visual feature extraction network and generate an auxiliary class activation response map. The intermediate layer of the ViT-B network is the 11th Transformer Block.
[0074] Specifically, such as Figure 3As shown, the contrastive learning module based on semantic uncertainty regions is used to obtain a comprehensive semantic uncertainty map by fusing the class discrimination response, spatial gradient response, and class distribution information of the class activation response map. A two-dimensional Gaussian kernel function is introduced into the comprehensive semantic uncertainty map for smoothing to obtain the uncertainty score of each region. Based on the uncertainty score of each region, a sampling probability distribution of candidate regions is constructed. Based on the sampling probability distribution of candidate regions, positive / negative sample regions are selected from the original fabric image and cropped to obtain a set of positive / negative samples. Positive / negative sample pseudo-labels are constructed. The local feature representations corresponding to the positive / negative samples are extracted using the ViT-base visual feature extraction network. Based on the global feature representation and the local feature representation, contrastive learning constraints are performed to construct a local-global feature alignment relationship.
[0075] Specifically, a comprehensive semantic uncertainty map is obtained by fusing the class discrimination response, spatial gradient response, and class distribution information of the class activation feature map, including:
[0076] First, utilize the set low threshold and high threshold Activate the response graph of the class The region is divided into background, uncertain, and foreground regions, guiding the model to focus on semantically ambiguous potential defect regions and mapping different response intensity ranges to corresponding uncertainty measures. As the category discrimination response:
[0077]
[0078] in, Indicates the pixel position.
[0079] Furthermore, regarding the class activation response graph Perform spatial gradient calculations along the horizontal direction. and vertical direction Calculate the class activation response graphs separately Horizontal first-order difference and the first-order difference in the vertical direction Extract the first-order difference vector And calculate the magnitude of the first-order difference vector. The spatial gradient response intensity is obtained by normalizing the magnitude of the first-order difference vector. This is used to characterize activation mutations and structural instabilities at the edges of fabric defects, enhancing the model's ability to perceive defect contours and local boundaries. The calculation formula is as follows:
[0080] ;
[0081] ;
[0082] in, Activation response graph for classes Middle position Activation value at that location, It is the L2 norm. It is the minimum value. These are the height and width indices of the class activation response map, respectively.
[0083] Furthermore, for each pixel location in the class activation response map M... Response values under different defect categories c Normalization is performed to obtain the corresponding category response distribution. And calculate the category distribution uncertainty metric based on the category response distribution. This is used to characterize the semantic confusion level of a pixel in the category dimension, and the calculation formula is as follows:
[0084] ;
[0085] ;
[0086] in, For the number of defect categories, For category indexing, A constant used to prevent logarithmic aberrations, used to characterize the degree of ambiguity of pixel location at the category discrimination level.
[0087] Furthermore, the final comprehensive semantic uncertainty graph is obtained through weighted fusion. This uncertainty diagram serves as the basis for dividing subsequent positive and negative sample sampling, achieving robust characterization of subtle defect features against a complex fabric background. The formula is as follows:
[0088]
[0089] in, , , These are the weighting coefficients.
[0090] In this embodiment, the contrastive learning module SUCL based on semantic uncertainty regions performs spatial smoothing on the comprehensive semantic uncertainty map and calculates the regional uncertainty score of the candidate cropping region by performing positive and negative sample probability sampling, so as to construct the regional sampling probability distribution.
[0091] Specifically, a two-dimensional Gaussian kernel function is introduced into the comprehensive semantic uncertainty map for smoothing to obtain the uncertainty score of each region. This includes: firstly, a two-dimensional Gaussian kernel function is introduced into the comprehensive semantic uncertainty map for smoothing to improve the stability of the regional uncertainty measurement, and then the pixel coordinates are used as the basis for the score. The first one is obtained by cropping from the comprehensive semantic uncertainty graph centered on the first one. Candidate regions Based on the position of each pixel within the candidate region The comprehensive semantic uncertainty value at the location Calculate the corresponding regional uncertainty score for:
[0092] ;
[0093] in, This represents a two-dimensional Gaussian kernel function.
[0094] In this embodiment, the uncertainty score is normalized to construct a positive sample probability sampling strategy, so that regions with higher scores are selected as positive samples with a higher probability to mine potential foreground defect semantics, and background constraints are introduced. Negative sample sampling is performed, selecting negative samples from regions that meet the background criteria and have low semantic uncertainty, thereby constructing a set of positive and negative samples.
[0095] Specifically, a sampling probability distribution of candidate regions is constructed based on the uncertainty scores of each region. Positive / negative sample regions are then selected from the original fabric image based on this distribution and cropped to obtain a set of positive / negative samples. Finally, pseudo-labels for the positive / negative samples are constructed, including:
[0096] First, the regional uncertainty scores of multiple candidate regions are normalized to construct a sampling probability distribution for the candidate regions. Based on this sampling probability distribution, candidate regions with higher regional uncertainty scores are preferentially selected as positive sample candidate regions. The corresponding positive sample sampling probability distribution is calculated as follows:
[0097] ;
[0098] in, This is a parameter used to adjust the smoothness of the probability distribution. This is the set of candidate regions.
[0099] Furthermore, under the condition that the background determination constraint is met... In the candidate regions, a probability selection process is performed on candidate regions with lower regional uncertainty scores to obtain negative sample candidate regions. The corresponding negative sample sampling probability distribution is calculated as follows:
[0100] ;
[0101] in, The set of regions that satisfy the background determination constraints is called the candidate region set. A subset of.
[0102] Furthermore, based on the positive / negative sample sampling probability distribution, a local region is cropped from the original fabric image to obtain a set of positive / negative samples, and then the selected positive sample set is used as the basis for further processing. With negative samples The set of sample pseudo-labels is constructed using the following formula:
[0103] ;
[0104] in, These are pseudo-labels for positive and negative samples.
[0105] Specifically, local features and global features are extracted from the sampled local uncertainty region and the original image, respectively. These local and global feature representations are then input into two mappers (MLPs) with identical structures but different parameter update methods to obtain local uncertainty features and global semantic features, respectively. The mapper (MLP) includes a local mapper. and global mapper Among them, the global mapper The parameters in the data are updated using the Exponential Moving Average (EMA). Momentum factor =0.9, where For global mapper parameters, For local mapper parameters, local mapper parameters A contrastive loss is constructed based on the global and local feature representations using contrastive learning constraints, and then updated via backpropagation.
[0106] The InfoNCE contrastive loss is introduced to discriminately constrain the similarity relationship between global semantic features and local uncertainty features, thereby making the activation of the class activation map in the foreground region of fabric defects more continuous and complete. The formula for calculating the contrastive loss is as follows:
[0107] ;
[0108] in, The number of positive samples obtained from the sampling. For temperature coefficient, For global semantic features, and This represents the local uncertainty features of positive and negative samples. By maximizing the mutual information between global features and local positive sample features, while simultaneously increasing the distance between them and background negative sample features, deep feature alignment is achieved for semantically confused and boundary-uncertain regions in fabric images.
[0109] In this embodiment, the dynamic Gaussian adaptive denoising module, during the pseudo-label generation stage, addresses the issue of insufficient foreground coverage caused by overly conservative pseudo-labels in the early stages of model training. It introduces a dynamic threshold adjustment strategy based on cosine annealing decay. This strategy adjusts the background threshold based on the training iteration process. Cosine descent adaptive updates are performed to introduce more effective foreground supervision signals in the early stages of training and gradually enhance background suppression capabilities as training progresses, thereby balancing defect region coverage and structural stability, and providing sufficient and stable data support for subsequent segmentation heads.
[0110] Specifically, the background threshold The adjustment form changes with training iterations as follows:
[0111] ;
[0112] in, Indicates the current iteration. This represents the total number of training iterations.
[0113] The dynamic Gaussian adaptive denoising module introduces a denoising strategy based on a Gaussian mixture model (GMM) to address semantically erroneous pixels still present in high-confidence regions. By fitting a two-component Gaussian distribution to model the pixel-level cross-entropy loss, it distinguishes between clean pseudo-label clusters and noisy pseudo-label clusters. Under the constraints of loss distribution separability and noise determination, it adaptively identifies and removes pixels with high noise probability. By gradually removing noise interference from pseudo-labels, it improves the reliability of pseudo-labels, thereby providing a stable and reliable supervision signal for the fabric defect segmentation model.
[0114] Specifically, denoising strategies based on Gaussian Mixture Models (GMMs) include:
[0115] First, for each pixel in the input fabric image Calculate its predicted category distribution Pixel-level cross-entropy loss between pseudo-labels generated from the class activation response map:
[0116] ;
[0117] in, Represents the cross-entropy loss function. For pixels Category distribution , Pseudo-labels generated for class activation response maps .
[0118] Furthermore, a two-component Gaussian mixture model is fitted to model the pixel-level cross-entropy loss distribution to distinguish between clean and noisy pseudo-labels. The loss distribution function is shown below:
[0119] ;
[0120] in, Indicates a Gaussian distribution. , , The percentage, mean, and variance of clean clusters. , , The percentage, mean, and variance of the noise clusters are given.
[0121] Furthermore, the posterior probability that a pixel belongs to a noise component is calculated. :
[0122] ;
[0123] Furthermore, the separability of the loss distribution is determined by evaluating the distance between the means of the two Gaussian components, and the separability is satisfied. and noise determination constraints Enable noise filtering mechanism to identify and remove sets of pixels with high noise probability. :
[0124] ;
[0125] in, , These are the noise posterior probability threshold and the mean threshold, respectively. =0.9, =1.0. This strategy effectively enhances the reliability of false labels by adaptively identifying and removing pixels with high noise probability, thereby improving the model's accuracy in detecting fabric defects.
[0126] S3: The fabric defect detection network model is trained and validated using the training set and the test set. Relying only on image-level supervision signals, the quality of pseudo-labels is gradually optimized through a semantic uncertainty region enhancement mechanism, and high-noise-probability pixels are removed through an adaptive Gaussian denoising mechanism to obtain the trained fabric defect detection network model.
[0127] Specifically, the training process is as follows:
[0128] In each training epoch, the input training set and the original fabric image are processed through the ViT-B backbone network to obtain intermediate layer features and global features. The intermediate layer features are then processed by an auxiliary classifier to obtain activation response maps, and the auxiliary classification loss is calculated. The activation response map is processed by a contrastive learning module based on semantic uncertainty regions to first obtain a comprehensive semantic uncertainty map. Then, uncertainty scores for each region are obtained. Based on these scores, a sampling probability distribution for candidate regions is constructed. Positive / negative sample regions are selected from the original fabric image and cropped according to this distribution, resulting in a positive / negative sample set. Positive / negative sample pseudo-labels are then constructed. The cropped positive / negative sample fabric images are input into the ViT-B backbone network to obtain local feature representations corresponding to the positive / negative samples. The contrastive loss is calculated based on these global and local feature representations. ;
[0129] Perform cosine descent adaptive update of background threshold This is used for the next iteration; global features are input into the segmentation detection head, and pixel-level cross-entropy loss is calculated. Based on the pixel-level cross-entropy loss, a Gaussian Mixture Model (GMM)-based denoising strategy is performed to remove pixels with high noise probability, and the pixel-level cross-entropy loss corresponding to the clean probability pixels is retained as the classification loss of the segmentation detection head. Calculate the total loss , , and To compensate for the loss weights, the model parameters of the backbone network, segmentation detection head, and auxiliary classifier are updated through backpropagation.
[0130] The test set is used for validation every 200 fixed rounds. Training stops when the segmentation accuracy of the test set reaches the required level or the maximum number of training rounds is reached.
[0131] In this embodiment, the backbone network of the defect detection network model adopts the Vision Transformer (ViT-B) architecture for feature extraction from the input fabric image. The size of the input image is set to 448×448 pixels. During the construction of semantic uncertainty regions, the size of the uncertain local regions is set to 96×96, and the number of selected local regions is N, where N is 10. The AdamW optimization algorithm is used during model training, with a weight decay coefficient of 1×10⁻² and an initial learning rate of 6×10⁻⁻⁻⁻⁻⁻⁶. 5 The batch size was set to 4, and the number of training iterations was set to 20,000. In the process of distinguishing between defect and background regions, the initial background threshold parameters were set to 0.25 and 0.7, respectively, to differentiate between different semantic regions. During the contrastive learning process, the temperature coefficient was set to 0.5. The momentum factor in the exponential moving average (EMA) update strategy was set to 0.9. In the feature fusion and weight allocation stages, the weight coefficients... , , The weighting coefficients in the total loss are set to 0.3, 0.5, and 0.2 respectively. , and They were set to 0.25, 0.2, and 0.3 respectively.
[0132] S4: Use the trained fabric defect detection network model to detect defects in fabric images in the test set and output the fabric defect localization result map. In the testing phase, only the backbone network and segmentation detection head are used, and the SUCL module and DAGD module are not introduced.
[0133] Simulation verification:
[0134] (1) Ablation test
[0135] The plain weave fabric dataset presents a challenging application scenario due to the low contrast between defects and background texture, coupled with a relatively limited number of training samples, making defect feature representation difficult. Therefore, experimental results on this dataset more fully demonstrate the detection capabilities and technical effectiveness of the proposed method under complex conditions, thus validating the contribution of each key module to overall performance improvement. Consequently, the ablation experiments were conducted on the plain weave fabric dataset for both training and testing. The following methods were used for comparative verification in the ablation experiments: the Baseline method uses the TOCO framework as the standard framework; Baseline+SUCL adds a semantic uncertainty-based contrastive learning module to the Baseline; Baseline+DAGD adds a dynamic adaptive Gaussian denoising module to the Baseline; and Baseline+SUCL+DAGD is the proposed method, simultaneously applying both the semantic uncertainty-based contrastive learning module and the dynamic adaptive Gaussian denoising module.
[0136] Ablation experiments show that the overall model performance is relatively low when only the Semantic Uncertainty Contrast Learning (SUCL) module is introduced, indicating that relying solely on global semantic features is insufficient for accurate fabric defect detection without adequate local texture detail. In contrast, the introduction of the Dynamic Adaptive Gaussian Denoising (DAGD) module achieves better detection results, demonstrating the crucial role of DAGD in fabric defect identification. Furthermore, the experimental results show that when the SUCL and DAGD modules are effectively coordinated and integrated, the model performance significantly outperforms the case of using only a single module. Therefore, the SUCL and DAGD modules complement and synergize with each other in fabric defect detection tasks, possessing equally important technical value in improving the overall detection capability of the model.
[0137] Table 1 Ablation Experiment Results
[0138]
[0139] (2) Visual results analysis.
[0140] like Figure 4 The diagram shows the visualization results of the method of the present invention on plain weave fabric datasets and patterned fabric datasets. The visualization results further illustrate the technical effectiveness of the method of the present invention. The comparison results show that the method of the present invention can effectively suppress irrelevant region responses under complex texture background conditions, significantly enhance the saliency expression of defect regions, and form defect contours with clear boundaries and complete structures. Especially in low-contrast linear defect scenes, the method of the present invention can still maintain high response intensity and continuity, while some existing methods exhibit discontinuous response or missed detection in such scenes. Furthermore, for micro-defects and defects with high similarity to the background texture, the method of the present invention can achieve relatively complete detection results.
[0141] 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 weakly supervised fabric defect detection method based on semantic uncertainty region enhancement, characterized in that, The steps are as follows: S1: Obtain the fabric defect image dataset, perform image-level category annotation only on the fabric images, divide the annotated fabric defect image dataset into a training set and a test set, and preprocess the training set; S2: Construct a defect detection network model; the defect detection network model includes a connected backbone network and a segmentation detection head. During training, it also includes an auxiliary classifier connected to the backbone network. A contrastive learning module based on semantic uncertainty regions is introduced between the auxiliary classifier and the backbone network. During training, a dynamic adaptive Gaussian denoising module is introduced into the segmentation detection head. S3: Train and validate the fabric defect detection network model using the training set and test set to obtain the trained fabric defect detection network model. S4: Use the trained fabric defect detection network model to detect defects in fabric images in the test set and output the fabric defect localization result map.
2. The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to claim 1, characterized in that, The backbone network adopts the ViT-B network based on Transformer. The ViT-B network includes a first Transformer Block to a twelfth Transformer Block connected in sequence, which is used to extract the global feature representation of the original fabric image layer by layer. The auxiliary classifier is used to classify the features of the eleventh intermediate layer of the ViT-B network and generate an auxiliary class activation response map. The segmentation detection head is used to classify the global feature representation and output a fabric defect location result map.
3. The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to claim 2, characterized in that, The contrastive learning module based on semantic uncertainty regions is used to obtain a comprehensive semantic uncertainty map by fusing the class discrimination response, spatial gradient response, and class distribution information of the class activation response map. A two-dimensional Gaussian kernel function is introduced into the comprehensive semantic uncertainty map for smoothing to obtain uncertainty scores for each region. A sampling probability distribution of candidate regions is constructed based on the uncertainty scores of each region. Positive / negative sample regions are selected from the original fabric image and cropped according to the sampling probability distribution of the candidate regions to obtain a set of positive / negative samples. Positive / negative sample pseudo-labels are constructed, and the local feature representations corresponding to the positive / negative samples are extracted using the ViT-B network. Contrastive learning constraints are then performed based on the global feature representations and local feature representations.
4. The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to claim 3, characterized in that, A comprehensive semantic uncertainty map is obtained by fusing the class discrimination response, spatial gradient response, and class distribution information of the class activation feature map, including: Step 1: Utilize the set low threshold and high threshold Activate the response graph of the class The region is divided into a background region, an uncertain region, and a foreground region. Different response intensity intervals corresponding to the background region, uncertain region, and foreground region are mapped to corresponding uncertainty measures. As the category discrimination response: ; St2, calculate the class activation response graphs respectively. Horizontal first-order difference and the first-order difference in the vertical direction Extract the first-order difference vector And calculate the magnitude of the first-order difference vector. ; for the magnitude of the first-order difference vector Normalization is performed to obtain the spatial gradient response. ; St3, for each pixel position in the class activation response map M Response values under different defect categories c Normalization is performed to obtain the corresponding category response distribution. And calculate the category distribution uncertainty metric based on the category response distribution. : ; in, For the number of defect categories, For defect category indexing, A constant to prevent abnormal logarithmic operations; St4, responding by class distinction Spatial gradient response and category distribution uncertainty measure Weighted fusion yields the final comprehensive semantic uncertainty graph. .
5. The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to claim 4, characterized in that, A two-dimensional Gaussian kernel function is applied to the comprehensive semantic uncertainty map for smoothing to obtain uncertainty scores for each region. This includes: applying a two-dimensional Gaussian kernel function to the comprehensive semantic uncertainty map for smoothing, and obtaining uncertainty scores for each region using pixel coordinates. The first one is obtained by cropping from the comprehensive semantic uncertainty graph centered on the first one. Candidate regions According to the candidate region Position of each pixel The comprehensive semantic uncertainty value at the location Calculate the corresponding regional uncertainty score : ; in, This represents a two-dimensional Gaussian kernel function.
6. The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to claim 5, characterized in that, Based on the uncertainty scores of each region, a sampling probability distribution for candidate regions is constructed. Positive / negative sample regions are then selected from the original fabric image based on this distribution and cropped to obtain a set of positive / negative samples. Finally, pseudo-labels for the positive / negative samples are constructed, including: A. Calculate the sampling probability distribution of the positive sample: ; in, This is a parameter used to adjust the smoothness of the probability distribution. For the candidate region set; B. Calculate the negative sample sampling probability distribution: ; in, To satisfy the background determination constraints The set of regions, which is the candidate region set. Subset; C. Based on the positive / negative sample sampling probability distribution, crop out local regions from the original fabric image to obtain positive / negative sample sets, and construct sample pseudo-labels based on the selected positive and negative sample sets: ; in, , These are the positive sample set and the negative sample set, respectively.
7. The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to claim 6, characterized in that, Based on the global feature representation and the local feature representation, a contrastive learning constraint is performed, including: The local feature representation is input into the MLP local mapper to obtain the local uncertainty features, and the global feature representation is input into the MLP global mapper to obtain the global semantic features. The MLP global mapper is updated using an exponential moving average. , Momentum factor For global mapper parameters, For local mapper parameters; local mapper parameters The similarity relationship between global semantic features and local uncertainty features is discriminatively constrained by introducing InfoNCE contrastive loss, and updated through backpropagation; the formula for calculating the contrastive loss is as follows: ; in, The number of positive samples obtained from the sampling. For temperature coefficient, For global semantic features, and This represents the local uncertainty characteristics of positive and negative samples.
8. The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to any one of claims 4-7, characterized in that, The dynamic Gaussian adaptive denoising module is used to adjust the high threshold using a dynamic threshold adjustment strategy based on cosine annealing attenuation. It performs dynamic adjustments; it is also used to remove high-noise-probability pixels in the segmentation detection head prediction distribution using a Gaussian mixture model-based denoising strategy.
9. The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to claim 8, characterized in that, The high threshold is adjusted using a dynamic threshold adjustment strategy based on cosine annealing decay. The method for dynamic adjustment is as follows: ; in, Indicates the current iteration number. This represents the total number of training iterations.
10. The weakly supervised fabric defect detection method based on semantic uncertainty region enhancement according to claim 8 or 9, characterized in that, Methods for removing high-noise-probability pixels from the prediction distribution of the segmentation detection head using a denoising strategy based on a Gaussian mixture model include: STEP 1: Calculate the predicted class distribution for each pixel b in the input fabric image. Pixel-level cross-entropy loss between pseudo-labels generated from the class activation response map: ; in, Represents the cross-entropy loss function. For pixels Category distribution , Pseudo-labels generated for class activation response maps ; STEP2 models the pixel-level cross-entropy loss distribution by fitting a two-component Gaussian mixture model. The loss distribution function is: ; in, Indicates a Gaussian distribution. , , These represent the percentage, mean, and variance of clean clusters, respectively. , , These represent the proportion, mean, and variance of the noise clusters, respectively. STEP3, Calculate pixels Posterior probability of belonging to noise component : ; STEP 4: Determine the separability of the loss distribution by evaluating the distance between the means of the clean Gaussian component and the noisy Gaussian component, and then... (The sentence is incomplete and requires more context to be translated accurately.) and noise determination constraints Enable noise filtering mechanism to identify and remove sets of pixels with high noise probability. : ; in, , These are the noise posterior probability threshold and the mean threshold, respectively.