An unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction

The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction solves the problems of insufficient accuracy and stability in existing fabric defect detection technologies, achieves efficient detection of small and slender defects, and enhances the continuity of abnormal response and the stability of feature representation.

CN122134716APending Publication Date: 2026-06-02ZHONGYUAN ENGINEERING COLLEGE

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ZHONGYUAN ENGINEERING COLLEGE
Filing Date
2026-04-22
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing unsupervised fabric defect detection methods have limited accuracy in detecting minute and slender linear defects against complex texture backgrounds. Their feature representation is unstable, and their abnormal responses are discrete and discontinuous, making it difficult to take into account multi-scale structural information.

Method used

By introducing distribution alignment and selective feature reconstruction mechanisms, a teacher-student network model is constructed. Combined with a residual dense scale aggregation structure, the stability and spatial continuity of feature representation are enhanced. The distribution-aware consistency constraint module is used to align the normal texture distribution, and the response difference between abnormal and normal regions is strengthened through the selective feature reconstruction module.

Benefits of technology

It significantly improves the accuracy and stability of fabric defect detection, increases the recall rate of detecting small and slender defects, and maintains the robustness of the model in complex industrial scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122134716A_ABST
    Figure CN122134716A_ABST
Patent Text Reader

Abstract

This invention proposes an unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction. The method involves acquiring and partitioning a normal sample dataset; constructing an unsupervised fabric defect detection network model, including a teacher feature extraction network, a student feature reconstruction network, and a residual dense scale aggregation head; introducing the residual dense scale aggregation head after the teacher and student feature extraction networks; introducing a selective feature reconstruction module in the student feature reconstruction network; introducing a distribution-aware consistency constraint module between the teacher and student feature extraction networks; and introducing a dense connection structure in the residual dense scale aggregation head. The trained fabric defect detection network model is used to detect fabric images in the test set to obtain fabric defect localization images. This method solves the problems of unstable feature representation of abnormal regions, discrete and discontinuous abnormal responses, and difficulty in simultaneously considering multi-scale structural information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of fabric defect detection, and more particularly to an unsupervised fabric defect detection method. Background Technology

[0002] In the textile industry, fabric quality inspection is a crucial step in ensuring product consistency and production stability. During weaving, dyeing, and finishing processes, fabrics are susceptible to defects such as warp breaks, weft breaks, skipped yarns, oil stains, pinholes, and fine cracks due to fluctuations in equipment operation, deviations in process parameters, and repetitive operational errors. These defects are typically characterized by high randomness, diverse forms, small size, or elongated linear distribution. Their grayscale variations and textures are highly similar to the background fabric, lacking clear and stable structural boundaries. Traditional manual inspection methods are not only labor-intensive and inefficient, but also easily influenced by subjective experience, making it difficult to meet the requirements for accuracy and stability in continuous, large-scale production. Therefore, utilizing machine vision technology to automate fabric defect detection has become an important development direction for quality control in the textile industry.

[0003] With the development of deep learning technology, fabric defect detection methods based on convolutional neural networks have been gradually applied. Existing methods mainly include detection and segmentation methods based on supervised learning, as well as unsupervised anomaly detection methods that have emerged in recent years. Among them, supervised methods usually rely on a large number of labeled defect samples for model training, and achieve defect localization or pixel-level segmentation by learning the discriminative features of different types of defects. Under the condition of sufficient samples, they can achieve good detection results. However, in actual industrial scenarios, defect types are diverse and occur infrequently, sample acquisition is difficult and labeling costs are high, which limits the generalization ability of supervised models when faced with novel or rare defects. To reduce the dependence on defect labeled data, unsupervised anomaly detection methods usually use normal samples as the training basis. By modeling normal texture distribution or structural features, they respond abnormally to regions that deviate from the normal distribution during the inference stage, thereby achieving defect detection, which has certain advantages in industrial applications.

[0004] However, existing unsupervised anomaly detection methods still have certain limitations against complex fabric textures. On the one hand, fabric backgrounds are characterized by strong periodicity and high local structural similarity. Minor defects often manifest only as subtle texture perturbations or local structural anomalies, and their feature distribution is highly similar to that of normal regions. For example, unsupervised anomaly detection methods based on reconstruction errors (such as those based on autoencoders or generative adversarial networks) typically reconstruct the input image and use the pixel-level difference between the original and reconstructed images as the basis for anomaly discrimination. These methods tend to learn the overall distribution of normal samples and smoothly reconstruct the input. However, because the model often has a strong generalization ability to local fine structures during reconstruction, it is easy to reconstruct minor defects along with the original image, thereby weakening the difference expression between abnormal and normal regions, leading to inconspicuous anomaly responses or false detections. On the other hand, in the process of multi-scale feature representation and fusion, if there is a lack of effective constraints on the stability of feature distribution, the anomaly response may exhibit discrete or discontinuous phenomena in space. For example, methods based on feature embedding and distance metrics (such as PatchCore and PaDiM) typically extract multi-layer features and construct a feature library. During the inference phase, they calculate the distance between the test sample features and the normal feature distribution to achieve anomaly detection. These methods rely on the concatenation or independent modeling of features at different scales. However, due to differences in semantic representation and scale distribution between different layers of features, and the lack of a unified distribution alignment and constraint mechanism, the spatial response of features is easily unstable, resulting in discrete, fragmented, or discontinuous response patterns in anomalous regions, affecting the complete segmentation of defect areas. Furthermore, in high-resolution industrial images, defect scale changes significantly; if the model cannot simultaneously consider local details and overall structural features, it will also affect detection accuracy and stability. For instance, unsupervised anomaly detection methods based on a teacher-student structure (such as STPM and Reverse Distillation) typically constrain features at different levels through distillation to characterize the multi-scale representation of normal samples and generate anomaly maps through feature differences during the inference phase. However, these methods often employ simple layer-by-layer alignment or weighted fusion strategies during feature fusion, which are insufficient for modeling the interaction between multi-scale information and make it difficult to simultaneously take into account fine-grained local texture and global structural semantics, resulting in decreased detection performance in defect scenarios with significant scale changes or complex structures.

