A surface defect detection method based on multi-modal learning
By combining image and text features with a multimodal learning model, the problem of lost spatial information in traditional visual networks is solved, achieving efficient detection of minute defects and improving detection accuracy.
Patent Information
- Application Number
- CN202510655024.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-21
- Publication Date
- 2026-11-24
AI Technical Summary
Traditional visual networks lose too much spatial and boundary information during training, resulting in a decline in the detection of minute defects. Manual visual inspection is inefficient and prone to missed or false detections.
A multimodal learning-based approach is adopted, combining image and text features. Defect detection is performed through a multimodal learning model, which includes image preprocessing, text preprocessing, feature extraction, text location matching, and defect detection modules. The model parameters are optimized using a tokenizer and cross-entropy loss function to preserve the original spatial information of the defects.
It improves the accuracy of defect detection and can accurately identify minute defects even in situations with complex features and many interfering factors, making it more advantageous than a simple U-shaped neural network.
Smart Images

Figure CN123160408A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of defect detection technology, and more specifically to a surface defect detection method based on multimodal learning. Background Technology
[0002] With the booming development of the economy, my country's manufacturing industry is also developing rapidly, placing increasingly higher demands on the appearance quality of products. Currently, most appearance quality inspections still rely on manual visual inspection, which is inefficient and frequently results in missed or false inspections. This leads to reduced product quality and waste of resources. To better control product appearance defects, intelligent inspection methods based on machine vision will gradually replace manual visual inspection in the production line quality assessment stage, becoming the mainstream method.
[0003] For target images with minor defects, traditional visual networks lose too much spatial and boundary information during training due to multiple convolution and pooling operations, resulting in a decline in detection performance. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide a surface defect detection method based on multimodal learning, which enhances defect features while retaining the original spatial information of the defect, and has a high defect detection accuracy.
[0005] To address the aforementioned technical problems, this invention provides a surface defect detection method based on multimodal learning, comprising:
[0006] Step 1: Use a camera to capture images and obtain an initial image dataset X. At the same time, use a text annotation method based on category and location to annotate the images.
[0007] Step 2: Construct a multimodal learning model, which includes an image preprocessing module, a text preprocessing module, an image feature extraction module, a text feature extraction module, a text location matching module, and a defect detection module;
[0008] Step 3: Input the initial image dataset X into the image and text preprocessing module, and obtain preprocessed image-text pairs through n image and text preprocessing algorithms.
[0009] The text preprocessing algorithm used is a Tokenizer.
[0010] X = E token (Index(WordPiece(T))∪{CLS,SEP})+E pos (P)+E seg(S), T is the original text, WordPiece is the word segmentation table, Index is the word segmentation index, CLS is the classification tag, SEP is the delimiter, P is the position index of the word in the sequence, S is the sentence number to which the word belongs, E token It is a lexical embedding, E pos It is position embedding, E seg It is a fragment embedding.
[0011] Step 4: Pair the preprocessed image with text. The input image and text feature extraction module are trained to obtain image-text pairs. The corresponding image feature vectors and text feature vectors;
[0012] Step 5: Divide the mask space into nine subspaces, add the position category embedding vector to the text feature vector and input it into the text position matching module to generate the optimal text corresponding subspace prediction mask;
[0013] The text position matching module uses cross-entropy loss E1:
[0014] B is the batch size, Q is the number of query vectors generated by the module for target detection, and l ij It is an indicator function, p ij It is the probability that the module predicts the true location category corresponding to the j-th query.
[0015] Step Six: Input the subspace prediction mask and image feature vector into the defect detection module for training, optimize parameters, and obtain the trained multimodal learning model, specifically including:
[0016] The defect detection module uses a combined loss E2:
[0017] E2=λ bce L bce +λ dice L dice +λ focal L focal ,
[0018]
[0019] λ bce , λ dice , λ focal Weighting coefficients, y i It's a real tag, p i is the predicted probability of pixel i, ∈ is a constant used for numerical stability, and γ is a focusing parameter used to reduce the relative loss of well-classified samples.
[0020] The objective function of the multimodal learning model is: E(θ) f ,θ y )=E1-E2~W(X l ), where θ f θ represents the parameter of the text position matching module. y Indicates the parameters of the defect detection module;
[0021] The optimization method for the parameters of the multimodal learning model is as follows:
[0022]
[0023] Where, θ f The parameters represent the text position matching module. θ represents the parameters to be optimized in the text position matching module. y These represent the parameters of the defect detection module. This represents the parameters to be optimized in the defect detection module, where μ is the learning rate.
[0024] During the training process, through continuous cross-training and updating, the parameters in the network of the multimodal learning model are optimized.
[0025] The model's key feature lies in the text position matching module in step five:
[0026] The text location matching module processes the text feature vector from step four, predicts the location category by adding a query vector, generates the optimal text location pair using Hungarian matching, and finally generates a predicted subspace prediction mask, specifically including:
[0027] The text feature vector processed in step four is expanded to the dimension of the query vector Q. Simultaneously, the query vector Q is expanded to the batch dimension. The two are combined through element-level addition:
[0028] F p =F t exp +Q exp ,in It is the fused location-aware feature.
[0029] Location-aware features predict the target's location category using a classification head network. During the training phase, the Hungarian matching algorithm is used to establish the optimal match between the query and the real location, and the cross-entropy loss is calculated.
[0030]
[0031] Generate a subspace prediction mask based on the predicted location category.
[0032] Where (x) c ,y c ) represents the center coordinates of the predicted location region, and σ controls the diffusion range of the Gaussian distribution.
[0033] The beneficial effects of this invention are:
[0034] When the original target image has complex features, many interfering factors, and unclear defect types, the use of digital image technology for preprocessing will also result in the loss of some information. This invention constructs a multimodal learning model for defect detection. When traditional visual models lose spatial information, this model can compensate for spatial information through text features. Compared with a simple U-shaped neural network, the defect detection accuracy of this invention is higher. Attached Figure Description
[0035] Figure 1 The multimodal learning model of this invention includes a convolutional block as a component of the image feature extraction module.
[0036] Figure 2 The initial image-text pair in Example 1;
[0037] Figure 3 This refers to the position masks for the nine subspaces in Example 1;
[0038] Figure 4 The detection results are from the multimodal model in Example 1;
[0039] Figure 5 This is the detection result of UNet in Example 1. Detailed Implementation
[0040] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments described are not intended to limit the present invention.
[0041] Reference Figure 1 As shown, this invention discloses a surface defect detection method based on multimodal learning, comprising the following steps:
[0042] Step 1: Use a camera to capture images and obtain an initial image dataset X. At the same time, use a text annotation method based on category and location to annotate the images.
[0043] Step 2: Construct a multimodal learning model, which includes an image preprocessing module, a text preprocessing module, an image feature extraction module, a text feature extraction module, a text location matching module, and a defect detection module;
[0044] Step 3: Input the initial image dataset X into the image and text preprocessing module, and obtain preprocessed image-text pairs through n image and text preprocessing algorithms.
[0045] The text preprocessing algorithm used is a Tokenizer.
[0046] X = E token (Index(WordPiece(T))∪{CLS,SEP})+E pos (P)+E seg (S), T is the original text, WordPiece is the word segmentation table, Index is the word segmentation index, CLS is the classification tag, SEP is the delimiter, P is the position index of the word in the sequence, S is the sentence number to which the word belongs, E token It is a lexical embedding, E pos It is position embedding, E seg It is a fragment embedding.
[0047] Step 4: Pair the preprocessed image with text. The input image and text feature extraction module are trained to obtain image-text pairs. The corresponding image feature vectors and text feature vectors;
[0048] Step 5: Divide the mask space into nine subspaces, add the position category embedding vector to the text feature vector and input it into the text position matching module to generate the optimal text corresponding subspace prediction mask;
[0049] The text location matching module maps each segment of text to a specific location mask, using cross-entropy loss E1.
[0050] B is the batch size, Q is the number of query vectors generated by the module for target detection, and l ij It is an indicator function, p ij It is the probability that the module predicts the true location category corresponding to the j-th query.
[0051] Step Six: Input the subspace prediction mask and image feature vector into the defect detection module for training, optimize parameters, and obtain the trained multimodal learning model, specifically including:
[0052] The defect module detects whether the category of each pixel is a defect category, using the joint loss E2:
[0053] E2=λ bce L bce +λ dice L dice +λfocal L focal ,
[0054]
[0055] λ bce , λ dice , λ focal Weighting coefficients, y i It's a real tag, p i is the predicted probability of pixel i, ∈ is a constant used for numerical stability, and γ is a focusing parameter used to reduce the relative loss of well-classified samples.
[0056] Reference Figure 1 As shown, the image and text feature extraction module extracts features from the image and text. The purpose is to enable the extracted features to be accurately detected by the defect detection module, and to enable the text position matching module to assign the corresponding text to the correct subspace, thereby forming a position mask that is beneficial to the final prediction result.
[0057] The ultimate goal of the model is to fuse the location mask with the feature upsampling mask proposed by the image feature extraction module to predict the category of each pixel as accurately as possible. The training method involves the defect detection module attempting to determine whether each pixel belongs to a defect category based on the objective function.
[0058] The objective function of the multimodal learning model is: E(θ) f ,θ y )=E1-E2~W(X l ), where θ f θ represents the parameter of the text position matching module. y Indicates the parameters of the defect detection module;
[0059] The optimization method for the parameters of the multimodal learning model is as follows:
[0060]
[0061] Where, θ f The parameters represent the text position matching module. θ represents the parameters to be optimized in the text position matching module. y These represent the parameters of the defect detection module. This represents the parameters to be optimized in the defect detection module, where μ is the learning rate.
[0062] During the training process, through continuous cross-training and updating, the parameters in the network of the multimodal learning model are optimized.
[0063] Due to the application of the above technical solutions, the present invention has the following advantages compared with the prior art: When the original target image features are complex, there are many interfering factors, and the defect type is not obvious, the use of digital image technology for preprocessing will also cause some information loss. The present invention constructs a multimodal learning model for defect detection. When the traditional visual model loses spatial information, this model can compensate for spatial information through text features. Compared with the simple U-shaped neural network, the defect detection accuracy of the present invention is higher.
[0064] Example 1
[0065] In the textile manufacturing industry, fabrics produced often have loose threads, a defect that is not readily apparent. Detection of these defects is frequently ineffective; therefore, a multimodal learning method is employed for their detection.
[0066] I. Images are acquired on production equipment to obtain an image dataset. The acquired image data is then labeled using a category + location text annotation method to obtain image text pairs, such as... Figure 2 As shown;
[0067] Second, the text in the image-text pair is vectorized by a Tokenizer, and then text features are generated by a Transformer encoder. The image features are generated by an image feature extraction module consisting of multiple ConvBlocks.
[0068] III. Mapping the mask space into nine subspaces, as follows: Figure 3 As shown, text features combined with the query vector are input into the classifier to predict the position category corresponding to a text, and then converted into the corresponding subspace mask. The cross-entropy loss E1 is used.
[0069]
[0070] IV. For different fabric images, a defect detection module is used for classification. The defect detection module determines the category of each pixel using the following method:
[0071] E2=λ bce L bce +λ dice L dice +λ focal L focal ,
[0072]
[0073]
[0074] V. Train the multimodal learning model. The objective function of the model is as follows:
[0075] E(θf ,θ y )=E1-E2~W(X l ),
[0076] The optimization method is as follows:
[0077]
[0078] VI. After training, the optimal model parameters θ are obtained. f ,θ y Use this set of parameters for subsequent defect detection.
[0079] Experimental results are as follows Figure 4 As shown, the position mask is the subspace position mask predicted in step three for the text.
[0080] For comparison, detection results from the U-shaped deep neural network UNet were added, such as... Figure 5 The image shows a schematic diagram of the detection results from UNet.
Claims
1. A surface defect detection method based on multimodal learning, characterized in that, Includes the following steps: Step 1: Use a camera to capture images and obtain an initial image dataset X. At the same time, use a text annotation method based on category and location to annotate the images. Step 2: Construct a multimodal learning model, which includes an image preprocessing module, a text preprocessing module, an image feature extraction module, a text feature extraction module, a text location matching module, and a defect detection module; Step 3: Input the initial image dataset X into the image and text preprocessing module, and obtain preprocessed image-text pairs through n image and text preprocessing algorithms. The text preprocessing algorithm used is a Tokenizer. X = E token (Index(WordPiece(T))∪{CLS,SEP})+E pos (P)+E seg (S), T is the original text, WordPiece is the word segmentation table, Index is the word segmentation index, CLS is the classification tag, SEP is the delimiter, P is the position index of the word in the sequence, S is the sentence number to which the word belongs, E token It is a lexical embedding, E pos It is position embedding, E seg It is a fragment embedding; Step 4: Pair the preprocessed image with text. The input image and text feature extraction module are trained to obtain image-text pairs. The corresponding image feature vectors and text feature vectors; Step 5: Divide the mask space into nine subspaces, add the position category embedding vector to the text feature vector and input it into the text position matching module to generate the optimal text corresponding subspace prediction mask; The text position matching module uses cross-entropy loss E1: B is the batch size, Q is the number of query vectors generated by the module for target detection, and l ij It is an indicator function, p ij It is the probability that the module predicts the true location category corresponding to the j-th query; Step Six: Input the subspace prediction mask and image feature vector into the defect detection module for training, optimize parameters, and obtain the trained multimodal learning model, specifically including: The defect detection module uses a combined loss E2: E2=λ bce L bce +λ dice L dice +λ focal L focal , λ bce , λ dice , λ focal Weighting coefficients, y i It's a real tag, p i is the predicted probability of pixel i, ∈ is a constant used for numerical stability, and γ is a focusing parameter used to reduce the relative loss of well-classified samples.
2. The surface defect detection method based on multimodal learning as described in claim 1, characterized in that, The text position matching module in step five: The text location matching module processes the text feature vector from step four, predicts the location category by adding a query vector, generates the optimal text location pair using Hungarian matching, and finally generates a predicted subspace prediction mask, specifically including: S1. Expand the text feature vector processed in step four to the dimension of the query vector Q. Simultaneously, the query vector Q is expanded to the batch dimension. The two are combined through element-level addition: in It is the fused position-aware feature S2. Location-aware features predict the target's location category through a classification head network. During the training phase, the Hungarian matching algorithm is used to establish the optimal match between the query and the real location, and the cross-entropy loss is calculated. S3. Generate a subspace prediction mask based on the predicted location category. Where (x) c ,y c ) represents the center coordinates of the predicted location region, and σ controls the diffusion range of the Gaussian distribution.
