Patch inductance surface defect detection method and system based on token fusion
By introducing a token fusion module into the Vision Transformer network model, the similarity of tokens is fused to optimize the detection of surface defects in patch inductors, solving the problems of low detection accuracy and high computational resource consumption, and achieving fast and accurate detection of surface defects in patch inductors.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-20
- Publication Date
- 2026-04-14
AI Technical Summary
Existing surface defect detection methods for patch inductors suffer from low detection accuracy, high computational resource consumption, and slow detection speed, making them particularly difficult to meet real-time detection requirements on mobile application platforms with limited computing resources.
A token fusion module is introduced, which optimizes the processing through the Vision Transformer network model to fuse the similarity between tokens, reduce redundant tokens, and improve the training speed and detection accuracy of the model, making it suitable for platforms with limited computing resources.
It enables rapid and accurate detection of surface defects in patch inductors, reduces computational resource consumption, improves model throughput and detection efficiency, and meets real-time production requirements.
Smart Images

Figure CN116309451B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image recognition technology, and in particular to a method and system for detecting surface defects in patch inductors based on token fusion. Background Technology
[0002] Surface mount inductors (SMOs) are widely used in digital products, automotive electronics, security products, and small communication devices due to their low impedance, high power, high saturation current, and miniaturization. During the manufacturing process, defects such as insufficient adhesive, terminal misalignment, loose claws, poor wire clamping, and chipping can occur. To improve the yield of SMOs, quality inspection is necessary. Traditional image processing techniques for surface defect detection require feature analysis for each type of defect, followed by repeated trials and parameter adjustments using image processing algorithms to achieve good results. This method has poor versatility, demands high experience and technical expertise from engineers, and cannot guarantee accuracy. While convolutional neural networks (CNNs) can be used for surface defect detection, the millimeter-level defects mean that CNNs, using local receptive fields for feature extraction, cannot establish long-distance dependencies in global information, resulting in low accuracy. Compared to CNNs, Vision... The Transformer (ViT) module, consisting of an attention module with matrix multiplication operations and a multilayer perceptron module, can accelerate model training and inference speed, exhibiting excellent performance in small object detection tasks. However, on mobile application platforms with limited computing resources, the large size of the ViT model leads to significant latency when detecting surface defects in patch inductors, failing to meet the production requirements for real-time patch inductor detection. A common method to improve ViT's detection speed is token pruning. A token represents a slice of the input image, resulting in multiple image patches. These patches are then linearly mapped and positionally encoded. While token pruning can improve the model's detection accuracy, it has the following drawbacks: it requires additional model training, increasing computational load; token pruning leads to information loss, limiting the number of tokens; and the number of tokens changes with the input, making batch processing impossible. Summary of the Invention
[0003] To address the aforementioned technical problems, the present invention aims to provide a method and system for detecting surface defects in surface mount inductors based on token fusion, thereby achieving rapid and accurate detection of surface defects in surface mount inductors by introducing a token fusion module.
[0004] The first technical solution adopted in this invention is: a method for detecting surface defects of patch inductors based on token fusion, comprising the following steps:
[0005] Obtain the dataset of defects in patch inductors;
[0006] Based on the Vision Transformer network model, a token fusion module is introduced to optimize it, resulting in an optimized Vision Transformer network model.
[0007] The surface defect detection results of the patch inductor surface defect dataset are obtained by performing surface defect detection on the optimized Vision Transformer network model.
[0008] Furthermore, the step of obtaining the patch inductor defect dataset specifically includes:
[0009] Image acquisition and processing are performed on the surface mount inductors on the production line to obtain the raw dataset of surface mount inductors;
[0010] Data augmentation processing is performed on the original dataset of surface mount inductors to obtain the augmented dataset of surface mount inductors.
[0011] By using image annotation software, the patch inductors with surface defects in the enhanced patch inductor dataset are labeled to obtain the patch inductor defect dataset.
[0012] Furthermore, the step of introducing a token fusion module to optimize the Vision Transformer network model to obtain an optimized Vision Transformer network model specifically includes:
[0013] A token fusion module is introduced to determine the similarity between tokens, and obtain the similarity judgment result of the first token and the similarity judgment result of the second token.
[0014] The tokens are fused based on the similarity judgment results of the first tokens and the similarity judgment results of the second tokens;
[0015] Based on the similarity fusion results between tokens, a binary soft matching algorithm is used to match the similarity between tokens;
[0016] The self-attention weights of the Vision Transformer network model are adjusted and updated based on the similarity matching results between tokens, resulting in the optimized Vision Transformer network model.
[0017] Furthermore, the step of introducing a token fusion module to determine the similarity between tokens and obtain the first token similarity judgment result and the second token similarity judgment result specifically includes:
[0018] By introducing a token fusion module, the Vision Transformer network model includes a self-attention module, a token fusion module, and a multilayer perceptron module.
[0019] The key vector Key in the self-attention module of the Vision Transformer network model is used to extract the feature information in the token fusion module, thereby obtaining the feature information of the token fusion module.
[0020] The feature information in the token fusion module is analyzed by dot product similarity to determine the similarity between tokens and obtain the first token similarity judgment result.
[0021] The multilayer perceptron module based on the Vision Transformer network model obtains the similarity judgment result of the second tokens by measuring the similarity between tokens through cosine distance.
[0022] Furthermore, the step of matching the similarity between tokens based on the similarity fusion result using a binary soft matching algorithm specifically includes:
[0023] All tokens input to the token fusion module are equally divided to obtain a first partition set and a second partition set.
[0024] The cosine distance between the output features of the self-attention module of the Vision Transformer network model and the output features of the multilayer perceptron module of the Vision Transformer network model is calculated to obtain the cosine distance value.
[0025] Based on the cosine distance value, the tokens in the first partition set and the second partition set are compared one by one to obtain the comparison result;
[0026] Select tokens from the comparison results that exceed a preset similarity threshold and mark them with borders;
[0027] The tokens with marked edges are fused together, and their feature information is averaged and concatenated for matching to obtain the similarity matching results between the tokens.
[0028] Furthermore, the step of adjusting the self-attention weights of the Vision Transformer network model based on the similarity matching results between tokens and updating them in the Vision Transformer network model to obtain the optimized Vision Transformer network model specifically includes:
[0029] Define a row vector that contains the size of each token;
[0030] Based on the similarity matching results between tokens, the row vectors are added to the self-attention module of the Vision Transformer network model, and the self-attention weights of the Vision Transformer network model are adjusted.
[0031] The adjusted self-attention module is then updated in the Vision Transformer network model to obtain the optimized Vision Transformer network model.
[0032] Furthermore, the expression for the process of adjusting the attention weights of the Vision Transformer network is as follows:
[0033]
[0034] In the above formula, d represents the scaling factor, Q represents the Query, K represents the Key, s represents the row vector, and T represents the transpose of the matrix.
[0035] Furthermore, the step of performing surface defect detection processing on the patch inductor defect dataset based on the optimized Vision Transformer network model to obtain the patch inductor surface defect detection results specifically includes:
[0036] The patch inductor defect dataset is input into the optimized Vision Transformer network model, which includes a patch layer, a linear mapping layer, an embedding layer, a first LN layer, a self-attention layer, a token fusion layer, a multilayer perceptron layer, a second LN layer, and a classification layer.
[0037] The patch inductor defect dataset is segmented based on the patch layer to obtain the segmentation results.
[0038] The segmentation results are linearly mapped using a linear mapping layer to obtain a dimensionality-reduced result.
[0039] The positional encoding process is performed on the reduced-dimensional result based on the embedding layer to obtain the encoded result;
[0040] Based on the first LN layer, the variance and mean of the encoding result are calculated to obtain the first calculation result;
[0041] The encoding results are mapped to Q, K, and V values based on the self-attention layer, and grouped according to the number of attention heads to obtain the grouping results;
[0042] The first calculation result and the grouping result are added together and then input into the token fusion layer for averaging. That is, the tokens are matched for similarity using a binary soft matching algorithm to obtain the matching result.
[0043] The matching results are scaled based on the multilayer perceptron layer to obtain scaled matching results.
[0044] The matching result is added to the scaled matching result and then input into the second LN layer for variance and mean calculation to obtain the second calculation result;
[0045] Based on the second calculation result, image classification processing is performed through the classification layer to obtain the classification result. The classification result includes front chipping, side chipping, insufficient adhesive, poor wire clamping, segment misalignment, and claw floating of the chip inductor.
[0046] Furthermore, the optimized VisionTransformer network model is tested using a test set from a patch inductor defect dataset. F1-Score, Recall, and Precision are used as evaluation metrics to determine whether the optimized VisionTransformer network model has reached its optimal state. The optimal state is determined when the loss function of the optimized VisionTransformer network model converges.
[0047] The second technical solution adopted in this invention is: a surface defect detection system for patch inductors based on token fusion, comprising:
[0048] The acquisition module is used to acquire a dataset of defects in patch inductors.
[0049] The optimization module, based on the Vision Transformer network model, introduces the token fusion module to optimize it, resulting in an optimized Vision Transformer network model.
[0050] The detection module performs surface defect detection processing on the patch inductor defect dataset based on the optimized Vision Transformer network model, and obtains the surface defect detection results of the patch inductor.
[0051] The beneficial effects of the method and system of this invention are as follows: This invention designs a token merging method that does not require training while taking into account model performance. A token merging module is introduced between the attention module and the multilayer perceptron module of the Vision Transformer to optimize the model, thereby merging redundant tokens, improving the model's throughput, increasing the model's training speed, shortening the model's total training time, and enabling the model to be ported to mobile platforms with limited computing resources, thus meeting the need for fast and accurate detection of surface defects in patch inductors. Attached Figure Description
[0052] Figure 1 This is a flowchart of the steps of the method for detecting surface defects of patch inductors based on token fusion in this invention;
[0053] Figure 2 This is a structural block diagram of the surface defect detection system for patch inductors based on token fusion according to the present invention;
[0054] Figure 3 This is a schematic diagram illustrating the token fusion strategy introduced in the Transformer block of this invention;
[0055] Figure 4 This is a schematic diagram of the token similarity matching process of the present invention;
[0056] Figure 5 This is a diagram of the Vision Transformer network structure for the token fusion module introduced in this invention;
[0057] Figure 6 This is a diagram showing the surface defect detection results of a patch inductor according to a specific embodiment of the present invention. Detailed Implementation
[0058] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments. The step numbers in the following embodiments are only for ease of explanation and do not limit the order of the steps. The execution order of each step in the embodiments can be adapted according to the understanding of those skilled in the art.
[0059] Reference Figure 1 This invention provides a method for detecting surface defects of patch inductors based on token fusion, the method comprising the following steps:
[0060] S1. Obtain the dataset of defects in patch inductors;
[0061] Specifically, a dataset of surface mount inductor defects was created by augmenting the raw data of surface mount inductors collected from the production line using data augmentation algorithms to enrich the diversity of the dataset samples. The data augmentation algorithms used included rotation, translation, flipping, mirroring, brightness variation, and noise addition. Then, image annotation software was used to create labels, assigning the following tags to defects in surface mount inductors: front chipping, side chipping, insufficient glue, poor wire clamping, segment misalignment, and claw floating, respectively: collapsase, Vcollapse, noglue, VBadclamp, offset, and Pfloat. The surface mount inductor defect dataset was randomly divided into training, validation, and test sets in an 8:1:1 ratio.
[0062] S2. Based on the Vision Transformer network model, a token fusion module is introduced to optimize it, resulting in an optimized Vision Transformer network model.
[0063] S21. Define the similarity between tokens;
[0064] Specifically, we first define the similarity between tokens. A relatively simple and direct way to determine whether tokens are similar is that tokens that are close in distance are considered similar, but this method is not the optimal solution;
[0065] This scheme uses the key (K) in the QKV (query, key, value) self-attention mechanism built into the transformer to determine the similarity of tokens, such as... Figure 3 As shown, in the feature extraction stage of the model, the Key in the Attention module has been extracted and the feature information contained in each token has been summarized. The token fusion module uses dot product similarity to analyze and process the feature information input to the Attention module to determine whether the tokens are similar. The tokens are the input information of the token fusion module. At the same time, the cosine distance is used in the Multilayer Perceptron (MLP) module to measure the similarity between tokens. Finally, the output of the token fusion module is fused with the output of the Multilayer Perceptron module. Tokens with high similarity are fused. With n=8, the Key value and dot product similarity of the model are calculated. If the similarity is greater than or equal to 98%, the tokens are fused, so that the model can achieve a good balance between detection accuracy and detection speed.
[0066] S22. Based on the feature information output by the attention module, use the binary soft matching algorithm to match the similarity of tokens;
[0067] Specifically, based on the feature information output by the attention module, a binary soft matching algorithm is used to match the similarity of tokens, and its flowchart is as follows: Figure 4 As shown, the first step involves dividing all tokens input to the token fusion module into two sets of equal size, set A and set B. The second step compares each token in set A with each token in set B based on the features output by the attention module and the cosine distance output by the multilayer perceptron module, identifying similar tokens and drawing an edge between them. The third step selects the n most similar edges based on token similarity and removes the rest. The fourth step fuses the most similar edges obtained in the third step and takes the average of the feature information. The fifth step concatenates the two matched sets to obtain the final fused result processed by the token fusion module. Since each token in set A of the bipartite soft matching graph has only one edge, the computational cost of fusing similar tokens in the fourth step is negligible.
[0068] The binary soft matching algorithm can accurately match n pairs of similar tokens and fuse them together. This precisely reduces n tokens in each layer. When the model has L layers, it can ultimately reduce nL tokens, significantly reducing token redundancy, improving model throughput, and reducing the computational resources required for model runtime. The larger the value of n, the more tokens are reduced, but the impact on the model's detection accuracy is minimal. Notably, regardless of the number of tokens in the input patch inductor defect image, the token fusion module will ultimately reduce the number of tokens by nL, greatly improving the computational efficiency when batch processing tokens and accelerating training and inference.
[0069] S23, Adjust attention weights.
[0070] Specifically, the tokens in the transformer block are fused into n tokens after passing through the fusion module. Therefore, each token now represents n images, not just one. In the ViT algorithm model, one token represents a segmentation block of the patch inductor input image. When the input patch inductor image is segmented into N images, there will be N tokens. The attention matrix also has an N×N dimension, representing the correspondence between the N image blocks. After fusing n tokens, the attention matrix should become (Nn)×(Nn). After processing with the token fusion module, the attention weights corresponding to the keys of the fused image blocks will also increase because they incorporate the feature information of multiple tokens. Once the tokens are fused, they can no longer represent a single input image block, requiring an update to the softmax attention value. We address this issue with a simple improvement, defining a row vector s, s∈R. 1×N s represents a row vector containing the size of each token, and the attention formula is:
[0071]
[0072] In the above formula, d represents the scaling factor, Q represents the query, K represents the key, s represents the row vector, and T represents the transpose of the matrix;
[0073] By directly adding the row vector s to the attention matrix using the above formula, it is equivalent to updating the attention weights of the key values of the fused tokens, and these key values are the key values that have been fused.
[0074] S3. Based on the optimized Vision Transformer network model, surface defect detection processing is performed on the patch inductor defect dataset to obtain the patch inductor surface defect detection results.
[0075] Specifically, the ViT network model, which incorporates the token fusion module, is trained using the pre-defined dataset with 200 epochs. Network parameters are saved every 10 training iterations. The model's performance is then tested using a test set, with F1-Score, Recall, and Precision used as evaluation metrics to determine if the network model is optimal.
[0076] Construct a Vision Transformer model that incorporates a token fusion module. After the above processing, the token fusion module can be directly added to the already trained ViT algorithm model, such as... Figure 5As shown, the Vision Transformer algorithm model, which introduces a token fusion module, first segments the 416×416 image of a patch inductor surface defect. The size of the segmented image patch is 16×16. After passing through the Patch module, each input image is divided into 416×416 / 16×16=676 patches, and the dimension of each patch is 768. Then, after processing through the linear mapping layer, the dimension becomes 676×768, that is, the number of tokens is 676, and the dimension of the tokens is 768. A cls character is added, and then position encoding is performed. At this time, the token dimension is 677×768. The processed tokens are input into (LayerNorm, LN) to calculate the variance and mean of each image patch. After processing by the LN layer, the feature dimension is still 677×768. In the attention module, the input tokens are mapped to Q, K, and V, and grouped according to the number of attention heads. This scheme has 12 attention heads, and after grouping, the QKV dimension becomes 677×64. Next, the output of the attention module and the output of the LN layer are added together. The result of this addition is input to the token fusion module, where a binary soft matching algorithm is used to perform similarity matching on the tokens, fusing tokens with high similarity to reduce redundancy. The result is then input to the multilayer perceptron module for scaling, with the processed dimension remaining 677×768. The output of the MLP layer is then added to the output of the token fusion module, followed by LN processing. After the algorithm iterates L times, the feature extraction and learning of the surface defects of the patch inductor is completed. Finally, the input image is processed to achieve surface defect detection of the patch inductor. Using the token fusion module during the training phase is not mandatory, as it can be directly incorporated into the algorithm model without training. However, adding the token fusion module during training can reduce the decrease in model detection accuracy and accelerate training. The token fusion module essentially performs an averaging operation on the tokens, which can be considered a pooling operation. Therefore, this invention can use average pooling for backpropagation to construct an algorithm model that requires no training.
[0077] In summary, this invention fine-tunes the parameters of the Vision Transformer network model incorporating a token fusion module. If the loss function converges during training and all defect types exhibit excellent evaluation metrics when the algorithm model is evaluated using a patch inductor test set, no parameter fine-tuning is necessary; otherwise, the above process is repeated. Finally, the optimal weight file is saved. During the patch inductor detection stage, by loading the optimal weight file, surface defects of the patch inductor can be predicted, enabling the identification and localization of defect targets. Finally, the prediction results are output and displayed, such as... Figure 5 As shown, when a test image is input, the improved Vision Transformer model, which is trained through multiple iterations, is used to predict the input test image, thereby achieving the identification and localization of defective targets. Figure 6 This image shows the results of surface defect detection for surface mount inductors. The types of surface defects identified in the image are: insufficient adhesive, front chipping, and side chipping. The detection accuracy is over 96%, with insufficient adhesive and side chipping achieving an accuracy of 99%. This meets the needs of fast and accurate production of surface mount inductors.
[0078] Therefore, this solution designs a token fusion model that requires no training and balances detection speed and accuracy, offering the following advantages: it fuses redundant tokens without requiring training, reduces computational resource consumption, improves model training and inference speed, increases model throughput, and enables large models to be ported to embedded platforms with limited computational resources. The basic idea of the token fusion model is to introduce a token fusion module between the attention module and the multilayer perceptron module of the Vision Transformer model. First, the similarity of tokens is defined, using the feature information of the attention module and the cosine distance of the multilayer perceptron module to measure token similarity. Based on the token similarity, a binary soft matching algorithm is used for matching, and tokens with high similarity are fused, ultimately reducing the number of tokens by nL. For the fused tokens, a row vector s is defined to represent the size of each token, and the attention weights are updated for the key value of the new token. This results in a training-free model that balances detection accuracy and speed.
[0079] Reference Figure 2 A token-based surface defect detection system for patch inductors includes:
[0080] The acquisition module is used to acquire a dataset of defects in patch inductors.
[0081] The optimization module, based on the Vision Transformer network model, introduces the token fusion module to optimize it, resulting in an optimized Vision Transformer network model.
[0082] The detection module performs surface defect detection processing on the patch inductor defect dataset based on the optimized Vision Transformer network model, and obtains the surface defect detection results of the patch inductor.
[0083] The content of the above method embodiments is applicable to this system embodiment. The specific functions implemented in this system embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.
[0084] The above is a detailed description of the preferred embodiments of the present invention. However, the present invention is not limited to the embodiments described. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention. All such equivalent modifications or substitutions are included within the scope defined by the claims of this application.
Claims
1. A method for detecting surface defects in patch inductors based on token fusion, characterized in that, Includes the following steps: Obtain the dataset of defects in patch inductors; By introducing a token fusion module, the Vision Transformer network model includes a self-attention module, a token fusion module, and a multilayer perceptron module. The key vector Key in the self-attention module of the Vision Transformer network model is used to extract the feature information in the token fusion module, thereby obtaining the feature information of the token fusion module. The feature information in the token fusion module is analyzed by dot product similarity to determine the similarity between tokens and obtain the first token similarity judgment result. The multilayer perceptron module based on the Vision Transformer network model uses cosine distance to measure the similarity between tokens and obtains the similarity judgment result of the second tokens. The tokens are fused based on the similarity judgment results of the first tokens and the similarity judgment results of the second tokens; All tokens input to the token fusion module are equally divided to obtain a first partition set and a second partition set. The cosine distance between the output features of the self-attention module of the Vision Transformer network model and the output features of the multilayer perceptron module of the Vision Transformer network model is calculated to obtain the cosine distance value. Based on the cosine distance value, the tokens in the first partition set and the second partition set are compared one by one to obtain the comparison result; Select tokens from the comparison results that exceed a preset similarity threshold and mark them with borders; The tokens with marked edges are merged, and their feature information is averaged and concatenated for matching to obtain the similarity matching results between the tokens. Define a row vector that contains the size of each token; Based on the similarity matching results between tokens, the row vectors are added to the self-attention module of the Vision Transformer network model, and the self-attention weights of the Vision Transformer network model are adjusted. The adjusted self-attention module is then updated to the Vision Transformer network model to obtain the optimized Vision Transformer network model. The surface defect detection results of the patch inductor surface defect dataset are obtained by performing surface defect detection on the optimized Vision Transformer network model.
2. The method for detecting surface defects of patch inductors based on token fusion according to claim 1, characterized in that, The step of obtaining the patch inductor defect dataset specifically includes: Image acquisition and processing are performed on the surface mount inductors on the production line to obtain the raw dataset of surface mount inductors; Data augmentation processing is performed on the original dataset of surface mount inductors to obtain the augmented dataset of surface mount inductors. By using image annotation software, the patch inductors with surface defects in the enhanced patch inductor dataset are labeled to obtain the patch inductor defect dataset.
3. The method for detecting surface defects of patch inductors based on token fusion according to claim 2, characterized in that, The expression for adjusting the attention weights of the Vision Transformer network is: ; In the above formula, Indicates the scaling factor. Indicates Query, Indicates Key, Represents a row vector. This represents the transpose of a matrix.
4. The method for detecting surface defects of patch inductors based on token fusion according to claim 3, characterized in that, The step of performing surface defect detection processing on the patch inductor defect dataset based on the optimized Vision Transformer network model to obtain the patch inductor surface defect detection results specifically includes: The patch inductor defect dataset is input into the optimized Vision Transformer network model, which includes a patch layer, a linear mapping layer, an embedding layer, a first LN layer, a self-attention layer, a token fusion layer, a multilayer perceptron layer, a second LN layer, and a classification layer. The patch inductor defect dataset is segmented based on the patch layer to obtain the segmentation results. The segmentation results are linearly mapped using a linear mapping layer to obtain a dimensionality-reduced result. The positional encoding process is performed on the reduced-dimensional result based on the embedding layer to obtain the encoded result; Based on the first LN layer, the variance and mean of the encoding result are calculated to obtain the first calculation result; The encoding results are mapped to Q, K, and V values based on the self-attention layer, and grouped according to the number of attention heads to obtain the grouping results; The first calculation result and the grouping result are added together and then input into the token fusion layer for averaging. That is, the tokens are matched for similarity using a binary soft matching algorithm to obtain the matching result. The matching results are scaled based on the multilayer perceptron layer to obtain scaled matching results. The matching result is added to the scaled matching result and then input into the second LN layer for variance and mean calculation to obtain the second calculation result; Based on the second calculation result, image classification processing is performed through the classification layer to obtain the classification result. The classification result includes front chipping, side chipping, insufficient adhesive, poor wire clamping, segment misalignment, and claw floating of the chip inductor.
5. The method for detecting surface defects of patch inductors based on token fusion according to claim 4, characterized in that, It also includes testing the optimized Vision Transformer network model using the test set in the patch inductor defect dataset, and using F1-Score, Recall, and Precision as evaluation metrics for the optimized Vision Transformer network model to determine whether the optimized Vision Transformer network model has reached its optimal state.
6. A surface defect detection system for patch inductors based on token fusion, characterized in that, Includes the following modules: The acquisition module is used to acquire a dataset of defects in patch inductors. The optimization module introduces a token fusion module. The resulting Vision Transformer network model includes a self-attention module, a token fusion module, and a multilayer perceptron module. The key vector Key in the self-attention module of the Vision Transformer network model is used to extract the feature information in the token fusion module, thereby obtaining the feature information of the token fusion module. The feature information in the token fusion module is analyzed by dot product similarity to determine the similarity between tokens and obtain the first token similarity judgment result. The multilayer perceptron module based on the Vision Transformer network model uses cosine distance to measure the similarity between tokens and obtains the similarity judgment result of the second tokens. The tokens are fused based on the similarity judgment results of the first tokens and the similarity judgment results of the second tokens; All tokens input to the token fusion module are equally divided to obtain a first partition set and a second partition set. The cosine distance between the output features of the self-attention module of the Vision Transformer network model and the output features of the multilayer perceptron module of the Vision Transformer network model is calculated to obtain the cosine distance value. Based on the cosine distance value, the tokens in the first partition set and the second partition set are compared one by one to obtain the comparison result; Select tokens from the comparison results that exceed a preset similarity threshold and mark and draw edges on them; The tokens with marked edges are merged, and their feature information is averaged and concatenated for matching to obtain the similarity matching results between the tokens. Define a row vector that contains the size of each token; Based on the similarity matching results between tokens, the row vectors are added to the self-attention module of the Vision Transformer network model, and the self-attention weights of the Vision Transformer network model are adjusted. The adjusted self-attention module is then updated to the Vision Transformer network model to obtain the optimized Vision Transformer network model. The detection module performs surface defect detection processing on the patch inductor defect dataset based on the optimized Vision Transformer network model, and obtains the surface defect detection results of the patch inductor.
Citation Information
Patent Citations
Rice disease identification method based on visual transformer
CN113723312A