[0005] In summary, existing fabric defect detection technologies still have limited accuracy in detecting minute and elongated linear defects under complex texture backgrounds. These methods fail to fully integrate the periodicity of fabric texture structures and the differences in multi-layer feature representation during feature modeling, easily leading to unstable abnormal responses and discontinuous region segmentation. Although existing supervised and unsupervised anomaly detection methods have made some progress in terms of detection accuracy and adaptability, they still struggle to simultaneously achieve anomaly response intensity, spatial continuity, and detection stability in application scenarios where fabric defect samples are difficult to obtain, defect types are diverse, and texture differences are subtle. Summary of the Invention

[0006] To address the technical problems of unstable feature representation in abnormal regions, discrete and discontinuous abnormal responses, and difficulty in simultaneously considering multi-scale structural information in existing technologies, this invention proposes an unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction. This invention introduces a feature distribution consistency constraint mechanism to statistically align reconstructed features with normal texture distribution, enhancing the stability of feature representation. Simultaneously, a selective feature reconstruction mechanism is introduced to reconstruct and adjust features in different spatial regions, effectively strengthening the response differences between abnormal and normal regions, suppressing the interference of normal texture on abnormal responses, and enhancing the feature contrast of abnormal regions. Furthermore, a residual dense scale aggregation structure is constructed to perform cross-scale fusion and layer-by-layer enhancement of multi-level features, improving the spatial continuity and structural integrity of abnormal responses. This invention significantly improves the accuracy of fabric defect detection while effectively maintaining the model's detection stability and robustness in complex industrial scenarios, achieving further improvement in the overall performance of fabric defect detection under unsupervised conditions.

[0007] To achieve the above objectives, the technical solution of the present invention is implemented as follows:

[0008] An unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction includes the following steps:

[0009] S1: Obtain a fabric image dataset containing only normal samples, preprocess the fabric image dataset, and divide the preprocessed dataset into a training set, a validation set, and a test set.

[0010] S2: Construct an unsupervised fabric defect detection network model; the fabric defect detection network model includes a teacher feature extraction network and a student feature reconstruction network, and a residual dense scale aggregation head is introduced after the teacher feature extraction network and the student feature reconstruction network; a selective feature reconstruction module is introduced in the student feature reconstruction network; a distribution-aware consistency constraint module is introduced between the teacher feature extraction network and the student feature reconstruction network; and a dense connection structure is introduced in the residual dense scale aggregation head;

[0011] S3: Train and validate the fabric defect detection network model using the training set and validation set to obtain the trained fabric defect detection network model;

[0012] S4: Use the trained fabric defect detection network model to detect fabric images in the test set to obtain fabric defect localization images;

[0013] Furthermore, the teacher feature extraction network is used to extract multi-scale teacher semantic feature maps from the input normal image. The teacher feature extraction network uses the second, third, and fourth stages of the four residual feature extraction stages of the ResNet-18 network structure to extract features and output the multi-scale teacher semantic feature maps. The second, third, and fourth stages output the first teacher semantic feature map, the second teacher semantic feature map, and the third teacher semantic feature map, respectively.

[0014] The student feature reconstruction network is used to extract features from the input abnormal image and reconstruct a multi-scale student decoding feature map consistent with the teacher feature extraction network. The student feature reconstruction network adopts an encoder-decoder symmetric structure. The encoder part uses the feature extraction structure of the ResNet-18 network to extract features and obtain the multi-scale student coding feature maps of the last three stages of the residual feature extraction stage, including the first student coding feature map, the second student coding feature map, and the third student coding feature map. The decoder part adopts a residual feature extraction structure symmetric with the corresponding layer of the encoder and constructs the feature reconstruction path by replacing the original downsampling operation with bilinear upsampling. The decoder outputs a multi-scale student decoding feature map with the same feature dimension as the corresponding layer of the teacher feature extraction network. The multi-scale student decoding feature map includes the first student decoding feature map, the second student decoding feature map, and the third student decoding feature map corresponding to the teacher's multi-layer semantic feature map.

[0015] Furthermore, the selective feature reconstruction module is used to adjust and enhance the response differences between abnormal and normal regions in the multi-scale student coding feature map through selective reconstruction. The selective feature reconstruction module is introduced between the encoder and decoder of the student feature reconstruction network. The selective feature reconstruction module includes a semantic bottleneck path and a texture enhancement path. The semantic bottleneck path is used to perform multi-scale feature fusion and residual semantic bottleneck processing on the multi-scale student coding feature map to construct a compact semantic embedding representation. The texture enhancement path is used to perform texture gating operation and cross-scale decoding feature fusion on the shallow coding features in the multi-scale student coding feature map to obtain texture-enhanced decoding input features.

[0016] Furthermore, in the semantic bottleneck path, multi-scale feature fusion and residual semantic bottleneck processing are performed on the multi-scale student coding feature map to construct a compact semantic embedding representation, specifically including:

[0017] The first student coding feature map, the second student coding feature map, and the third student coding feature map are respectively... After convolution and upsampling, the data is concatenated. Multi-scale fusion is performed at the channel dimension, followed by... Convolution Transformation Channel compression is performed to obtain fusion features. fusion features Compact embedding tensors are obtained through residual semantic bottleneck processing. , used as input to the decoder; the residual semantic bottleneck processing includes a first residual block and a second residual block connected in sequence.

[0018] Furthermore, in the texture enhancement path, texture gating and cross-scale decoding feature fusion are performed on the shallow coding features in the multi-scale student coding feature map to obtain texture-enhanced decoding input features, specifically including:

