Fabric defect detection method based on graph anomaly monitoring
By dividing the fabric image into grid windows and building an image node diagram, using the graph automatic encoder to identify abnormal nodes, the dependence problem on a large number of defect image samples in the prior art is solved, and efficient defect detection in complex texture scenarios is achieved.
Patent Information
- Application Number
- CN202510318803.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-18
- Publication Date
- 2025-07-04
AI Technical Summary
The dependence of the prior art on a large number of defective fabric image samples in fabric defect detection leads to difficulty in deployment, and the detection effect is poor in complex texture scenarios, especially traditional image processing methods are difficult to obtain general templates, and machine learning methods are inefficient when there is a lack of samples.
Using the fabric defect detection method based on graph abnormality monitoring, the fabric image is divided into grid windows, the image node diagram is constructed and the abnormal node recognition is used to use the graph automatic encoder to achieve high accuracy detection of defects.
High accuracy detection is achieved in the case of a small number of defective fabric images, reducing dependence on training data, improving the adaptability of complex textured fabrics, and improving production efficiency and product quality.
Smart Images

Figure CN120259216A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image recognition, and particularly relates to a fabric defect detection method based on graph anomaly monitoring. It is applicable to fabric quality inspection and real-time defect location in textile industrial production. Since there is no need to use fabric sample images with defects during the model training process, it is particularly applicable to fabric scenarios where it is difficult to obtain a large number of fabric images with defects or where it is difficult to use template matching algorithms for defect detection due to complex textures. Background Art
[0002] In modern textile industry, fabric defect detection has always been one of the key issues in development. The existence of defects will affect the aesthetics and quality of fabrics. Early detection and treatment of defects are crucial for textile production.
[0003] Fabric defect detection is an important part of quality control in the textile industry. Manual detection methods rely on human eyes to observe and judge whether there are defects on the fabric surface. This method is simple to operate, but has problems such as low detection efficiency, low accuracy, and high cost. Especially when dealing with large-scale high-speed production tasks, its deficiencies are particularly obvious. A fabric inspection machine is a machine device used to detect fabric defects. It is mainly applied in textile production lines to check fabric surface defects such as holes, poor stitching, etc., to ensure the quality of textiles. The fabric inspection machine adopts high-speed photography and image processing technologies, and can quickly and accurately identify defects on fabrics, replacing the traditional manual detection method, greatly improving the detection efficiency and accuracy. At the same time, through the fabric inspection machine, for fabrics with complex fabric structures or delicate textures, it can be better detected and judged, effectively avoiding problems such as missed detection and misjudgment. The fabric inspection machine is one of the important devices in modern textile production, and is of great significance for ensuring textile quality, improving production efficiency, and reducing costs.
[0004] Most of the existing technologies are based on traditional image processing or machine learning methods, and have a strong dependence on fixed templates and large datasets of fabric images with defects. The method based on traditional image processing usually relies on template matching algorithms and requires collecting normal defect sample images as templates in advance. However, in the fabric scenario with textures, it is difficult to obtain a general template due to the continuous change of the relative position of textures in the collected images, resulting in poor detection effects. For example, Patent 1 with the publication number CN103604809B detects and classifies fabric defects by comparing real-time collected fabric images with defect-free primitive (template) images. The method based on machine learning extracts features from static images and then discriminates defects. This method requires collecting a large number of normal and defective fabric image samples in advance to construct a dataset and perform training and matching on this basis. However, in actual application scenarios, it is often impossible to obtain a large number of fabric image samples with defects, which makes it difficult to deploy these machine learning-based methods. For example, Patent 2 with the publication number CN117152484B detects fabric defects based on an improved YOLOv5s model and requires constructing a fabric image dataset containing a large number of normal sample images and defective sample images in advance, which increases the deployment cost and difficulty. Similarly, Patents 3 to 6 with the publication numbers CN113807434B, CN114240885B, CN113433137B, and CN109685766B also require collecting normal sample images and defective sample images in advance to construct a monitoring model. An exception is Patent 7 with the publication number CN114723705B, which divides the fabric image into multiple windows and judges the similarity between each window and its neighboring window or the window corresponding periodically in the case of textures. Windows with lower similarity will be determined as defective windows. The method proposed in Patent 7 does not require prior training, but its representation learning ability based on similarity calculation is weak, and misjudgment may easily occur in complex texture scenarios. No effective solution has been proposed for the above technical problems. Summary of the Invention
[0005] An embodiment of the present invention provides a fabric defect detection method based on graph anomaly monitoring. This method can achieve high-accuracy fabric defect detection with only a small number of fabric images with defects, reducing the dependence on training data and improving the adaptability to fabrics with complex textures. This method can reduce the defective product rate, improve production efficiency and product quality, and bring economic benefits to textile enterprises.
[0006] The present invention achieves this purpose through the following technical solutions:
[0007] A fabric defect detection method based on graph anomaly monitoring includes the following steps:
[0008] Obtain fabric image data on at least one fabric inspection machine and perform preprocessing to obtain the preprocessed fabric image data;
[0009] Input the preprocessed fabric image data into a fabric defect detection model to obtain the defect detection result of the fabric image output by the fabric defect detection model, where the defect detection result includes the fabric physical position information corresponding to the defect;
[0010] The fabric defect detection model includes an image grid division module, a pre-trained image feature extraction module, an adjacency matrix construction module, a graph construction module, a graph autoencoder module, an inner product decoder module, and an abnormal node recognition module; the image grid division module divides the fabric image into multiple grid windows, and each grid window corresponds to a grid image; the pre-trained image feature extraction module is used to extract features from each grid image to generate corresponding grid image feature vectors; the adjacency matrix construction module calculates the spatial adjacency relationship and the feature similarity adjacency relationship between the grid windows respectively, and the two are weighted and fused to obtain an adjacency matrix; the graph construction module takes each grid window as a node in the graph, and establishes an edge between every two nodes to form a grid image node graph, where the grid image feature vector is used as the feature vector of the node, and the adjacency matrix is used as the weight of the edge; the graph autoencoder module maps the grid image node graph to a low-dimensional latent representation; the inner product decoder module reconstructs the adjacency matrix according to the low-dimensional latent representation to obtain a reconstructed adjacency matrix; the abnormal node recognition module calculates the reconstruction error of the row vector of the adjacency matrix corresponding to each node according to the adjacency matrix and the reconstructed adjacency matrix, and determines the node with a larger reconstruction error as an abnormal node. For the grid window corresponding to the abnormal node, obtain its corresponding fabric physical position information according to the counter.
[0011] Furthermore, the fabric defect detection model is obtained by the following steps:
[0012] S1: Construct a fabric image dataset, preprocess the fabric image data and divide it into a training set, a validation set and a test set;
[0013] S2: Input the fabric image data into the image grid division module to obtain multiple grid images;
[0014] S3: Input each grid image into the pre-trained image feature extraction module respectively to obtain grid image feature vectors;
[0015] S4: Input the grid image feature vectors and the grid window spatial position information corresponding to the grid images into the adjacency matrix construction module to obtain an adjacency matrix;
[0016] S5: Input the grid image feature vector and its adjacency matrix into the graph construction module to obtain the grid image node graph;
[0017] S6: Input the grid image node graph into the graph autoencoder module to obtain the low-dimensional latent representation;
[0018] S7: Input the low-dimensional latent representation into the inner product decoder module to obtain the reconstructed adjacency matrix;
[0019] S8: Calculate the loss based on the adjacency matrix and the reconstructed adjacency matrix, perform gradient backpropagation, and update the model parameters;
[0020] S9: Repeat steps S2 to S8, iteratively train until the model converges, and the training phase ends;
[0021] S10: Use the validation set to select the optimal hyperparameters and the anomaly node determination threshold for the model, and use the test set to evaluate the generalization performance of the model.
[0022] Further, in step S1, the system uses a camera fixedly installed on the fabric inspection machine to perform real-time image acquisition on the surface of the continuously moving fabric, obtaining a series of fabric image frames;
[0023] Specifically, the image collected by the camera is an RGB image with a resolution of H×W. First, perform grayscale preprocessing to convert it into a single-channel grayscale image, and then perform Gaussian filtering preprocessing with a kernel size of 3×3 to reduce the interference of noise on subsequent feature extraction, obtaining the preprocessed fabric image
[0024] Specifically, all preprocessed fabric images are divided into a training set, a validation set, and a test set according to a certain ratio. Among them, the training set only includes fabric images without defects, and both the validation set and the test set contain a large number of fabric images without defects and a small number of fabric images with defects;
[0025] Further, in step S2, the fabric image is divided into grid windows of the same size, and the size of each grid window is p×q pixels. The final number of grid windows The two-dimensional coordinate center of each grid window is denoted as (x i , y i ), and the corresponding grid image is denoted as M i , where i = 1, 2,..., N;
[0026] Further, in step S3, the pre-trained image feature extraction module can be expressed as:
[0027]
[0028] Among them, θ represents the parameters of the pre-trained network, and d is the output feature dimension. The pre-trained image feature extraction module is used to convert the grid image M corresponding to each grid window i into a d-dimensional feature vector:
[0029]
[0030] Combining the feature vectors of N grid images, we get:
[0031]
[0032] Furthermore, in the step S4, the adjacency matrix construction module simultaneously considers the spatial adjacency relationship and the feature similarity adjacency relationship between grid windows;
[0033] Specifically, when grid windows are adjacent to each other or close in the image plane, there should be an edge connection in the graph to reflect their potential texture continuity or spatial correlation. Therefore, the spatial adjacency relationship matrix can be constructed according to the distance between the centers of grid windows or the eight-neighborhood relationship of grid windows The value of each element is:
[0034]
[0035] where neighbor i represents the set of grid windows that have a spatial adjacency relationship with grid window i, indicates that grid window i and grid window j are adjacent in space, then indicates that grid window i and grid window j are not adjacent in space.
[0036] Specifically, to enhance the ability to capture similar textures and gray-scale distributions, the similarity of the grid image feature vectors of different grid windows is calculated to obtain the feature similarity adjacency matrix The value of each element is:
[0037]
[0038] where S(x i , x j ) represents the similarity calculation of the grid image feature vectors x i and x j , and the cosine distance similarity can be used:
[0039]
[0040] or the Euclidean distance similarity:
[0041]
[0042] Among them, σ is the characteristic scale hyperparameter.
[0043] Specifically, the spatial adjacency matrix A (space) and the feature similarity adjacency matrix A (feat) are weighted and fused to obtain the adjacency matrix
[0044] A = αA (space) + (1 - α)A (feat)
[0045] where α ∈ [0, 1] is the fusion weight hyperparameter.
[0046] Furthermore, in the step S5, the grid image feature vector X and the adjacency matrix A are input into the graph construction module to obtain the grid image node graph where is the node set, x i serves as the feature vector of node i, ε is the set of edges of the graph, and the adjacency matrix A serves as the weight of each edge in the graph.
[0047] Furthermore, in the step S6, the graph autoencoder module can be expressed as:
[0048]
[0049] where f enc represents the Graph Convolutional Network (GCN), and k represents the feature dimension of the low-dimensional latent representation. The graph autoencoder module is used to map the network image node graph G to the low-dimensional latent representation:
[0050]
[0051] Specifically, f enc consists of L layers in total, and the output feature of the l-th layer (l = 1, 2, 3,..., L) can be expressed as:
[0052]
[0053] where represents adding a self-connection to the original adjacency matrix A, and I is the identity matrix; is 's degree matrix; H (l) is the input feature of the l-th layer, and H (1) = X; is the trainable weight parameter, d l and d l+1 represent the input feature dimension and the output feature dimension of the l-th layer respectively, d1 = N, dL+1 = k; σ(·) is the activation function, and ReLU or LeakyReLU can be used; Z = H (L+1) .
[0054] Furthermore, in the step S7, the inner product decoder module can be expressed as:
[0055]
[0056] where is the reconstructed adjacency matrix; σ(·) is the activation function, and the Sigmoid function is selected to normalize the result to the interval (0, 1).
[0057] Furthermore, in the step S8, to prevent overfitting, a weight decay regularization term is introduced, and the loss function used can be expressed as:
[0058] L = L rec + λ‖W‖ 2
[0059] where L rec is the reconstruction loss calculated based on the adjacency matrix and the reconstructed adjacency matrix, W represents all trainable parameters in the model; λ is a hyperparameter used to control the regularization strength.
[0060] Specifically, binary cross - entropy (BCE) is used to calculate the reconstruction loss between the adjacency matrix and the reconstructed adjacency matrix:
[0061]
[0062] Furthermore, in the step S10, for each image in the validation set and the test set, first obtain the adjacency matrix and the reconstructed adjacency matrix through the steps S2 to S8, and then use the abnormal node recognition module to determine abnormal nodes.
[0063] Specifically, in the abnormal node recognition module, calculate the reconstruction error of the row vector of the adjacency matrix corresponding to node i:
[0064]
[0065] where ‖·‖ can take the L1 norm or the L2 norm; A i,: and respectively represent the i - th row of the adjacency matrix A and the reconstructed adjacency matrix . If the value of δ i is greater than the abnormal node determination threshold τ, then node i is determined as an abnormal node.
[0066] Specifically, the calculation method of the abnormal node determination threshold τ is:
[0067] τ = (τ1 + τ2) / 2
[0068] Where τ1 is the lowest threshold for correctly detecting all defects in the validation set. That is, for any threshold less than τ1, there will be a situation where defects in the validation set cannot be correctly detected. τ2 ≥ τ1 is the highest threshold with the least number of false detections of defects under the condition that all defects in the validation set can be correctly detected. That is, for any threshold greater than τ2, the number of false detections of defects will increase.
[0069] Compared with the prior art, the core innovation of the present invention lies in proposing a fabric defect detection method based on graph anomaly monitoring. By dividing the fabric image into windows, constructing a graph based on the windows, and then using an anomaly monitoring strategy of a specially designed graph autoencoder to quickly identify abnormal nodes, and finally mapping back to the abnormal regions in the fabric image, accurate detection and positioning of various fabric defects are achieved. Compared with the prior art, the present invention does not require the use of a large number of fabric images with defects during the model training process, and has better robustness and generalization ability for fabrics with complex textures or diverse defect types. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0071] Figure 1 is a flowchart implemented according to the present invention;
[0072] Figure 2 is a structural diagram of a fabric defect detection model based on graph anomaly monitoring designed according to the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0073] The following will describe the exemplary embodiments of the present invention in more detail with reference to the drawings. Although the exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art. It should be noted that, without conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other. The present invention will be described in detail below with reference to the drawings and in combination with the embodiments.
[0074] The present invention discloses a fabric defect detection method based on graph anomaly monitoring, including the following:
[0075] Obtain fabric image data on at least one fabric inspection machine and perform preprocessing to obtain the preprocessed fabric image data;
[0076] Input the preprocessed fabric image data into a fabric defect detection model to obtain the defect detection result of the fabric image output by the fabric defect detection model, where the defect detection result includes the fabric physical position information corresponding to the defect;
[0077] The fabric defect detection model includes an image grid division module, a pre-trained image feature extraction module, an adjacency matrix construction module, a graph construction module, a graph autoencoder module, an inner product decoder module, and an abnormal node recognition module; the image grid division module divides the fabric image into multiple grid windows, and each grid window corresponds to a grid image; the pre-trained image feature extraction module is used to extract features from each grid image to generate a corresponding grid image feature vector; the adjacency matrix construction module calculates the spatial adjacency relationship and the feature similarity adjacency relationship between the grid windows respectively, and fuses them with weights to obtain an adjacency matrix; the graph construction module takes each grid window as a node in the graph, and establishes an edge between every two nodes to form a grid image node graph, where the grid image feature vector is used as the feature vector of the node, and the adjacency matrix is used as the weight of the edge; the graph autoencoder module maps the grid image node graph to a low-dimensional latent representation; the inner product decoder module reconstructs the adjacency matrix according to the low-dimensional latent representation to obtain a reconstructed adjacency matrix; the abnormal node recognition module calculates the reconstruction error of the row vector of the adjacency matrix corresponding to each node according to the adjacency matrix and the reconstructed adjacency matrix, and determines the node with a larger reconstruction error as an abnormal node. For the grid window corresponding to the abnormal node, obtain its corresponding fabric physical position information according to the counter.
[0078] The overall inference process of the defect detection model based on graph anomaly monitoring is as follows: input the preprocessed fabric image data into the image grid division module to obtain multiple grid images; input each grid image into the pre-trained image feature extraction module respectively to obtain grid image feature vectors; input the grid image feature vectors and the spatial position information of the grid windows corresponding to the grid images into the adjacency matrix construction module to obtain an adjacency matrix; input the grid image feature vectors and the adjacency matrix into the graph construction module to obtain a grid image node graph; input the grid image node graph into the graph autoencoder module to obtain a low-dimensional latent representation; input the low-dimensional latent representation into the inner product decoder module to obtain a reconstructed adjacency matrix; input the adjacency matrix and the reconstructed adjacency matrix into the abnormal node recognition module to obtain the abnormal node determination result.
[0079] The training process of the defect detection model based on graph anomaly monitoring is asFigure 1 , Figure 2 As shown in Figure 2 , the specific steps are as follows:
[0080] S1: Construct a fabric image dataset, preprocess the fabric image data, and divide it into a training set, a validation set, and a test set.
[0081] Specifically, first, through a camera fixedly installed on the fabric inspection machine, real-time image acquisition is performed on the surface of the continuously moving fabric to obtain a series of fabric image frames. Each image is an RGB image with a resolution of H×W. Secondly, each image is preprocessed by grayscaling and converted into a single-channel grayscale image, and then preprocessed by Gaussian filtering with a kernel size of 3×3 to reduce the interference of noise on subsequent feature extraction, obtaining the preprocessed fabric image Then, the images are divided into fabric images with defects and fabric images without defects. Each fabric image with defects is manually labeled, and the labeling result is the defect area in the image. Finally, the dataset is divided. A certain proportion (such as 60%) of the earliest collected fabric images without defects are used as the training set, a certain proportion (such as 20%) of the fabric images without defects collected during the middle period and a certain proportion (such as 50%) of the fabric images with defects collected earliest are used as the validation set, and the remaining fabric images without defects and fabric images with defects are used as the test set.
[0082] S2: Input the fabric image data into the image grid division module to obtain multiple grid images.
[0083] Specifically, the fabric image is divided into grid windows of the same size. The size of each grid window is p×q pixels, and the final number of grid windows The two-dimensional coordinate center of each grid window is denoted as (x i , y i ), and the corresponding grid image is denoted as M i , where i = 1, 2, …, N.
[0084] S3: Input each grid image into the pre-trained image feature extraction module to obtain grid image feature vectors.
[0085] Specifically, the pre-trained image feature extraction module can be expressed as:
[0086]
[0087] where θ represents the parameters of the pre-trained network, and d is the output feature dimension. The pre-trained image feature extraction module is used to convert the grid image M i corresponding to each grid window into a d-dimensional feature vector:
[0088]
[0089] Combine the feature vectors of N grid images to obtain:
[0090]
[0091] S4: Input the grid image feature vectors and the spatial position information of the grid windows corresponding to the grid images into the adjacency matrix construction module to obtain an adjacency matrix.
[0092] Specifically, the adjacency matrix construction module simultaneously considers the spatial adjacency relationship and the feature similarity adjacency relationship between grid windows.
[0093] When grid windows are adjacent to each other or close in the image plane, there should be edges connected in the graph to reflect their potential texture continuity or spatial correlation. Therefore, a spatial adjacency relationship matrix can be constructed according to the distance between the centers of grid windows or the eight-neighborhood relationship of grid windows. The value of each element is:
[0094]
[0095] where neighbor i represents the set of grid windows having a spatial adjacency relationship with grid window i, means that grid window i and grid window j are adjacent in space, then means that grid window i and grid window j are not adjacent in space.
[0096] To enhance the ability to capture similar textures and gray-scale distributions, calculate the similarity of the grid image feature vectors of different grid windows to obtain a feature similarity adjacency matrix. The value of each element is:
[0097]
[0098] where S(x i , x j ) represents calculating the similarity of grid image feature vectors x i and x j , and the cosine distance similarity can be used:
[0099]
[0100] or the Euclidean distance similarity:
[0101]
[0102] where σ is a feature scale hyperparameter.
[0103] The spatial adjacency matrix A (space) and the feature similarity adjacency matrix A (feat) are weighted and fused to obtain the adjacency matrix
[0104] A = αA (space) +(1 - α)A (feat)
[0105] where α ∈ [0, 1] is the fusion weight hyperparameter.
[0106] S5: Input the grid image feature vector and the adjacency matrix into the graph construction module to obtain the grid image node graph.
[0107] Specifically, input the grid image feature vector X and the adjacency matrix A into the graph construction module to obtain the grid image node graph where is the node set, x i serves as the feature vector of node i, ε is the set of edges of the graph, and the adjacency matrix A serves as the weight of each edge in the graph.
[0108] S6: Input the grid image node graph into the graph auto - encoder module to obtain the low - dimensional latent representation.
[0109] Specifically, the graph auto - encoder module can be expressed as:
[0110]
[0111] where f enc represents the Graph Convolutional Network (GCN), and k represents the feature dimension of the low - dimensional latent representation. The graph auto - encoder module is used to map the network image node graph G to the low - dimensional latent representation:
[0112]
[0113] f enc consists of L layers in total, and the output feature of the l - th layer (l = 1, 2, 3,..., L) can be expressed as:
[0114]
[0115] where represents adding self - connections to the original adjacency matrix A, and I is the identity matrix; is 's degree matrix; H (l) is the input feature of the l - th layer, H (1) = X; is the trainable weight parameter, d l and dl+1 respectively represent the input feature dimension and the output feature dimension of the $l$-th layer, $d_1 = N$, $d$ L+1 $= k$; $\sigma(\cdot)$ is the activation function, and ReLU or LeakyReLU can be used; $Z = H$ (L+1) .
[0116] S7: Input the low-dimensional latent representation into the inner product decoder module to obtain the reconstructed adjacency matrix.
[0117] Specifically, the inner product decoder module can be expressed as:
[0118]
[0119] where is the reconstructed adjacency matrix; $\sigma(\cdot)$ is the activation function, and the Sigmoid function is selected to normalize the result to the interval $(0, 1)$.
[0120] S8: Calculate the loss based on the adjacency matrix and the reconstructed adjacency matrix, perform gradient backpropagation, and update the model parameters.
[0121] Specifically, to prevent overfitting, a weight decay regularization term is introduced, and the loss function used can be expressed as:
[0122] $L = L$ rec $+ \lambda \|W\|$ 2
[0123] where $L$ rec is the reconstruction loss calculated based on the adjacency matrix and the reconstructed adjacency matrix, $W$ represents all trainable parameters in the model; $\lambda$ is a hyperparameter used to control the regularization strength.
[0124] The binary cross entropy (BCE) is used to calculate the reconstruction loss between the adjacency matrix and the reconstructed adjacency matrix:
[0125]
[0126] S9: Repeat steps S2 to S8, iterate the training until the model converges, and the training phase ends.
[0127] S10: Use the validation set to select the optimal hyperparameters and the abnormal node determination threshold for the model, and use the test set to evaluate the generalization performance of the model.
[0128] Specifically, for each image in the validation set and the test set, first obtain the adjacency matrix and the reconstructed adjacency matrix through steps S2 to S8, and then use the abnormal node recognition module to determine the abnormal nodes.
[0129] In the abnormal node recognition module, calculate the reconstruction error of the row vector of the adjacency matrix corresponding to node i:
[0130]
[0131] where ‖·‖ can take the L1 norm or the L2 norm; A i,: and respectively represent the i-th row of the adjacency matrix A and the reconstructed adjacency matrix . If the value of δ i is greater than the abnormal node determination threshold τ, then node i is determined as an abnormal node.
[0132] The calculation method of the abnormal node determination threshold τ is:
[0133] τ = (τ1 + τ2) / 2
[0134] where τ1 is the lowest threshold for correctly detecting all defects in the validation set, that is, for any threshold less than τ1, there will be a situation where there are defects in the validation set that cannot be correctly detected; τ2 ≥ τ1 is the highest threshold with the least number of false detections of defects under the condition of being able to correctly detect all defects in the validation set, that is, for any threshold greater than τ2, the number of false detections of defects will increase.
[0135] The process of selecting the model hyperparameters is as follows: set different hyperparameters for the model to obtain different model instances; for each model instance, train on the training set according to steps S2 to S9 and perform inference on the validation set, and calculate the performance metrics (such as the F1 metric) of each model instance on the validation set; compare the performance metrics of each model instance on the validation set, and select the model instance with the optimal performance metric as the finally used model.
[0136] For the finally used model selected through the validation set, perform model inference on the test set and calculate the performance metrics of the model on the test set.
[0137] The above has described the present invention in detail through embodiments, but the content described is only an exemplary embodiment of the present invention and cannot be considered as limiting the scope of implementation of the present invention. The protection scope of the present invention is defined by the claims. All those who use the technical solutions described in the present invention, or those skilled in the art, inspired by the technical solutions of the present invention, within the essence and protection scope of the present invention, design similar technical solutions to achieve the above technical effects, or make equivalent changes and improvements to the application scope, etc., should still fall within the patent coverage protection scope of the present invention.
Claims
1. A fabric defect detection method based on graph anomaly monitoring, characterized in that: Including the following steps: Obtain fabric image data on at least one fabric inspection machine and perform preprocessing to obtain preprocessed fabric image data; Input the preprocessed fabric image data into a fabric defect detection model to obtain a defect detection result of the fabric image output by the fabric defect detection model, where the defect detection result includes fabric physical position information corresponding to the defect; The fabric defect detection model includes an image grid division module, a pre-trained image feature extraction module, an adjacency matrix construction module, a graph construction module, a graph autoencoder module, an inner product decoder module, and an abnormal node recognition module; the image grid division module divides the fabric image into multiple grid windows, and each grid window corresponds to a grid image; the pre-trained image feature extraction module is used to extract features from each grid image to generate a corresponding grid image feature vector; The adjacency matrix construction module calculates the spatial adjacency relationship and the feature similarity adjacency relationship between the grid windows respectively, and fuses them with weights to obtain an adjacency matrix; the graph construction module takes each grid window as a node in the graph, and establishes an edge between every two nodes to form a grid image node graph, where the grid image feature vector is used as the feature vector of the node, and the adjacency matrix is used as the weight of the edge; the graph autoencoder module maps the grid image node graph to a low-dimensional latent representation; the inner product decoder module reconstructs the adjacency matrix according to the low-dimensional latent representation to obtain a reconstructed adjacency matrix; the abnormal node recognition module calculates the reconstruction error of the row vector of the adjacency matrix corresponding to each node according to the adjacency matrix and the reconstructed adjacency matrix, and determines the node with a larger reconstruction error as an abnormal node. For the grid window corresponding to the abnormal node, obtain its corresponding fabric physical position information according to the counter.
2. The fabric defect detection method based on graph anomaly monitoring according to claim 1, characterized in that: The fabric defect detection model is obtained by the following steps: S1: Construct a fabric image dataset, preprocess the fabric image data and divide it into a training set, a validation set, and a test set; S2: Input the fabric image data into the image grid division module to obtain multiple grid images; S3: Input each grid image into the pre-trained image feature extraction module respectively to obtain grid image feature vectors; S4: Input the grid image feature vectors and the spatial position information of the grid windows corresponding to the grid images into the adjacency matrix construction module to obtain an adjacency matrix; S5: Input the grid image feature vectors and the adjacency matrix into the graph construction module to obtain a grid image node graph; S6: Input the grid image node graph into the graph autoencoder module to obtain a low-dimensional latent representation; S7: Input the low-dimensional latent representation into the inner product decoder module to obtain a reconstructed adjacency matrix; S8: Calculate the loss according to the adjacency matrix and the reconstructed adjacency matrix, perform gradient backpropagation, and update the model parameters; S9: Repeat steps S2 to S8, iterate and train until the model converges, and the training stage ends; S10: Use the validation set to select the optimal hyperparameters and abnormal node determination threshold for the model, and use the test set to evaluate the generalization performance of the model.
3. The fabric defect detection method based on graph anomaly monitoring according to claim 2, characterized in that: In the step S1, the system performs real-time image acquisition on the surface of the continuously moving fabric through a camera fixedly installed on the fabric inspection machine, obtaining a series of fabric image frames; the image acquired by the camera is an RGB image with a resolution of H×W. First, it is preprocessed by graying to convert it into a single-channel grayscale image, and then preprocessed by Gaussian filtering with a kernel size of 3×3 to reduce the interference of noise on subsequent feature extraction, obtaining the preprocessed fabric image All the preprocessed fabric images are divided into a training set, a validation set, and a test set according to a certain ratio, where the training set only includes fabric images without defects, and both the validation set and the test set contain a large number of fabric images without defects and a small number of fabric images with defects; In the step S2, the fabric image is divided into grid windows of the same size, where the size of each grid window is p×q pixels, and the number of finally obtained grid windows The two-dimensional coordinate center of each grid window is denoted as (x i , y i ), and the corresponding grid image is denoted as M i , where i = 1, 2, …, N; In the step S3, the pre-trained image feature extraction module can be expressed as: Among them, θ represents the parameters of the pre-trained network, and d is the output feature dimension. The pre-trained image feature extraction module is used to convert the grid image M corresponding to each grid window i into a d-dimensional feature vector: Combining the feature vectors of N grid images to obtain:
4. The fabric defect detection method based on graph anomaly monitoring according to claim 2, wherein: In the step S4, the adjacency matrix construction module simultaneously considers the spatial adjacency relationship and the feature similarity adjacency relationship between grid windows. When grid windows are adjacent to each other or close to each other on the image plane, there should be edge connections in the figure to reflect their potential texture continuity or spatial correlation. Therefore, a spatial adjacency relationship matrix can be constructed based on the distance between the centers of the grid windows or the eight-neighborhood relationship of the grid windows The value of each element is: Among them, neighbor i represents the set of grid windows that have a spatial adjacency relationship with grid window i, indicates that grid window i and grid window j are adjacent in space, then indicates that grid window i and grid window j are not adjacent in space; To enhance the ability to capture similar textures and gray-scale distributions, the similarity of the grid image feature vectors of different grid windows is calculated to obtain a feature similarity adjacency matrix The value of each element is as follows: Among them, S(x i , x j ) represents the calculation of the similarity between the grid image feature vectors x i and x j . The cosine distance similarity can be used: Or Euclidean distance similarity: where σ is the feature scale hyperparameter; The spatial adjacency matrix A (space) and the feature similarity adjacency matrix A (feat) are weighted and fused to obtain the adjacency matrix A = αA (space) +(1 - α)A (feat) where α ∈ [0,1] is the fusion weight hyperparameter.
5. The fabric defect detection method based on graph anomaly monitoring according to claim 2, characterized in that: In the step S5, the grid image feature vector X and the adjacency matrix A are input into the graph construction module to obtain the grid image node graph where is the node set, x i is used as the feature vector of node i, ε is the set of edges of the graph, and the adjacency matrix A is used as the weight of each edge in the graph.
6. The fabric defect detection method based on graph anomaly monitoring according to claim 2, wherein: In the step S6, the graph autoencoder module can be expressed as: Among them, f enc represents a Graph Convolutional Network (GCN), and k represents the feature dimension of the low-dimensional latent representation; the graph autoencoder module is used to map the network image node graph G to the low-dimensional latent representation:
7. The fabric defect detection method based on graph anomaly monitoring according to claim 6, wherein: f enc It contains a total of L layers, and the output features of the l-th layer (l = 1, 2, 3,..., L) can be expressed as: Among them, represents adding self - connections to the original adjacency matrix A, and I is the identity matrix; is the degree matrix of; H (l) is the input feature of the l - th layer, H (1) = X; is a trainable weight parameter, d l and d l+1 represent the input feature dimension and output feature dimension of the l - th layer respectively, d1 = N, d L+1 = k; σ(·) is the activation function, and ReLU or LeakyReLU can be used; Z = H (L+1) .
8. The fabric defect detection method based on graph anomaly monitoring according to claim 2, characterized in that: In the step S7, the inner product decoder module can be expressed as: Among them, is the reconstructed adjacency matrix; σ(·) is the activation function, and the Sigmoid function is selected to normalize the result to the interval (0, 1).
9. The fabric defect detection method based on graph anomaly monitoring according to claim 2, wherein: In the step S8, to prevent overfitting, a weight decay regularization term is introduced, and the loss function used can be expressed as: L = L rec + λ‖W‖ 2 Among them, L rec is the reconstruction loss calculated based on the adjacency matrix and the reconstructed adjacency matrix, W represents all trainable parameters in the model; λ is a hyperparameter used to control the regularization strength; Using Binary Cross Entropy (BCE) to calculate the reconstruction loss between the adjacency matrix and the reconstructed adjacency matrix: In the step S10, the abnormal node recognition module is used to determine abnormal nodes. The abnormal node determination threshold is: τ = (τ1 + τ2) / 2 where τ1 is the lowest threshold for correctly detecting all defects in the validation set, that is, for any threshold less than τ1, there will be a situation where defects in the validation set cannot be correctly detected; τ2 ≥ τ1 is the highest threshold with the least number of false detections of defects under the condition that all defects in the validation set can be correctly detected, that is, for any threshold greater than τ2, the number of false detections of defects will increase; In the abnormal node recognition module, calculate the reconstruction error of the row vector of the adjacency matrix corresponding to node i: Among them, ‖·‖ can take the L1 norm or the L2 norm; A i,: and respectively represent the i-th row of matrix A and ; if the value of δ i is greater than τ, then node i is determined to be an abnormal node.
Citation Information
Patent Citations
An online visual detection method for pattern cloth defects
CN103604809B
A fabric defect detection method based on region fusion features
CN109685766B
YOLO Neural Network-Based Surface Defect Detection Device for Textile Fabrics
CN113433137B
Methods for identifying fabric defects and model training methods
CN113807434B
A fabric defect detection method based on an improved Yolov4 network
CN114240885B