Optical communication device surface defect detection network structure based on twin architecture and detection method
Through the optical communication device surface defect detection network based on the twin architecture, using twin ResNet residual network and non-defect feature matching and elimination module and other technologies, the problem of false detection caused by relative position deviation in the optical communication device surface defect detection is solved, and the Accurate segmentation and efficient detection of surface defects in optical communication devices.
Patent Information
- Application Number
- CN202410607048.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-16
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-05-16
AI Technical Summary
Existing optical communication device surface defect detection technology cannot accurately distinguish relative position deviations that are not defects, leading to misdetection on the production line and reducing detection accuracy.
An optical communication device surface defect detection network based on the twin architecture is adopted, including a feature extraction encoder and a feature fusion decoder. Multi-scale features are extracted through the twin ResNet residual network. The non-defect feature matching elimination module eliminates non-defect features and the defect feature enhancement module Enhance differential features and achieve accurate segmentation of defective areas through multi-layer perceptrons.
It significantly improves the accuracy and efficiency of surface defect detection of optical communication devices, reduces the false alarm rate of the production line, can accurately segment various types of defects, and weakens the impact of relative position deviation on detection.
Smart Images

Figure CN118570133A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field related to image processing, and more specifically, relates to a surface defect detection network structure and detection method for optical communication devices based on a twin architecture. Background Art
[0002] Optical communication devices are the core components of optical communication equipment. They are mainly used for the conversion between photoelectric signals and are widely used in industrial control systems, the Internet, mobile communications and other fields. The quality of optical communication devices directly affects the overall performance of optical communication equipment. In the automated production and manufacturing process of optical communication devices, surface defect detection is a crucial step. In the production and processing of optical communication devices, due to their complex processes, they are easily affected by factors such as production equipment, processing technology and human operation, resulting in defects and unqualified quality. Therefore, it is crucial to screen out unqualified optical communication devices through visual inspection methods.
[0003] Optical communication device defects are of various types and shapes, making segmentation extremely difficult. During the production process, conventional defects with significant characteristics such as contamination, scratches, bruises, and breakages are prone to occur, as well as special defects such as missed or wrong solder joints and wires. Because the characteristics of solder joints and wires themselves are not defects, only by using the same model of non-abnormal optical communication devices as templates and finding the difference between the two samples can it be determined whether the optical communication device to be tested has abnormal conditions such as missed or wrong solder joints and wires. For such special defects, single defect segmentation networks such as U-Net and SegFormer that are only trained based on defect samples cannot perform effective detection. In order to accurately detect defects such as "missing wires" and "wrong wires" that may exist in optical communication devices, a change detection network that aims to find the difference between the two input images is required.
[0004] At present, ChangeFormer is one of the best-performing change detection models. It is a twin network based on the Transformer architecture. ChangeFormer uses the Transformer's self-attention mechanism to capture the long-distance dependencies between image features; it uses a parameter-sharing twin network structure to process input images, so that the model can learn the differences between two input images. This method provides a detection method for abnormal conditions such as "missing lines" and "wrong lines" in optical communication devices. However, in addition to the above-mentioned abnormal conditions of "missing lines" and "wrong lines", the optical communication device to be tested may also have relative position offsets of patch components, solder joints and solder wires relative to the template optical communication device sample. This type of position offset does not affect the working performance of the optical communication device and is not a defect or abnormality.
[0005] However, the ChangeFormer change detection network used in the prior art will report such position offsets as defects through direct change detection logic, which will eventually cause large-scale false detections on the production line and seriously reduce the detection accuracy of the optical communication device production line. Summary of the invention
[0006] In view of the defects of related technologies, the purpose of the present invention is to provide a network structure and detection method for surface defect detection of optical communication devices based on a twin architecture, aiming to solve the problem that existing detection technologies misjudge features caused by relative position offsets that are not defects, resulting in false alarms on production lines and inability to accurately detect surface defects that affect the working performance of optical communication devices.
[0007] To achieve the above-mentioned object, in a first aspect, the present invention provides a surface defect network structure of an optical communication device based on a twin architecture, comprising: a feature extraction encoder and a feature fusion decoder;
[0008] The feature extraction encoder includes a twin ResNet residual network, a non-defect feature matching elimination module and a defect feature enhancement module;
[0009] The twin ResNet residual network is used to extract multi-scale features from the input sample image to be tested and the template sample image, and output five sets of feature maps of different scales respectively; the sample image to be tested and the template sample image are obtained by splicing the coaxial light and low ring light images of the template sample and the sample to be tested through the channel dimension;
[0010] The non-defect feature matching elimination module is used to set the feature strength of the corresponding position of the matching point in the two feature maps of the same scale in the four sets of feature maps of non-maximum scale to 0, so as to obtain the difference feature map of the corresponding scale; the non-defect feature matching elimination module is also used to perform a subtraction operation on the feature map of the maximum scale in the sample to be tested and the template sample, so as to obtain the difference feature map;
[0011] The defect feature enhancement module is used to enhance the defect features of the difference feature map and output the difference feature map after defect enhancement;
[0012] The feature fusion decoder is used to unify the scale, concatenate and compress the channels of five different scale difference feature maps to fuse the multi-scale features and output the defect area segmentation result.
[0013] Optionally, the twin ResNet residual network includes two ResNet residual networks with consistent structures and shared weights; the twin ResNet residual network cancels the maximum pooling layer before the output of the first layer of ResNet.
[0014] Optionally, the scales of the difference feature maps of five groups of different scales are 64 dimensions×128 pixels×128 pixels, 64 dimensions×64 pixels×64 pixels, 128 dimensions×32 pixels×32 pixels, 256 dimensions×16 pixels×16 pixels, and 512 dimensions×8 pixels×8 pixels.
[0015] Optionally, the non-defect feature matching and elimination module includes a feature sequence generation submodule, a lightweight Transformer architecture, a feature matching submodule and a matching feature elimination submodule;
[0016] The input of the non-defect feature matching elimination module is four sets of feature maps with a non-maximum scale of C dimension × W pixels × W pixels in the sample to be tested and the template sample;
[0017] The feature sequence generation submodule is used to flatten the two input feature maps of the same scale into a length of W. 2 The characteristic sequence of
[0018] The Transformer architecture is used to process the feature sequences of the test sample feature map and the template sample feature map by self-attention mechanism and cross-attention mechanism respectively, and repeat the process N times in sequence to obtain the processed feature sequence;
[0019] The feature matching submodule is used to construct a similarity matrix according to the similarity of the feature sequences of the sample to be tested and the template sample; after the similarity matrix is normalized, matching points with high similarity are obtained by threshold screening, and then matching points with high confidence are screened from the matching points with high similarity according to the mutual nearest neighbor principle, and a matching point index set of the feature graphs of the sample to be tested and the template sample is obtained according to the final matching result;
[0020] The matching feature elimination submodule creates a test sample mask matrix and a template sample mask matrix of W pixels×W pixels of the same size as the feature map according to the matching point index set, sets the value of the corresponding matching point index position in the mask matrix to 0, and sets the remaining positions to 1, multiplies the test sample mask matrix and the template sample mask matrix with the feature vectors of the corresponding positions of the input test sample feature map and template sample feature map, respectively, to obtain the test sample feature map and the template sample feature map with the non-defect features successfully matched eliminated, obtains the difference features, and obtains the difference feature map of the corresponding scale.
[0021] Optionally, feature maps of different scales correspond to different N values, and the smaller the scale of the feature map, the larger N is.
[0022] Optionally, the defect feature enhancement module is composed of a Transformer encoder-decoder and a convolutional triplet attention module;
[0023] The Transformer codec is used to enhance defect features on five difference feature maps of different scales, and output five difference feature maps of different scales containing global context information and enhanced defect features;
[0024] The convolution triplet attention module is used to calculate the weighted attention weights of multiple dimensions of the enhanced difference feature map, and apply the weighted attention weights to the difference feature maps of the corresponding dimensions respectively, and output the difference feature map after defect enhancement.
[0025] Optionally, the multi-layer perceptron module includes a first multi-layer perceptron, an upsampling submodule, a channel splicing submodule, a second multi-layer perceptron, a two-dimensional transposed convolutional layer and a segmentation head;
[0026] The first multi-layer perceptron is used to unify the channels of the five difference feature maps of different scales into 64 dimensions to obtain five difference feature maps of different scales;
[0027] The upsampling submodule is used to upsample four difference feature maps with scales of 64 dimensions × 64 pixels × 64 pixels, 64 dimensions × 32 pixels × 32 pixels, 64 dimensions × 16 pixels × 16 pixels, and 64 dimensions × 8 pixels × 8 pixels to a size of 128 pixels × 128 pixels by bicubic interpolation, thereby obtaining five difference feature maps with a scale of 64 dimensions × 128 pixels × 128 pixels;
[0028] The channel stitching submodule is used to stitch the five difference feature maps together in the channel dimension after upsampling, so as to obtain a difference feature map with a scale of 320 dimensions × 128 pixels × 128 pixels;
[0029] The second multi-layer perceptron is used to compress the number of channels of the feature map from 320 to 64 to enable multi-scale feature fusion.
[0030] The two-dimensional transposed convolution layer upsamples the fused feature map and adjusts the size to 256 pixels×256 pixels to obtain a feature map with a scale of 64 dimensions×256 pixels×256 pixels;
[0031] The segmentation head is used to predict the category of "defect" and "non-defect" for each pixel in the input 64-dimensional × 256 pixels × 256 pixels feature map, and obtain a binary defect segmentation result image with a size of 256 pixels × 256 pixels; wherein, the black area with a pixel value of 0 represents the normal area, and the white area with a pixel value of 255 represents the defective area.
[0032] In a second aspect, the present invention further provides a method for detecting surface defects of an optical communication device based on a twin architecture, applying a network structure as described in any one of the first aspects, comprising:
[0033] Obtain images of the template sample and the sample to be tested under coaxial light and low-annular light illumination, and obtain the sample to be tested image and the template sample image respectively after channel dimension splicing;
[0034] The template sample image and the sample image to be tested are input into a surface defect detection network for optical communication devices based on a twin architecture, and a defect area segmentation result is output.
[0035] Compared with the prior art, the above technical solution conceived by the present invention can achieve the following beneficial effects:
[0036] 1. The present invention provides a surface defect detection network for optical communication devices based on a twin architecture. The surface defect detection network for optical communication devices based on a twin architecture is adopted. The idea of change detection is used to construct a data set consisting of a sample to be tested and a template sample under two types of illumination, coaxial light and low-ring light. The multi-scale image features of the two samples are extracted simultaneously by using an improved ResNet residual network, and the non-defect features in the feature map of the sample to be tested and the feature map of the template sample are eliminated. The difference features of the sample to be tested and the template sample are obtained through change detection, and the difference features are regarded as defect features. The five difference feature maps of different scales are subjected to defect feature enhancement processing, and then input into a multi-layer perceptron to output the segmentation result of the final defect area. The defect detection network of this scheme can accurately segment various defects in the scenario where there are many types of defects in optical communication devices, various shapes, and there is a relative position offset among the patch components, solder joints and solder wires. At the same time, it can weaken the non-defect features caused by the relative position offset between the sample to be tested and the template sample, and realize the accurate and rapid segmentation of the surface defect area of the optical communication device, which significantly improves the efficiency and accuracy of surface defect segmentation and defect detection of optical communication devices.
[0037] 2. The present invention provides a surface defect detection network for optical communication devices based on a twin architecture, in which a non-defect feature matching elimination module (Feature Matching for Non-defect Elimination, FMNE) is designed. A lightweight Transformer architecture is designed in the non-defect feature matching elimination module. While reducing the consumption of computing resources, by generating a mask matrix, the non-defect features caused by the relative offset of solder joints, solder wires, and chip components commonly present in optical communication devices are weakened. The segmentation detection accuracy on the optical communication device data set is much higher than the existing conventional segmentation model. In the process of extracting the difference features between the sample to be tested and the template sample, the non-defect feature matching elimination module in the network is used to eliminate the non-defect features in the difference features; the defect feature enhancement module is used to enable the network to accurately capture the large-span defects and small-area defect features in the sample; the lightweight multi-layer perceptron is used to realize the fusion of multi-scale difference features, and finally the final defect segmentation result is obtained through the segmentation head.
[0038] 3. The present invention provides a surface defect detection network for optical communication devices based on a twin architecture, which adopts an optical communication device defect feature enhancement module, integrates low-level detail information and high-level semantic information in the difference feature map extracted by the twin network, and captures important feature information across dimensions in the feature map. It can generate feature maps with richer information and more distinct defect features, so that the defect segmentation accuracy and performance of the network designed by the present invention are higher.
[0039] 4. The present invention provides a surface defect detection network for optical communication devices based on a twin architecture, wherein the surface defect detection network fuses feature information of five feature maps of different scales through a lightweight multi-layer perceptron. Compared with the conventional segmentation network that only uses the highest-dimensional feature map for upsampling to obtain the final segmentation result, the network defect segmentation accuracy designed by the present invention is significantly improved.
[0040] 5. The present invention provides a method for detecting surface defects of optical communication devices based on a twin architecture, which uses an improved ResNet residual network to simultaneously extract multi-scale image features of two samples, eliminates non-defect features in the feature map of the sample to be tested and the feature map of the template sample, obtains difference features, and processes five difference feature maps of different scales through defect feature enhancement processing and multi-layer perceptron processing to obtain the final segmentation result of the defect area, thereby realizing surface defect detection. This solution can realize accurate segmentation and detection of various defects, greatly reduce the false alarm rate of the optical communication device production line, realize accurate and rapid segmentation and detection of surface defect areas of optical communication devices, and significantly improve the efficiency and accuracy of surface defect segmentation and defect detection of optical communication devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 It is a schematic diagram of the structure of a surface defect detection network for optical communication devices based on a twin architecture provided by an embodiment of the present invention;
[0042] Figure 2 is a schematic diagram of a non-defect feature matching and elimination module provided in an embodiment of the present invention;
[0043] Figure 3 is a schematic diagram of a lightweight Transformer in a non-defect feature matching and elimination module provided in an embodiment of the present invention;
[0044] Figure 4 It is a schematic diagram of the working principle of the mask matrix in the non-defect feature matching elimination module provided by an embodiment of the present invention;
[0045] Figure 5 is a test sample and defect segmentation result provided by an embodiment of the present invention;
[0046] Figure 6is a schematic diagram of relative position offset of an optical communication device provided by an embodiment of the present invention;
[0047] Figure 7 It is a visualization effect diagram of the non-defect feature matching and elimination module provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0049] The contents involved in the above embodiment are described below in conjunction with a preferred embodiment.
[0050] Embodiment 1
[0051] A network structure for detecting surface defects of optical communication devices based on a twin architecture, comprising: a feature extraction encoder and a feature fusion decoder;
[0052] The feature extraction encoder includes a twin ResNet residual network, a non-defect feature matching elimination module and a defect feature enhancement module;
[0053] The twin ResNet residual network is used to extract multi-scale features from the input sample image to be tested and the template sample image, and output five sets of feature maps of different scales respectively; the sample image to be tested and the template sample image are obtained by splicing the coaxial light and low ring light images of the template sample and the sample to be tested through the channel dimension;
[0054] The non-defect feature matching elimination module is used to set the feature strength of the corresponding position of the matching point in the two feature maps of the same scale in the four sets of feature maps of non-maximum scale to 0, so as to obtain the difference feature map of the corresponding scale; the non-defect feature matching elimination module is also used to perform a subtraction operation on the feature map of the maximum scale in the sample to be tested and the template sample, so as to obtain the difference feature map;
[0055] The defect feature enhancement module is used to enhance the defect features of the difference feature map and output the difference feature map after defect enhancement;
[0056] The feature fusion decoder is used to unify the scale, concatenate and compress the channels of five different scale difference feature maps to fuse the multi-scale features and output the defect area segmentation result.
[0057] Based on the problems existing in the existing technology, there is an urgent need to develop an optical communication device defect detection method that can not only cope with the various types and shapes of surface defects of optical communication devices, but also reduce the impact of relative position offset on defect detection tasks, so as to achieve accurate detection of surface defects of various optical communication devices.
[0058] like Figure 1 As shown, an embodiment of the present invention discloses a surface defect detection network for optical communication devices based on a twin architecture, which is used to detect and segment surface defects of various types and shapes in optical communication devices. At the same time, it can weaken the non-defect features caused by the relative position offset between the sample to be tested and the template sample, avoid large-scale false alarms in the production line, and achieve accurate and rapid segmentation of surface defect areas of optical communication devices, significantly improving the defect segmentation efficiency and accuracy of optical communication devices. By adopting the change detection concept, the designed network structure learns how to find the difference between the template sample image and the sample image to be tested by comparison, and regards the difference features between the two as defect features; among them, the main difficulty of change detection is that between the template sample image and the sample image to be tested, in addition to the defect features, there is also the problem of relative position offset of components such as solder joints and solder wires.
[0059] The defect detection network feature extraction encoder is composed of an improved twin ResNet residual network, a non-defect feature matching elimination module, and a defect feature enhancement module. Among them, the five groups of different scales of the difference feature map scales are 64 dimensions × 128 pixels × 128 pixels, 64 dimensions × 64 pixels × 64 pixels, 128 dimensions × 32 pixels × 32 pixels, 256 dimensions × 16 pixels × 16 pixels, and 512 dimensions × 8 pixels × 8 pixels.
[0060] The twin ResNet residual network in the embodiment of the present application includes two ResNet residual networks with consistent structure and shared weights; on this basis, the present invention cancels the maximum pooling layer before the first layer output of the ResNet residual network, and adjusts the scale of the first layer output feature map from 64 dimensions × 64 pixels × 64 pixels to 64 dimensions × 128 pixels × 128 pixels; at the same time, in order to reduce the amount of network parameters and make the network as lightweight as possible, the present invention replaces the standard convolution layer in ResNet with a depth-separable convolution, while retaining the residual connection. The ResNet-34 network is used in the embodiment of the present application. The scales of the five groups of feature maps of different scales can change with the number of layers of the ResNet variant network. In alternative embodiments, variants of ResNet networks such as ResNet-18, ResNet-50, and ResNet-101 can also be used.
[0061] The network designed in this embodiment first extracts multi-scale features of the sample image to be tested and the template sample image; four sets of feature maps with scales of 64 dimensions × 64 pixels × 64 pixels, 128 dimensions × 32 pixels × 32 pixels, 256 dimensions × 16 pixels × 16 pixels, and 512 dimensions × 8 pixels × 8 pixels in the multi-scale feature maps of the two samples are input into Figure 2 and Figure 3 In the non-defect feature matching elimination module shown in the figure, non-defect feature matching elimination is performed to weaken the non-defect features caused by the relative position offset between the sample to be tested and the template sample, and obtain the difference feature map at the corresponding scale. Then, the difference feature of the sample to be tested and the template sample with a scale of 64 dimensions × 128 pixels × 128 pixels is obtained by directly performing a difference operation. The difference feature map and the four difference feature maps obtained by the non-defect feature matching elimination module are respectively input into the defect feature enhancement module to highlight the defect features. Finally, the feature maps of the five scales after the defect features are enhanced are input into the lightweight feature fusion decoder to output the segmentation result of the final defect area.
[0062] The template sample image and the sample image to be tested, which are spliced in the channel dimension by images under coaxial light and low-ring light, are input into the surface defect detection network of optical communication devices based on the twin architecture. The improved twin ResNet backbone network simultaneously extracts multi-scale features of the template sample and the sample to be tested, and outputs five groups of feature maps of different scales. The feature map scales are 64 dimensions × 128 pixels × 128 pixels, 64 dimensions × 64 pixels × 64 pixels, 128 dimensions × 32 pixels × 32 pixels, 256 dimensions × 16 pixels × 16 pixels, and 512 dimensions × 8 pixels × 8 pixels.
[0063] Optionally, the non-defect feature matching and elimination module includes a feature sequence generation submodule, a lightweight Transformer architecture, a feature matching submodule and a matching feature elimination submodule;
[0064] The input of the non-defect feature matching elimination module is four sets of feature maps with a non-maximum scale of C dimension × W pixels × W pixels in the sample to be tested and the template sample;
[0065] The feature sequence generation submodule is used to flatten the two input feature maps of the same scale into a length of W. 2 The characteristic sequence of
[0066] The Transformer architecture is used to process the feature sequences of the test sample feature map and the template sample feature map by self-attention mechanism and cross-attention mechanism respectively, and repeat the process N times in sequence to obtain the processed feature sequence;
[0067] The feature matching submodule is used to construct a similarity matrix according to the similarity of the feature sequences of the sample to be tested and the template sample; after the similarity matrix is normalized, matching points with high similarity are obtained by threshold screening, and then matching points with high confidence are screened from the matching points with high similarity according to the mutual nearest neighbor principle, and a matching point index set of the feature graphs of the sample to be tested and the template sample is obtained according to the final matching result;
[0068] The matching feature elimination submodule creates a test sample mask matrix and a template sample mask matrix of W pixels×W pixels of the same size as the feature map according to the matching point index set, sets the value of the corresponding matching point index position in the mask matrix to 0, and sets the remaining positions to 1, multiplies the test sample mask matrix and the template sample mask matrix with the feature vectors of the corresponding positions of the input test sample feature map and template sample feature map, respectively, to obtain the test sample feature map and the template sample feature map with the non-defect features successfully matched eliminated, obtains the difference features, and obtains the difference feature map of the corresponding scale.
[0069] The four sets of feature maps with scales of 512×8×8 pixels, 256×16×16 pixels, 128×32×32 pixels, and 64×64×64 pixels in the test samples and template samples are input into Figure 2 In the Feature Matching for Non-defect Elimination (FMNE) module shown in the figure, two feature maps of the same scale are flattened into sequences respectively, and then used Figure 3 The lightweight Transformer shown in the figure obtains the feature sequences of the sample to be tested and the template sample after being processed by the self-attention and cross-attention mechanisms, regards the feature sequences as feature vectors, obtains the similarity between the feature vectors through the vector inner product operation, and constructs a similarity matrix. According to the similarity matrix and the mutual nearest neighbor matching principle, the matching point index set of the two feature sequences is obtained, and then the mask matrix of the sample to be tested and the mask matrix of the template sample of the same size as the sample feature map are created. Figure 4 As shown in the figure, the mask matrix is multiplied by the feature vector at the corresponding position of the feature map, the feature intensity at the corresponding position of the matching point is set to 0, and the features of the successfully matched features of the sample to be tested and the template sample are eliminated respectively. Then, the difference features of the corresponding scales of the sample to be tested and the template sample after matching and eliminating the non-defect features are obtained, and four difference feature maps with scales of 512 dimensions × 8 pixels × 8 pixels, 256 dimensions × 16 pixels × 16 pixels, 128 dimensions × 32 pixels × 32 pixels, and 64 dimensions × 64 pixels × 64 pixels are obtained. The difference feature map has largely eliminated the image features that match between the sample to be tested and the template sample, while retaining the defect features on the sample to be tested.
[0070] Optionally, feature maps of different scales correspond to different N values, and the smaller the scale of the feature map, the larger N. In this embodiment, when the feature map scale is 512 dimensions × 8 pixels × 8 pixels, N is 4; when the feature map scale is 256 dimensions × 16 pixels × 16 pixels, 128 dimensions × 32 pixels × 32 pixels, and 64 dimensions × 64 pixels × 64 pixels, N is 2.
[0071] Use Figure 3 The lightweight Transformer shown applies the self-attention mechanism to the feature map of the sample to be tested and the feature map of the template sample, and then applies the cross-attention mechanism to the feature map of the sample to be tested and the feature map of the template sample, and repeats the self-attention and cross-attention mechanisms N times in sequence. Through the application of the self-attention and cross-attention mechanisms, an enhanced feature sequence is obtained after the relative position information and global context information of the sample to be tested and the template sample are integrated.
[0072] Specifically, Figure 3 As shown in the figure, the lightweight Transformer first obtains the query vector through feature sequence A, and obtains the key vector and value vector through feature sequence B. Taking the feature sequence of the sample to be tested as an example, when self-attention is performed on the feature sequence of the sample to be tested, feature sequence A and feature sequence B are the same, both of which are feature sequences of the sample to be tested. When cross-attention is performed on the feature sequence of the sample to be tested, feature sequence A is the feature sequence of the sample to be tested, and feature sequence B is the feature sequence of the template sample.
[0073] The query vector, key vector and value vector are generated as follows:
[0074] Q=UW Q ,K=RW K ,V=RW V
[0075] Among them, U and R represent Figure 3 The characteristic sequence A and characteristic sequence B shown, W Q , W K , W V are the learnable weights of feature transformation.
[0076] The self-attention mechanism and cross-attention operation of the lightweight Transformer are performed as follows:
[0077]
[0078] in, It represents the template sample feature sequence of scale i after adding position encoding, and is used represents the feature sequence of the sample to be tested with scale i after adding position encoding, Atten self Represents the self-attention mechanism, Attencross represents the cross attention mechanism, Represents the feature map of the template sample at scale i after self-attention and cross-attention mechanisms. Represents the feature map of the sample to be tested at scale i after self-attention and cross-attention mechanisms.
[0079] The obtained feature sequences of the sample to be tested and the template sample are regarded as feature vectors, and the inner product operation between the vectors is performed to obtain the similarity matrix. Then the Softmax operator is applied on the row and column dimensions to normalize the similarity matrix. The matching points with high similarity are obtained through threshold screening, and then the matching points with high confidence are further screened according to the mutual nearest neighbor principle. The index of each matching point in the feature map of the sample to be tested and the template sample is obtained according to the final matching result.
[0080] like Figure 4 As shown in , create a W pixel × W pixel mask matrix of the sample to be tested and a template sample mask matrix of the same size as the feature map. Eliminate the successfully matched non-defect features, obtain the difference features, and obtain the difference feature map of the corresponding scale as the difference feature map output by the non-defect feature matching elimination module, as shown in Figure 7 shown.
[0081] Optionally, the defect feature enhancement module is composed of a Transformer encoder-decoder and a convolutional triplet attention module;
[0082] The Transformer codec is used to enhance defect features on five difference feature maps of different scales, and output five difference feature maps of different scales containing global context information and enhanced defect features;
[0083] The convolution triplet attention module is used to calculate the weighted attention weights of multiple dimensions of the enhanced difference feature map, and apply the weighted attention weights to the difference feature maps of the corresponding dimensions respectively, and output the difference feature map after defect enhancement.
[0084] Defect feature enhancement includes the following steps: input the difference feature map containing defect features obtained by the non-defect feature matching elimination module into the Transformer codec in the defect feature enhancement module. The encoder of the Transformer codec is responsible for capturing the high-level semantic information in the feature map, while the decoder uses this information to reconstruct a feature map with richer information and more significant defect features. The feature map processed by the Transformer codec integrates the global context information of the feature map, especially for large-area and long-distance defects, to achieve more accurate and complete feature extraction, improving the accuracy and performance of the optical communication device defect detection network. The five feature maps with scales of 64×128 pixels×128 pixels, 64×64 pixels×64 pixels, 128×32 pixels×32 pixels, 256×16 pixels×16 pixels, and 512×8 pixels×8 pixels output by the Transformer decoder are input into the Convolutional Triplet Attention Module (CTAM) in the defect feature enhancement module. The Convolutional Triplet Attention Module captures the cross-dimensional interaction information between the channel C and the space H (height) or W (width), solves the problem of disappearance of the interdependence between the channel dimension and the spatial dimension, and effectively enhances the surface defect features of the optical communication device, obtaining five feature maps with scales of 64×128 pixels×128 pixels, 64×64 pixels×64 pixels, 128×32 pixels×32 pixels, 256×16 pixels×16 pixels, and 512×8 pixels×8 pixels.
[0085] Optionally, the multi-layer perceptron module includes a first multi-layer perceptron, an upsampling submodule, a channel splicing submodule, a second multi-layer perceptron, a two-dimensional transposed convolutional layer and a segmentation head;
[0086] The first multi-layer perceptron is used to unify the channels of the five difference feature maps of different scales into 64 dimensions to obtain five difference feature maps of different scales;
[0087] The upsampling submodule is used to upsample four difference feature maps with scales of 64 dimensions × 64 pixels × 64 pixels, 64 dimensions × 32 pixels × 32 pixels, 64 dimensions × 16 pixels × 16 pixels, and 64 dimensions × 8 pixels × 8 pixels to a size of 128 pixels × 128 pixels by bicubic interpolation, so as to obtain five difference feature maps with a scale of 64 dimensions × 128 pixels × 128 pixels;
[0088] The channel stitching submodule is used to stitch the five difference feature maps together in the channel dimension after upsampling, so as to obtain a difference feature map with a scale of 320 dimensions × 128 pixels × 128 pixels;
[0089] The second multi-layer perceptron is used to compress the number of channels of the feature map from 320 to 64 to enable multi-scale feature fusion.
[0090] The two-dimensional transposed convolution layer upsamples the fused feature map and adjusts the size to 256 pixels×256 pixels to obtain a feature map with a scale of 64 dimensions×256 pixels×256 pixels;
[0091] The segmentation head is used to predict the category of "defect" and "non-defect" for each pixel in the input 64-dimensional × 256 pixels × 256 pixels feature map, and obtain a binary defect segmentation result image with a size of 256 pixels × 256 pixels; wherein, the black area with a pixel value of 0 represents the normal area, and the white area with a pixel value of 255 represents the defective area.
[0092] In a specific embodiment, the steps include:
[0093] Obtain a dataset for surface defect segmentation of optical communication devices. This embodiment targets the image acquisition stage in the process of surface defect segmentation of optical communication devices, and collects 4 types of defect samples of 15 models in optical communication devices, a total of 600 defect sample images, and performs data enhancement on defect samples of each category, so that the dataset size reaches 875 images. The surface defects of optical communication devices in the dataset include categories such as base crushing, base scratches 4, component contamination and damage, too many wrong wires and too few wires, etc. The sample image format is PNG, and the size of each sample image is 256 pixels × 256 pixels. At the same time, sample images of defect-free optical communication devices of the same model are collected as template samples of optical communication devices of this model. The dataset size of template sample images is also 875, which correspond one-to-one to the sample images to be tested, and then the images are divided into training set, test set, and verification set in a ratio of 7:2:1.
[0094] Construct a surface defect segmentation model for optical communication devices based on a twin architecture. The twin backbone network model used in this embodiment is an improved ResNet-34 residual network. The defect segmentation model designed by the present invention can also use ResNet-18, ResNet-50, ResNet-101 and other networks as the twin backbone network.
[0095] For each pixel in the sample image to be tested, since the output result of the neural network is defect or non-defect, it can be equivalent to a binary classification network. Therefore, this embodiment selects a binary classification cross entropy loss function as the loss function of the defect detection network:
[0096]
[0097] Where: P 1i is the probability of each pixel being predicted as a defect. iis the true label of each pixel, and its value is 0 or 255, representing non-defect and defect, respectively. N is the total number of pixels in the image to be tested, and the cross entropy loss function aims to make the defect prediction probability of each pixel as close to the actual label probability as possible.
[0098] This embodiment uses the AdamM algorithm as the model optimizer, and the surface defect detection network is trained for 300 rounds with an initial learning rate of 0.0001.
[0099] The backbone network of the optical communication device surface defect segmentation model based on the twin architecture designed in this embodiment is the ResNet-34 residual network, in which the standard convolution is replaced by a depth-separable convolution, and the activation function after each convolution layer is the RELU function. The fully connected layer is responsible for determining whether each pixel is a defect in the end, and acts as a classifier. In addition to the fully connected layer, the remaining convolution parts are responsible for feature extraction.
[0100] Write a Python program to randomly sort the training samples and evenly distribute them. The batch size of batch training is 16 (unit: sheets). Use the training set in the optical communication device dataset to train the optical communication device surface defect detection network and save the weight parameters of the optimized network model.
[0101] Specifically, this embodiment inputs the training images into the model in batches. When the sum of the gradient descents of all samples in a batch is calculated, a weight update is performed until all batches are updated. The trained model is evaluated using the validation set to obtain the network validation loss value and calculate the IoU (intersection over union of regions of interest). If the IoU is greater than the existing maximum IoU, the parameter weights of the network model for this round are stored and the next iteration is performed; if it is less than the maximum IoU, the next iteration is performed directly. At the same time, the number of iterations of the network model is set to 300, and the training ends after the number of iterations is completed. The optimal network model is obtained and named FSNet_best_model.
[0102] Load the network weights corresponding to FSNet_best_model, test the network performance on the test set, evaluate the defect segmentation accuracy of the defect segmentation model, and calculate the IoU (Intersection over Union of Regions of Interest) of the defect segmentation model. The final test set accuracy is 0.9472, the recall rate is 0.8692, the F1 score is 0.9065, and the IoU is 0.8290, achieving a very accurate surface defect segmentation effect for optical communication devices.
[0103] In an embodiment of the present invention, the image of the optical communication device to be tested and the template sample image, which are spliced in the channel dimension by the image of the coaxial light and the low-ring light, are input into the surface defect detection network, and the multi-scale image features of the two samples are extracted simultaneously by using the improved ResNet residual network, and the non-defect features in the feature map of the sample to be tested and the feature map of the template sample are eliminated to obtain the difference feature map, and the five difference feature maps of different scales are processed by defect feature enhancement, and then input into the lightweight multi-layer perceptron to output the segmentation result of the final defect area. The technical problem that the existing detection technology misjudges the features caused by the relative position offset that does not belong to the defect, causes the production line to be falsely reported, and cannot accurately detect the surface defects that affect the working performance of the optical communication device is solved, and the accurate segmentation of various defects is achieved, which greatly reduces the false alarm rate of the optical communication device production line, and achieves accurate and rapid segmentation of the surface defect area of the optical communication device, which significantly improves the efficiency and accuracy of the surface defect segmentation and defect detection of the optical communication device.
[0104] Embodiment 2
[0105] A method for detecting surface defects of an optical communication device based on a twin architecture, using a network structure as described in any one of the first embodiments, comprising:
[0106] S1, obtaining images of the template sample and the sample to be tested under coaxial light and low-ring light illumination, and respectively obtaining the sample to be tested image and the template sample image after channel dimension splicing;
[0107] S2. Input the template sample image and the sample image to be tested into a surface defect detection network for optical communication devices based on a twin architecture, and output defect area segmentation results.
[0108] The embodiment of the present invention provides a method for detecting surface defects of optical communication devices based on a twin architecture, which is executed based on a network structure for detecting surface defects of optical communication devices based on a twin architecture and has the same functions and beneficial effects. It can solve the problem of the difficulty in accurately segmenting defects caused by the variety of defects and different characteristics in the task of segmenting surface defects of optical communication devices, as well as the problem of large-scale misdetection of the production line caused by the relative position offset of patch components and solder joints and wires in the template sample image and the sample image to be tested.
[0109] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A network structure for surface defect detection of optical communication devices based on twin architecture, characterized in that: include: Feature extraction encoder and feature fusion decoder; The feature extraction encoder includes a twin ResNet residual network, a non-defect feature matching elimination module and a defect feature enhancement module; The twin ResNet residual network is used to extract multi-scale features from the input sample image to be tested and the template sample image, and output five sets of feature maps of different scales respectively; the sample image to be tested and the template sample image are obtained by splicing the coaxial light and low ring light images of the template sample and the sample to be tested through the channel dimension; The non-defect feature matching elimination module is used to set the feature strength of the corresponding position of the matching point in the two feature maps of the same scale in the four sets of feature maps of non-maximum scale to 0, so as to obtain the difference feature map of the corresponding scale; the non-defect feature matching elimination module is also used to perform a subtraction operation on the feature map of the maximum scale in the sample to be tested and the template sample, so as to obtain the difference feature map; The defect feature enhancement module is used to enhance the defect features of the difference feature map and output the difference feature map after defect enhancement; The feature fusion decoder is used to unify the scale, concatenate and compress the channels of five different scale difference feature maps to fuse the multi-scale features and output the defect area segmentation result.
2. The network structure according to claim 1, characterized in that: The twin ResNet residual network includes two ResNet residual networks with consistent structures and shared weights; the twin ResNet residual network cancels the maximum pooling layer before the output of the first layer of ResNet.
3. The network structure according to claim 1, characterized in that: The scales of the five groups of difference feature maps are 64 dimensions × 128 pixels × 128 pixels, 64 dimensions × 64 pixels × 64 pixels, 128 dimensions × 32 pixels × 32 pixels, 256 dimensions × 16 pixels × 16 pixels, and 512 dimensions × 8 pixels × 8 pixels.
4. The network structure according to claim 1, characterized in that: The non-defect feature matching and elimination module includes a feature sequence generation submodule, a lightweight Transformer architecture, a feature matching submodule and a matching feature elimination submodule; The input of the non-defect feature matching elimination module is four sets of feature maps with a non-maximum scale of C dimension × W pixels × W pixels in the sample to be tested and the template sample; The feature sequence generation submodule is used to flatten the two input feature maps of the same scale into a length of W. 2 The characteristic sequence of The Transformer architecture is used to process the feature sequences of the test sample feature map and the template sample feature map by self-attention mechanism and cross-attention mechanism respectively, and repeat the process N times in sequence to obtain the processed feature sequence; The feature matching submodule is used to construct a similarity matrix according to the similarity of the feature sequences of the sample to be tested and the template sample; After the similarity matrix is normalized, the matching points with high similarity are obtained through threshold screening, and then the matching points with high confidence are screened out from the matching points with high similarity according to the mutual nearest neighbor principle, and the matching point index set of the feature graph of the sample to be tested and the template sample is obtained according to the final matching result; The matching feature elimination submodule creates a test sample mask matrix and a template sample mask matrix of W pixels×W pixels of the same size as the feature map according to the matching point index set, sets the value of the corresponding matching point index position in the mask matrix to 0, and sets the remaining positions to 1, multiplies the test sample mask matrix and the template sample mask matrix with the feature vectors of the corresponding positions of the input test sample feature map and template sample feature map, respectively, to obtain the test sample feature map and the template sample feature map with the non-defect features successfully matched eliminated, obtains the difference features, and obtains the difference feature map of the corresponding scale.
5. The network structure according to claim 4, characterized in that: Feature maps of different scales correspond to different N values. The smaller the scale of the feature map, the larger N is.
6. The network structure according to claim 1, characterized in that: The defect feature enhancement module consists of a Transformer encoder-decoder and a convolutional triplet attention module; The Transformer codec is used to enhance defect features on five difference feature maps of different scales, and output five difference feature maps of different scales containing global context information and enhanced defect features; The convolution triplet attention module is used to calculate the weighted attention weights of multiple dimensions of the enhanced difference feature map, and apply the weighted attention weights to the difference feature maps of the corresponding dimensions respectively, and output the difference feature map after defect enhancement.
7. The network structure according to claim 1, characterized in that: The multi-layer perceptron module includes a first multi-layer perceptron, an upsampling submodule, a channel splicing submodule, a second multi-layer perceptron, a two-dimensional transposed convolutional layer and a segmentation head; The first multi-layer perceptron is used to unify the channels of the five difference feature maps of different scales into 64 dimensions to obtain five difference feature maps of different scales; The upsampling submodule is used to upsample four difference feature maps with scales of 64 dimensions × 64 pixels × 64 pixels, 64 dimensions × 32 pixels × 32 pixels, 64 dimensions × 16 pixels × 16 pixels, and 64 dimensions × 8 pixels × 8 pixels to a size of 128 pixels × 128 pixels by bicubic interpolation, thereby obtaining five difference feature maps with a scale of 64 dimensions × 128 pixels × 128 pixels; The channel stitching submodule is used to stitch the five difference feature maps together in the channel dimension after upsampling, so as to obtain a difference feature map with a scale of 320 dimensions × 128 pixels × 128 pixels; The second multi-layer perceptron is used to compress the number of channels of the feature map from 320 to 64 to enable multi-scale feature fusion. The two-dimensional transposed convolution layer upsamples the fused feature map and adjusts the size to 256 pixels×256 pixels to obtain a feature map with a scale of 64 dimensions×256 pixels×256 pixels; The segmentation head is used to predict the category of "defect" and "non-defect" for each pixel in the input 64-dimensional × 256-pixel × 256-pixel feature map, and obtain a binary defect segmentation result image with a size of 256 pixels × 256 pixels; wherein the black area with a pixel value of 0 represents a normal area, and the white area with a pixel value of 255 represents a defective area.
8. A method for detecting surface defects of optical communication devices based on a twin architecture, using a network structure as described in any one of claims 1 to 7, characterized in that: include: Obtain images of the template sample and the sample to be tested under coaxial light and low-annular light illumination, and obtain the sample to be tested image and the template sample image respectively after channel dimension splicing; The template sample image and the sample image to be tested are input into a surface defect detection network for optical communication devices based on a twin architecture, and a defect area segmentation result is output.
Citation Information
Patent Citations
Artistic text image generation method based on neural style migration
CN111553837A
Moving target detection method based on data distribution difference and multi-scale feature fusion
CN115294177A
Cited By
Surface defect detection method and system based on multi-light-source fusion and related products
CN119323545A
Surface defect detection method, system and related products based on multi-light source fusion
CN119323545B
Digital twinning-based multi-scale defect visual detection method for high-pressure oil pipe of motor vehicle
CN119416663A
Multi-scale defect visual inspection method for high-pressure fuel pipes of motor vehicles based on digital twins
CN119416663B
PCB defect detection method and device, storage medium and electronic equipment
CN119904429A