[0019] The first of the multi-scale student coding feature maps Each shallow-layer encoded feature map is processed sequentially. Convolutional transformation, normalization, and nonlinear transformation yield the first... Enhancement features at each scale To implement the texture gating operation, the first Enhancement features at each scale Decoding output features compared to the previous scale Perform cross-scale decoding feature fusion to obtain the first Decoding input features at each scale The shallow coding features include a first student coding feature map and a second student coding feature map.

[0020] Furthermore, the distribution-aware consistency constraint module achieves feature distribution alignment between the multi-scale student decoding feature map and the multi-scale teacher semantic feature map by applying local directional consistency constraints and global distribution consistency constraints to each scale feature map between the multi-scale teacher semantic feature map and the multi-scale student decoding feature map;

[0021] The dense connection structure is a cascaded dilated convolutional dense connection structure. The cascaded dilated convolutional dense connection structure performs multi-scale context aggregation processing on the input feature map through multiple dilated convolutional layers to obtain the aggregated dense feature representation. Each dilated convolutional layer receives the channel-level concatenation result of all previous dilated convolutional layers as input.

[0022] Furthermore, it includes: constructing the local directional consistency constraint based on the pixel-level cosine similarity between the multi-scale teacher semantic feature map and the multi-scale student decoding feature map; the method for constructing the local directional consistency constraint is as follows:

[0023] Calculate the first Spatial coordinates of teachers in semantic feature maps at various scales Teacher feature vector at the location With the Spatial coordinates of student decoding feature maps at various scales Student feature vector at location The cosine distance between them, for the first The cosine distances of all spatial locations at each scale are averaged and... The local orientation consistency loss is obtained by summing the features across k scales, where K represents the teacher's semantic feature map and the student's decoded feature map at k scales. The calculation formula is as follows:

[0024] ;

[0025] in, Describing the L2 norm, and These represent the spatial height and width of the feature map, respectively.

[0026] Furthermore, this includes: constructing the global distribution consistency constraint based on the Kullback-Leibler divergence between the teacher distribution and the student distribution; the method for constructing the global distribution consistency constraint is as follows:

[0027] For the first Individual Teacher Characteristics With the Student characteristics at various scales Global average pooling is performed along the spatial dimension to obtain channel-level description vectors of teacher features. Channel-level description vectors of student characteristics And introduce temperature parameters The probability distribution is obtained by performing Softmax normalization on the channel-level description vector:

[0028] ;

[0029] in, and They represent the first Teacher and student characteristics at each scale in the first... The normalized probability distribution corresponding to each channel;

[0030] Calculate the Kullback-Leibler divergence between the teacher distribution and the student distribution:

[0031] ;

[0032] in, Indicates the number of channels;

[0033] exist The global distribution consistency loss is obtained by weighted summation across each scale:

[0034] .

[0035] Furthermore, the residual dense scale aggregation head is used to perform multi-scale fusion of the feature difference map between the multi-scale teacher semantic feature map and the multi-scale student decoding feature map to obtain an anomaly localization map. The residual dense scale aggregation head includes:

[0036] Shallow residual adapter: Employs basic residual units to project channel features onto the feature difference map between the multi-scale teacher semantic feature map and the multi-scale student decoding feature map, resulting in a compact representation. ;

[0037] Parallel cascaded dilated convolutional dense connection structure and residual correction path: The cascaded dilated convolutional dense connection structure is used for the compact representation Multi-scale context aggregation is performed to obtain dense feature representations; a residual correction path, consisting of a linear projection mapping structure composed of 1×1 convolutions and normalization operations, is used to refine the compact representation. Perform residual projection mapping to obtain the corrected features;

[0038] A feature aggregation layer is used to aggregate the dense feature representation and the corrected features to obtain an aggregated feature representation. ;

[0039] Decoding head: used for representing the aggregated features Local refinement is performed by using a 3×3 convolution layer combined with batch normalization and a nonlinear activation function to refine the aggregated feature representation. Perform spatial context fusion;

[0040] Output layer: The multi-channel features output by the decoder head are mapped to single-channel response features through 1×1 convolution. The single-channel response features are normalized and mapped, and the response values ​​are compressed to the [0,1] interval through the Sigmoid activation function to obtain the pixel-level anomaly probability map P.

[0041] Furthermore, the fabric defect detection network model is trained and validated using training and validation sets, specifically including:

[0042] Alignment Training Phase: Normal samples from the input training set are used to generate pseudo-abnormal fabric images by randomly perturbing and replacing regions in normal fabric images, employing only the distribution-aware consistency total loss. The total loss of distribution-aware consistency is calculated through forward propagation, and the parameters of the network for reconstructing student features are adjusted through backpropagation. Validation is performed on the validation set every fixed number of rounds until the total loss of distribution-aware consistency of the training and validation sets tends to stabilize.

[0043] Fine-tuning training: Pseudo-abnormal fabric images are generated by randomly perturbing and replacing regions in normal fabric images, and corresponding abnormality masks are generated and divided into training and validation sets. Multi-loss weighted fusion loss is calculated, including Focal loss and... The loss is weighted and combined; the multi-loss weighted fusion loss is calculated by forward propagation, and the parameters of the residual dense scale aggregation head are adjusted by backpropagation. The results are validated on the validation set every fixed number of rounds until the detection accuracy of the validation set tends to stabilize.

[0044] The beneficial effects of this invention are as follows:

[0045] This invention presents an unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction. The method enhances the stability of normal fabric texture features at the global statistical distribution level through a distribution-aware consistency constraint module, aligning reconstructed features with the original feature distribution in the probability distribution space, effectively reducing the risk of anomaly response drift and misjudgment. Simultaneously, the selective feature reconstruction module enhances the information interaction capability between features at different levels by selectively reconstructing and adjusting across multi-scale feature spaces, strengthening the response discrimination between abnormal and normal regions, and improving the saliency expression of minute and elongated defects. The residual dense-scale aggregation structure, through cross-layer feature fusion and layer-by-layer enhancement mechanisms, improves the continuity and integrity of anomaly responses in the spatial dimension, solving the problems of discrete responses, incomplete boundaries, and easy missed detection in complex texture backgrounds in fabric defect detection. Experiments show that this method has a significant performance gain compared to baseline methods on standard fabric defect datasets, not only improving the detection recall rate of minute and weakly salient defects but also maintaining detection stability while considering the model's generalization ability, providing a reliable technical means for automated fabric quality inspection under unsupervised conditions. Attached Figure Description

[0046] 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.

[0047] Figure 1 This is a flowchart of the unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction of the present invention.

[0048] Figure 2 This is the defect detection network model of the present invention.

[0049] Figure 3 This is the selective feature reconstruction module of the present invention.

[0050] Figure 4 This is the residual dense scale aggregation head module of the present invention.

[0051] Figure 5 This is the visualization result of the present invention. Detailed Implementation

[0052] 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.

[0053] An unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction, such as Figure 1 As shown, the steps include:

[0054] S1: Obtain a fabric image dataset containing only normal samples, preprocess the fabric image dataset, and divide the preprocessed dataset into a training set, a validation set, and a test set.

[0055] Specifically, this invention acquired a self-built fabric defect dataset from the laboratory, including a plain weave fabric dataset and a patterned fabric dataset. The plain weave fabric dataset includes 2200 training images and 500 test images. These images contain elongated defects and micro-defects with low contrast to the textured background, and the defect types include five categories: indentations, creases, 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, broken yarn, 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 relatively large proportion of linear defects, while the patterned fabric dataset is characterized by strong texture interference, diverse defect categories, and complex morphological changes. This invention divides the dataset according to the construction principles of unsupervised anomaly detection tasks, dividing the dataset into a training set, a validation set, and a test set. The training set and validation set contain only normal fabric image samples, while the test set contains both normal fabric images and real defect images. Abnormal fabric samples are not included in the model training process.

[0056] Specifically, the method for preprocessing the dataset is as follows:

[0057] 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 original fabric images by horizontal and vertical flipping, respectively. This expands the number of samples while keeping the semantic information of defects unchanged, enriches the distribution of defects in different spatial locations and arrangement directions, thereby improving sample diversity and reducing the risk of overfitting during model training.

[0058] For the patterned fabric dataset, considering its complex background texture and diverse directional variations, data augmentation operations are performed on the original fabric images using rotational expansion at three different angles. By constructing equivalent training samples under different directions, the robustness and generalization ability of the model to complex texture directional variations and irregular defect morphologies are improved, thereby enhancing the overall fabric defect detection performance. Differentiated data augmentation allows the model to adapt to the texture characteristics of different fabrics, improving its generalization ability in industrial scenarios.

[0059] This method constructs an unsupervised fabric anomaly detection dataset that relies solely on normal sample distribution information for alignment training. The training and validation sets are used for normal texture distribution modeling, while the test set is used for anomaly detection task verification, thus forming a fabric image dataset that conforms to the construction principles of unsupervised anomaly detection tasks.

[0060] S2: Construct an unsupervised fabric defect detection network model, such as Figure 2As shown, the fabric defect detection network model includes a parallel teacher feature extraction network and a student feature reconstruction network. The teacher feature extraction network extracts multi-scale teacher semantic feature maps from the input normal image, and the student feature reconstruction network extracts features from the input abnormal image and reconstructs a multi-scale student decoding feature map consistent with the teacher feature extraction network. A residual dense scale aggregation head is included after the teacher feature extraction network and the student feature reconstruction network to perform multi-scale fusion of the feature difference maps between the multi-scale teacher semantic feature maps and the multi-scale student decoding feature maps to obtain an anomaly localization map. A selective feature reconstruction module is introduced in the student feature reconstruction network to adjust and strengthen the response difference between abnormal and normal regions in the multi-scale student coding feature map through selective reconstruction. A distribution-aware consistency constraint module is introduced between the teacher feature extraction network and the student feature reconstruction network to constrain the feature distribution alignment of the multi-scale student coding feature map to the multi-scale teacher semantic feature map. A dense connection structure is introduced in the residual dense scale aggregation head to fully fuse abnormal features.

[0061] Specifically, the feature extraction structure of the ResNet-18 network includes an initial convolutional layer, a max pooling layer, and four residual feature extraction stages connected in sequence. The four residual feature extraction stages are conv1_x, conv2_x, conv3_x, and conv4_x, respectively. The teacher feature extraction network of this invention selects the output features of three stages—conv2_x, conv3_x, and conv4_x—from the four residual feature extraction stages as multi-layer semantic feature representations, namely the multi-scale teacher semantic feature map. The multi-scale teacher semantic feature map includes a first teacher semantic feature map, a second teacher semantic feature map, and a third teacher semantic feature map, which correspond to the outputs of the three stages—conv2_x, conv3_x, and conv4_x, respectively.

[0062] Specifically, the student feature reconstruction network adopts an encoder-decoder symmetric structure. The encoder part uses a ResNet-18 feature extraction structure to extract features, obtaining multi-scale student coding feature maps output from the three stages after the residual feature extraction stage, including a first student coding feature map, a second student coding feature map, and a third student coding feature map. The decoder part adopts a residual feature extraction structure symmetric to the corresponding layer of the encoder, and constructs a feature reconstruction path by replacing downsampling with bilinear upsampling. The student feature reconstruction network establishes a feature mapping relationship between the corresponding layers of the encoder and decoder. Finally, the decoder outputs multi-scale student decoding feature maps with the same feature dimensions as the corresponding layer of the teacher feature extraction network, denoted as the first student decoding feature map, the second student decoding feature map, and the third student decoding feature map, which are used for layer-by-layer distribution alignment calculation with the multi-scale teacher semantic feature map output by the teacher feature extraction network.

[0063] It should be noted that the ResNet-18 network structure has four residual feature extraction stages. The teacher feature extraction network of this invention only uses the last three stages for feature extraction, while the student feature reconstruction network uses the complete initial convolutional layer, max pooling layer, and four stages for feature extraction. However, the student encoder only outputs the outputs of the last three stages, which are then used for computation with the selective feature reconstruction module. The student decoder uses the complete four stages for feature decoding, but only outputs the outputs of the last three stages. The last three stages of the student encoder refer to the conv2_x stage, the conv3_x stage, and the co In the nv4_x stage, due to its symmetric structure, the last three stages of the student decoder refer to the conv3_x, conv2_x, and conv1_x stages of the ResNet-18 network, corresponding to the third, second, and first student decoder feature maps, respectively. The teacher feature extraction network only uses three stages to extract features, obtaining the first, second, and third teacher semantic feature maps. Therefore, these maps have the same scale as the first, second, and third student decoder feature maps and can be used for subsequent distribution-aware consistency calculations.

[0064] Specifically, a selective feature reconstruction module is introduced between the encoder and decoder of the student feature reconstruction network, such as... Figure 3As shown, the selective feature reconstruction module includes a semantic bottleneck path and a texture enhancement path. The semantic bottleneck path is used to perform multi-scale feature fusion and residual semantic bottleneck processing on the multi-scale student coding feature map to construct a compact semantic embedding representation. The texture enhancement path is used to perform texture gating operations and cross-scale decoding feature fusion on the shallow coding features in the multi-scale student coding feature map to obtain texture-enhanced decoding input features. The selective feature reconstruction module restricts the degree of freedom of feature reconstruction under the constraint of distribution-aware consistency: the semantic bottleneck path anchors the core semantics of normal regions to ensure stable reconstruction; the texture enhancement path supplements high-frequency details, allowing abnormal regions to retain feature differences, thereby achieving stable anchoring of normal texture structures and selective reconstruction of fine-grained abnormal regions.

[0065] In the semantic bottleneck path, the process of performing multi-scale feature fusion and residual semantic bottleneck processing on the multi-scale student coding feature map to construct a compact semantic embedding representation specifically includes:

[0066] First, the semantic bottleneck path affects the first, second, and third student coding feature maps output by the student encoder. Perform separately After convolution and upsampling, the data is concatenated. Multi-scale fusion is performed at the channel dimension, followed by... Convolution Transformation Channel compression is performed to obtain fusion features. Since each layer of the encoder and decoder corresponds to each scale of the feature map, in this invention, the features of each layer and the features of each scale can be considered as a consistent representation.

[0067] ;

[0068] in, Indicates the student encoder's first... Layer output features, express Convolution transformation, This indicates an upsampling operation.

[0069] Furthermore, fusion features Compact embedding tensors are obtained after residual semantic bottleneck processing. , used as input for subsequent decoders; the residual semantic bottleneck processing includes a first residual block and a second residual block connected in sequence.

[0070] In the texture enhancement path, texture gating and cross-scale decoding feature fusion are performed on the shallow encoded features in the multi-scale student encoded feature map to obtain texture-enhanced decoding input features, specifically including:

[0071] The texture enhancement path encodes shallow features of the student encoder output. conduct Enhanced features are obtained through convolutional transformation, normalization, and nonlinear transformation. (i.e., texture gating operation), and the decoding input features of the previous layer. via decoding block The obtained decoded output features Perform cross-scale decoding feature fusion to obtain the first Layer decoding input features The shallow coding features include a first student coding feature map and a second student coding feature map.

[0072] The calculation formula is:

[0073] ;

[0074] ;

[0075] express Convolutional transformation, BN represents batch normalization, and ReLU represents a non-linear activation function.

[0076] Through the above dual-path structure, the dual goals of semantic stability and detail supplementation are achieved. The main semantics of the normal region are anchored by the semantic bottleneck path to ensure reconstruction stability. The high-frequency details of the abnormal region are preserved by the texture enhancement path to strengthen feature differences and greatly improve the response distinction between defects and normal regions. This solves the problem of missing fine-grained defects and enables the model to form a selective response bias to abnormal regions while maintaining the stable expression of normal textures, thus achieving adaptive reconstruction of abnormal structures.

[0077] Specifically, the distribution-aware consistency constraint module applies local directional consistency constraints and global distribution consistency constraints to the feature maps at each scale between the multi-scale teacher semantic feature map and the multi-scale student decoding feature map. This achieves feature distribution alignment between the constrained multi-scale student decoding feature map and the multi-scale teacher semantic feature map. These dual constraints enable the student feature reconstruction network to accurately learn the standard normal texture features of the teacher feature extraction network at both the pixel level and the global statistical level, ensuring the stability of normal feature representation from the root.

[0078] Local directional consistency constraint: The distribution-aware consistency constraint module constructs local directional consistency constraints based on the pixel-level cosine similarity between teacher features (i.e., multi-scale teacher semantic feature map) and student features (i.e., multi-scale student decoding feature map).

[0079] The method for constructing local directional consistency constraints is as follows:

[0080] For the Spatial coordinates of teachers in semantic feature maps at various scales Teacher feature vector at the location With the Student feature vectors in the student decoding feature map at various scales Calculate the cosine distance for the th The cosine distances of all spatial locations at each scale are averaged and... The local orientation consistency loss is obtained by summing the values ​​at each scale (feature level), and the calculation formula is as follows:

[0081] ;

[0082] in, Describing the L2 norm, and These represent the spatial height and width of the feature map, respectively. This constraint, through a directional consistency measure, ensures that the student feature reconstruction network is spatially aligned with the semantic direction of the teacher feature extraction network features.

[0083] Global distribution consistency constraint: The distribution-aware consistency constraint module constructs global distribution consistency constraints based on the Kullback-Leibler divergence between the teacher distribution and the student distribution.

[0084] The method for constructing globally distributed consistency constraints is as follows:

[0085] First, regarding the first Characteristics of teachers at different levels With the Student characteristics Global average pooling is performed along the spatial dimension to obtain channel-level description vectors of teacher features. Channel-level description vectors of student characteristics And introduce temperature parameters The probability distribution is obtained by performing Softmax normalization on the channel-level description vector:

[0086] ;

[0087] Furthermore, the Kullback-Leibler divergence between the teacher distribution and the student distribution is calculated:

[0088] ;

[0089] in, Indicates the number of channels. and Indicates the first The first scale of teacher characteristics and student characteristics The normalized probability values ​​corresponding to each channel.

[0090] Furthermore, in The global distribution consistency loss is obtained by weighted summation at each scale (feature level):

[0091] ;

[0092] Through the aforementioned dual local and global consistency constraints, the student feature reconstruction network can fully learn the semantic distribution features of normal textures under defect-free sample training conditions.

[0093] Specifically, such as Figure 4 As shown, the residual dense-scale aggregation head includes:

[0094] The shallow residual adapter, a convolutional residual structure composed of basic residual units, is used to project channel features onto the feature difference maps obtained from the difference mapping between the teacher feature extraction network and the student feature reconstruction network, resulting in a compact representation. ;

[0095] Parallel cascaded dilated convolutional dense connection structures and residual correction paths; the cascaded dilated convolutional dense connection structures are used for the compact representation. Multi-scale context aggregation is performed to obtain dense feature representations; the residual correction path is a linear projection mapping structure consisting of 1×1 convolutions and normalization operations, used to refine the compact representation. Perform residual projection mapping to obtain the corrected features;

[0096] In a cascaded dilated convolutional dense connection structure, the compact representation... Perform multi-scale context aggregation to obtain dense feature representations, specifically including:

[0097] Through multiple hollow convolutional layers For the compact representation Processing is performed on each dilated convolutional layer. The channel-level concatenation results of all preceding dilated convolutional layers are received as input to obtain the final aggregated dense feature representation.

[0098] A feature aggregation layer is used to aggregate the dense feature representation and the corrected features to obtain an aggregated feature representation. To enhance multi-scale contextual continuity and maintain the topological integrity of fine-grained structural responses.

[0099] The calculation formulas for the parallel cascaded dilated convolutional dense connection structure, residual correction path, and feature aggregation layer are as follows:

[0100] ;

[0101] in, This represents the residual correction mapping function, used to directly map compact feature representations to the aggregate feature space. Indicates the first The output of a dilated convolutional layer is denoted as [channel concatenation]. Densely connected structures are denoted as .

[0102] Cascaded dilated convolution expands the perceptual range of features without increasing computational cost, achieving full coverage of multi-scale defect features and adapting to various defects ranging from pinholes to large areas of oil stains. Dense connections allow for full feature fusion, avoiding feature loss of minute defects. The residual correction path achieves dense fusion and feature filling, ensuring the topological integrity and boundary clarity of defect regions. It solves the core problems of discrete anomaly responses and discontinuous defect segmentation, enhances the flow of contextual information between scales, and thus improves the structural integrity and boundary clarity of the anomaly localization map.

[0103] Decoding head; used for representing the aggregated features Local refinement is performed by using a 3×3 convolution layer combined with batch normalization and a nonlinear activation function to refine the aggregated feature representation. Perform spatial context fusion to refine boundaries and local structures;

[0104] Output layer: The multi-channel features output by the decoder head are mapped to single-channel response features through 1×1 convolution. The single-channel response features are normalized and mapped. The response values ​​are compressed to the [0,1] interval through the Sigmoid activation function to obtain the pixel-level anomaly probability map P.

[0105] Through the synergistic effect of the aforementioned distribution-aware consistency constraint mechanism, selective feature reconstruction strategy, and residual dense scale aggregation structure, an unsupervised fabric defect detection network model trained solely on normal samples is constructed, providing a stable feature representation basis for subsequent accurate localization of abnormal regions.

[0106] S3: Use the training set and validation set to train and validate the fabric defect detection network model to obtain the trained fabric defect detection network model.

[0107] The training process is as follows:

[0108] During the alignment training phase, the goal is to optimize only the student feature reconstruction network, learn the normal feature distribution of the teacher network under unsupervised conditions, and achieve multi-scale feature alignment.

[0109] Normal samples from the input training set are used to generate pseudo-abnormal fabric images by randomly perturbing and replacing regions in normal fabric images, employing only distribution-aware consistency loss. The distribution-aware consistency loss is calculated through forward propagation, and the parameters of the network are reconstructed by updating student features through backpropagation. The network is evaluated on a validation set at fixed intervals. The convergence stability is maintained until convergence during the alignment phase.

[0110] In the fine-tuning phase, the goal is to optimize only the residual dense-scale aggregation head while freezing the parameters of the teacher feature extraction network and the student feature reconstruction network. This will enhance the ability to locate abnormal regions by utilizing pseudo-anomaly supervision, thereby improving the accuracy of defect detection.

[0111] Pseudo-abnormal fabric images are generated by randomly perturbing and replacing regions in normal fabric images, and corresponding anomalous masks are generated. These pseudo-abnormality masks are then used for supervision. A weighted fusion loss is employed. The parameters of the residual dense-scale aggregation head are updated by backpropagation, and the validation is performed on the validation set at fixed intervals until the monitoring and detection indicators on the validation set are stable.

[0112] In this embodiment, all experiments were conducted on a server running the Ubuntu operating system. The hardware configuration included a single NVIDIA GPU and the PyTorch deep learning framework. The training process consisted of two phases: alignment and fine-tuning. The total number of training iterations was set to 8,000, and the batch size was set to 32. The optimizer used was SGD with momentum, a momentum factor of 0.9, and weight decay. This embodiment employed a hierarchical learning rate strategy: the learning rate for the student feature reconstruction network decoder was set to 0.4, the learning rate for the residual layer was set to 0.1, and the learning rate for the residual dense scale aggregation head was set to 0.007. The loss function involved in the training process consisted of distribution-aware consistency loss. Focal loss and The loss composition, in which the alignment stage adopts For unsupervised alignment, the supervised loss during the fine-tuning phase is the Focal loss and Weighted sum of losses This is the weighting coefficient with a value of 0.25. Additionally, preset hyperparameters... Set to 6, temperature coefficient The KL divergence weight is 0.7. It is 0.12.

[0113] S4: Use the trained fabric defect detection network model to detect fabric images in the test set to obtain fabric defect localization images.

[0114] Simulation verification:

[0115] (1) Ablation experiment:

[0116] 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 ablation experiments employed the following combination of methods for comparative verification: Baseline using the DeSTSeg framework; Baseline+DAC-Loss adding a distribution-aware consistency constraint module to the Baseline; Baseline+SFRM adding a selective feature reconstruction module to the Baseline; Baseline+RDSA-Head adding a residual dense scale aggregation head module to the Baseline; and Baseline+DAC-Loss+SFRM+RDSA-Head representing the proposed method, simultaneously applying all three modules.

[0117] The effectiveness of the algorithm improvement proposed in this invention was verified through ablation experiments. The experimental results are shown in Table 1. The weighted F-value is the weighted harmonic mean of precision and recall. Table 1 shows that the detection performance is improved to varying degrees after introducing different functional modules based on the baseline model. First, the introduction of the Distribution-Aware Consistency Constraint (DAC-Loss) module significantly improves the model's performance compared to the baseline, indicating that this module effectively enhances the distribution-level consistency constraint in pixel-level anomaly localization, thereby improving fine-grained localization accuracy. Furthermore, the introduction of the Selective Feature Reconstruction (SFRM) module and the Residual Dense Scale Aggregation Head (RDSA-Head) module further improves both metrics on the dataset, demonstrating that the proposed modules effectively optimize fine-grained localization and segmentation boundary accuracy of anomaly regions. The comprehensive experimental results show that the DAC-Loss module, SFRM module, and Residual Dense Scale Aggregation Head module have good complementarity in unsupervised fabric defect detection tasks, synergistically improving the overall detection performance of the model, thus verifying the effectiveness and rationality of the improved scheme of this invention.

[0118] Table 1 Ablation Experiment Results

[0119]

[0120] (2) Visualization results analysis:

[0121] like Figure 5The visualization results shown are illustrated for plain weave fabric datasets and patterned fabric datasets using the method of this invention. The results demonstrate that the method of this invention can effectively suppress redundant responses in normal areas under complex texture backgrounds, resulting in a more concentrated and significantly brighter distribution of abnormal areas in the response map. Overall, the background noise is low, the boundaries are clear, and the structure is intact. Furthermore, for low-contrast, fine-grained, and small-area abnormal targets, it maintains good response continuity and localization accuracy, without obvious breaks or missed detections. These visualization results further verify the stability and effectiveness of the method of this invention in unsupervised fabric defect detection tasks.

[0122] 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. An unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction, characterized in that, The steps include: S1: Obtain a fabric image dataset containing only normal samples, preprocess the fabric image dataset, and divide the preprocessed dataset into a training set, a validation set, and a test set. S2: Construct an unsupervised fabric defect detection network model; the fabric defect detection network model includes a teacher feature extraction network and a student feature reconstruction network, and a residual dense scale aggregation head is introduced after the teacher feature extraction network and the student feature reconstruction network; a selective feature reconstruction module is introduced in the student feature reconstruction network; a distribution-aware consistency constraint module is introduced between the teacher feature extraction network and the student feature reconstruction network; and a dense connection structure is introduced in the residual dense scale aggregation head; S3: Train and validate the fabric defect detection network model using the training set and validation set to obtain the trained fabric defect detection network model; S4: Use the trained fabric defect detection network model to detect fabric images in the test set to obtain fabric defect localization images.

2. The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction according to claim 1, characterized in that, The teacher feature extraction network is used to extract multi-scale teacher semantic feature maps from the input normal image. The teacher feature extraction network uses the second, third and fourth stages of the four residual feature extraction stages of the ResNet-18 network structure to extract features and output the multi-scale teacher semantic feature maps. The second, third and fourth stages output the first teacher semantic feature map, the second teacher semantic feature map and the third teacher semantic feature map, respectively. The student feature reconstruction network is used to extract features from the input abnormal image and reconstruct a multi-scale student decoding feature map consistent with the teacher feature extraction network. The student feature reconstruction network adopts an encoder-decoder symmetric structure. The encoder part uses a feature extraction structure of ResNet-18 network to extract features and obtains multi-scale student coding feature maps output from the last three stages of the residual feature extraction stage, including a first student coding feature map, a second student coding feature map, and a third student coding feature map. The decoder part adopts a residual feature extraction structure symmetric with the corresponding layer of the encoder and constructs a feature reconstruction path by replacing the original downsampling operation with bilinear upsampling. The decoder outputs a multi-scale student decoding feature map consistent with the feature dimension of the corresponding layer of the teacher feature extraction network, including a first student decoding feature map, a second student decoding feature map, and a third student decoding feature map corresponding to the first teacher semantic feature map, the second teacher semantic feature map, and the third teacher semantic feature map, respectively.

3. The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction according to claim 2, characterized in that, The selective feature reconstruction module is used to adjust and enhance the response difference between abnormal and normal regions in the multi-scale student coding feature map through selective reconstruction. The selective feature reconstruction module is introduced between the encoder and decoder of the student feature reconstruction network. The selective feature reconstruction module includes a semantic bottleneck path and a texture enhancement path. The semantic bottleneck path is used to perform multi-scale feature fusion and residual semantic bottleneck processing on the multi-scale student coding feature map to construct a compact semantic embedding representation. The texture enhancement path is used to perform texture gating operations and cross-scale decoding feature fusion on the shallow coding features in the multi-scale student coding feature map to obtain texture-enhanced decoding input features.

4. The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction according to claim 3, characterized in that, In the semantic bottleneck path, multi-scale feature fusion and residual semantic bottleneck processing are performed on the multi-scale student coding feature map to construct a compact semantic embedding representation, specifically including: The first student coding feature map, the second student coding feature map, and the third student coding feature map are respectively... After convolution and upsampling, the data is concatenated. Multi-scale fusion is performed at the channel dimension, followed by... Convolution Transformation Channel compression is performed to obtain fusion features. fusion features Compact embedding tensors are obtained through residual semantic bottleneck processing. , used as input to the decoder; the residual semantic bottleneck processing includes a first residual block and a second residual block connected in sequence.

5. The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction according to claim 3 or 4, characterized in that, In the texture enhancement path, texture gating and cross-scale decoding feature fusion are performed on the shallow encoded features in the multi-scale student encoded feature map to obtain texture-enhanced decoding input features, specifically including: The first of the multi-scale student coding feature maps Each shallow-layer encoded feature map is processed sequentially. Convolutional transformation, normalization, and nonlinear transformation yield the first... Enhancement features at each scale To implement the texture gating operation, the first Enhancement features at each scale Decoding output features compared to the previous scale Perform cross-scale decoding feature fusion. For the decoding operation, the first... Decoding input features at each scale The shallow coding features include a first student coding feature map and a second student coding feature map.

6. The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction according to any one of claims 1-4, characterized in that, The distribution-aware consistency constraint module achieves feature distribution alignment between the multi-scale student decoding feature map and the multi-scale teacher semantic feature map by applying local directional consistency constraints and global distribution consistency constraints to each scale feature map between the multi-scale teacher semantic feature map and the multi-scale student decoding feature map. The dense connection structure is a cascaded dilated convolutional dense connection structure. The cascaded dilated convolutional dense connection structure performs multi-scale context aggregation processing on the input feature map through multiple dilated convolutional layers to obtain the aggregated dense feature representation. Each dilated convolutional layer receives the channel-level concatenation result of all previous dilated convolutional layers as input.

7. The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction according to claim 6, characterized in that, include: The local directional consistency constraint is constructed based on the pixel-level cosine similarity between the multi-scale teacher semantic feature map and the multi-scale student decoding feature map. The method for constructing the local directional consistency constraint is as follows: Calculate the first Spatial coordinates of teachers in semantic feature maps at various scales Teacher feature vector at the location With the Spatial coordinates of student decoding feature maps at various scales Student feature vector at location The cosine distance between them, for the first The cosine distances of all spatial locations at each scale are averaged and... The local orientation consistency loss is obtained by summing the features across k scales, where K represents the teacher's semantic feature map and the student's decoded feature map at k scales. The calculation formula is as follows: ; in, Describing the L2 norm, and They represent The spatial height and width of the feature map at each scale.

8. The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction according to claim 7, characterized in that, include: The global distribution consistency constraint is constructed based on the Kullback-Leibler divergence between the teacher distribution and the student distribution. The method for constructing the global distribution consistency constraint is as follows: For the first Individual Teacher Characteristics With the Student characteristics at various scales Global average pooling is performed along the spatial dimension to obtain channel-level description vectors of teacher features. Channel-level description vectors of student characteristics And introduce temperature parameters The probability distribution is obtained by performing Softmax normalization on the channel-level description vector: ; in, and They represent the first Teacher and student characteristics at each scale in the first... The normalized probability distribution corresponding to each channel; Calculate the Kullback-Leibler divergence between the teacher distribution and the student distribution: ; in, Indicates the number of channels; exist The global distribution consistency loss is obtained by weighted summation across each scale: 。 9. The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction according to any one of claims 2-4, 7 or 8, characterized in that, The residual dense scale aggregation head is used to perform multi-scale fusion of the feature difference map between the multi-scale teacher semantic feature map and the multi-scale student decoding feature map to obtain an anomaly localization map. The residual dense scale aggregation head includes: Shallow residual adapter: Employs basic residual units to project channel features onto the feature difference map between the multi-scale teacher semantic feature map and the multi-scale student decoding feature map, resulting in a compact representation. ; Parallel cascaded dilated convolutional dense connection structure and residual correction path: The cascaded dilated convolutional dense connection structure is used for the compact representation Multi-scale context aggregation is performed to obtain dense feature representations; a residual correction path, consisting of a linear projection mapping structure composed of 1×1 convolutions and normalization operations, is used to refine the compact representation. Perform residual projection mapping to obtain the corrected features; A feature aggregation layer is used to aggregate the dense feature representation and the corrected features to obtain an aggregated feature representation. ; Decoding head: used for representing the aggregated features Local refinement is performed by using a 3×3 convolution layer combined with batch normalization and a nonlinear activation function to refine the aggregated feature representation. Perform spatial context fusion; Output layer: The multi-channel features output by the decoder head are mapped to single-channel response features through 1×1 convolution. The single-channel response features are normalized and mapped, and the response values ​​are compressed to the [0,1] interval through the Sigmoid activation function to obtain the pixel-level anomaly probability map P.

10. The unsupervised fabric defect detection method based on distribution alignment and selective feature reconstruction according to claim 9, characterized in that, The fabric defect detection network model is trained and validated using a training set and a validation set, specifically including: Alignment Training Phase: Normal samples from the input training set are used to generate pseudo-abnormal fabric images by randomly perturbing and replacing regions in normal fabric images, employing only the distribution-aware consistency total loss. The total loss of distribution-aware consistency is calculated through forward propagation, and the parameters of the network for reconstructing student features are adjusted through backpropagation. Validation is performed on the validation set every fixed number of rounds until the total loss of distribution-aware consistency of the training and validation sets tends to stabilize. Fine-tuning training: Pseudo-abnormal fabric images are generated by randomly perturbing and replacing regions in normal fabric images, and corresponding abnormality masks are generated and divided into training and validation sets. Multi-loss weighted fusion loss is calculated, including Focal loss and... The loss is weighted and combined; the multi-loss weighted fusion loss is calculated by forward propagation, and the parameters of the residual dense scale aggregation head are adjusted by backpropagation. The results are validated on the validation set every fixed number of rounds until the detection accuracy of the validation set tends to stabilize.