Component identification model construction method combining space structure prior and Transform self-attention

By combining the spatial structure prior and Transformer self-attention, the component recognition model solves the problem of low component recognition accuracy in complex mechanical equipment, achieves high-accuracy identification of key components, reduces the missed detection rate, and satisfies industrial applications. needs.

CN118570127APending Publication Date: 2024-08-30HUAZHONG UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410589418.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-13
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

In the component recognition scenario of complex mechanical equipment, it is difficult for existing target detection networks to accurately identify key components, especially defective components, resulting in missed detection problems and failing to meet the requirements of industrial applications.

Method used

A component recognition model that combines spatial structure prior and Transformer self-attention, extracts and fuses spatial structure information in the image through the spatial structure prior mask generation unit and Transformer encoder, improves the baseline component recognition network, and enhances the recognition of key components. Detection capabilities.

Benefits of technology

It improves the accuracy of component identification, reduces the missed detection rate of key components, and improves the accuracy of defect detection. In particular, it effectively utilizes prior knowledge of spatial structure in complex mechanical equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118570127A
    Figure CN118570127A
Patent Text Reader

Abstract

The invention belongs to the technical field of computer vision, and particularly relates to a space structure prior and Transform self-attention combined part recognition model construction method, which comprises the following steps of: constructing a space structure prior image according to a routing inspection site of a routing inspection object, and extracting a space structure prior mask of a corresponding dimension from the space structure prior image; fusing the spatial structure prior mask with self-attention to obtain a self-attention mechanism fusing spatial structure prior; wherein the spatial structure priori mask is fused into self-attention by adjusting relative position codes; a spatial structure prior Transform encoder is constructed based on a self-attention mechanism fused with spatial structure prior, and then the spatial structure prior Transform encoder is combined with an existing model to construct a new model. The method can make full use of spatial structure priori knowledge, and improves the part recognition rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer vision technology, and more specifically, relates to a method for constructing a component recognition model combining spatial structure prior and Transformer self-attention. Background Art

[0002] Identifying the various components of precision mechanical equipment in the workshop is crucial for diagnosing its potential defects. Among the many types of defects, in addition to problems caused by foreign matter, most defects are closely related to the condition of the components themselves. Therefore, improving the accuracy of component identification plays a decisive role in improving the effect of defect diagnosis. However, in the component identification scenarios of EMUs, subways, trains, etc., there are problems such as complex component structures, a wide variety of types, and scarcity of defective samples. The widely used target detection network is usually unsatisfactory in its recognition accuracy when dealing with component detection of such equipment, which often results in missed detection of key components, especially key components with defects, which brings serious harm to the defect detection of equipment components and is difficult to meet the requirements of industrial applications.

[0003] In actual industrial environments, such as the bogies of rail transit vehicles, the structures of these complex mechanical equipment are precise and complex, and extremely high accuracy is required for component recognition. However, existing component target recognition methods have problems such as complex component structures and low component detection accuracy. Summary of the invention

[0004] In view of the defects of the prior art and the need for improvement, the present invention provides a method for constructing a component recognition model that combines spatial structure prior and Transformer self-attention, which aims to improve the recognition accuracy of components on complex equipment in the workshop.

[0005] To achieve the above object, according to one aspect of the present invention, a method for constructing a component recognition model combining spatial structure prior and Transformer self-attention is provided, comprising: training a component recognition network using a training sample set to obtain a component recognition model; wherein each training sample comprises: a spatial structure prior image obtained by annotating key components of an inspection image and its corresponding key component label; the component recognition network comprises: a spatial structure prior mask generation unit, a Transformer encoder and a baseline component recognition network;

[0006] The Transformer encoder is arranged at the output end of the feature extraction or feature fusion unit in the baseline component recognition network, and is used to encode the original feature map output by the output end based on the self-attention mechanism to obtain a new feature map, and input the new feature map into the subsequent functional unit in the baseline component recognition network to obtain the component recognition result; the spatial structure prior mask generation unit is used to divide the spatial structure prior image corresponding to each inspection image into multiple image blocks according to the dimension of the original feature map, so as to extract the spatial structure prior mask matrix SSPM with the same dimension as the original feature map from the prior image; the self-attention mechanism is used to construct a relative position encoding matrix B based on the original feature map corresponding to each inspection image, and fuse B with its corresponding SSPM to obtain a relative position encoding matrix Bsspm of the fused spatial structure prior, which is used to calculate the self-attention score matrix; the Transformer encoder performs the encoding based on the self-attention score matrix.

[0007] Furthermore, the spatial structure priori mask matrix SSPM is extracted as follows:

[0008] The image blocks that contain more than half of any key component position frame in the spatial result prior image divided into image blocks are taken as important image blocks, and the remaining image blocks are taken as background image blocks. Two different values ​​are used to represent the important image blocks and the background image blocks respectively, and the absolute position matrix P of the key components is obtained;

[0009] The key component absolute position matrix is ​​expanded in the order of rows and columns to obtain a row vector, and then the transpose of the row vector is matrix-multiplied with the row vector to obtain a spatial structure prior mask matrix SSPM.

[0010] Furthermore, the self-attention mechanism calculates the self-attention score matrix in the following way:

[0011]

[0012] Bsspm=B+B*SSPM;

[0013] Where Attention(Q, K, V) represents the self-attention score matrix, Q represents the query matrix, K represents the keyword matrix, V represents the numerical matrix V, d k Represents the sequence dimension.

[0014] Furthermore, the new feature map is added to the corresponding original feature map and then input into the subsequent functional unit in the baseline component recognition network.

[0015] Furthermore, the baseline component recognition network is YOLOv5.

[0016] Furthermore, the output end is an output end of the backbone feature extraction unit of YOLOv5 for outputting the last layer of high-level language feature map.

[0017] Furthermore, the output ends are all output ends of the neck feature fusion unit of YOLOv5.

[0018] The present invention also provides a device component identification method, comprising:

[0019] Collecting an inspection image, and obtaining a spatial structure prior image corresponding to the inspection image based on the inspection position of the inspection image;

[0020] The spatial structure prior image is input into a component recognition model constructed by a component recognition model construction method combining spatial structure prior and Transformer self-attention as described above to obtain a component recognition result.

[0021] The present invention also provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is executed by a processor, the device where the storage medium is located is controlled to execute a component recognition model construction method combining spatial structure prior and Transformer self-attention as described above and / or a device component recognition method as described above.

[0022] The present invention also provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.

[0023] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects:

[0024] (1) The present invention proposes a component recognition method that combines spatial structure prior and Transformer self-attention. First, the present invention fully explores the spatial structure prior knowledge between components hidden in the inspection image and embeds it into the relative position encoding in the Transformer self-attention mechanism to integrate the Transformer self-attention mechanism that can extract the relative relationship between different regions of the image. Subsequently, a corresponding Transformer encoder is constructed based on the Transformer self-attention mechanism that integrates the spatial structure prior, and the existing baseline component recognition model is improved based on the Transformer encoder to obtain a new component recognition model based on spatial structure prior, which is applied to the actual component recognition scenario. This component recognition model can fully utilize the spatial structure prior knowledge between key components based on the Transformer self-attention mechanism, fully explore the relationship between key components hidden in the inspection image to be tested, make up for the shortcomings of the traditional target detection model in global information extraction, and reduce the algorithm's missed detection of key components. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] Figure 1 A flowchart of a method for constructing a component recognition model combining spatial structure prior and Transformer self-attention provided by an embodiment of the present invention;

[0026] Figure 2 A priori schematic diagram of the spatial structure provided by an embodiment of the present invention;

[0027] Figure 3 A mapping relationship between an inspection image and a priori images provided in an embodiment of the present invention;

[0028] Figure 4 A schematic diagram of the construction of the relative position code B provided in an embodiment of the present invention;

[0029] Figure 5 A schematic diagram of constructing a spatial structure priori mask provided by an embodiment of the present invention;

[0030] Figure 6 A schematic diagram of a self-attention mechanism and a spatial structure prior Transformer encoder integrating spatial structure priors provided in an embodiment of the present invention;

[0031] Figure 7 A schematic diagram of a YOLOv5 network of a baseline component recognition model provided in an embodiment of the present invention;

[0032] Figure 8 A schematic diagram of constructing an improved baseline component recognition network based on a spatial structure prior Transformer provided in an embodiment of the present invention. DETAILED DESCRIPTION

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

[0034] Embodiment 1

[0035] A method for building a component recognition model that combines spatial structure priors and Transformer self-attention, such as Figure 1 As shown, it includes: using a training sample set to train a component recognition network to obtain a component recognition model; wherein each training sample includes: a spatial structure prior image and its corresponding key component label obtained by annotating key components of an inspection image; the component recognition network includes: a spatial structure prior mask generation unit, a Transformer encoder and a baseline component recognition network.

[0036] Among them, the Transformer encoder is set at the output end of the feature extraction or feature fusion unit in the baseline component recognition network, and is used to encode the original feature map output by the output end based on the self-attention mechanism to obtain a new feature map, and input it into the subsequent functional unit in the baseline component recognition network to obtain a component recognition result; the spatial structure prior mask generation unit is used to divide the spatial structure prior image corresponding to each inspection image into multiple image blocks according to the dimension of the original feature map, so as to extract the spatial structure prior mask matrix SSPM with the same dimension as the original feature map from the prior image; the self-attention mechanism is used to construct a relative position encoding matrix B based on the original feature map corresponding to each inspection image, and fuse B with its corresponding SSPM to obtain a relative position encoding matrix Bsspm of the fused spatial structure prior, which is used to calculate the self-attention score matrix; the Transformer encoder performs the above encoding based on the self-attention score matrix.

[0037] The method of this embodiment takes into account the relatively fixed spatial structural relationship between key components. If this spatial structural relationship is used in the prediction, the missed detection of key components can be effectively reduced and the accuracy of defect detection can be improved. Therefore, this embodiment aims to effectively integrate the spatial structural prior knowledge of the equipment, improve the accuracy of component target recognition, and provide a solid foundation for defect diagnosis of complex mechanical equipment.

[0038] Regarding S1 above, the spatial structure prior image is constructed as follows:

[0039] The method of this embodiment can be used to identify components in any precision mechanical equipment, such as high-speed rail EMUs. Now, the mechanical equipment of the high-speed rail EMU bogie group is introduced as an example. The inspection image of the EMU bogie mechanical equipment is collected by the inspection robot. In order to ensure that each key component can be captured clearly and completely, the collection position and angle of each inspection image are carefully designed, with each component structure of the high-speed rail EMU bogie as the center as the inspection site. Therefore, in the normal inspection robot acquisition procedure, there is a relatively fixed spatial structural relationship between the key components in each inspection image. This potential prior relationship is called spatial structure prior (Spatial Structure Priors, SSM). Using the spatial structure prior in the inspection image can significantly improve the network's detection effect on key components, especially for targets with a small number and unclear features that are easy to miss, such as key defective components with unclear features and small components with a relatively small image area.

[0040] exist Figure 2 In, the characteristics of the spatial structure prior image are described in detail. In a typical inspection image, the key components present a relatively fixed spatial structural relationship. Taking the key components in the figure as an example, component A represented by the red box is a double-headed anti-loosening wire, which is more in number and relatively easy to detect; while component B in the green box is a single-headed anti-loosening wire, which is less in number and more prone to missed detection. In order to reduce the missed detection of key components like component B, the method of this embodiment constructs a component recognition model that incorporates spatial structure priors, improves the model's use of global information, and thus reduces missed detections and false detections of similar components B.

[0041] In the actual inspection process, standard inspection images are selected for each inspection location to construct a spatial structure prior image set. At the same time, in order to facilitate the use of the spatial structure prior knowledge of the corresponding inspection location in the actual component recognition application, a corresponding image naming specification is designed for each standard inspection image. In actual applications, the spatial structure prior image of the corresponding inspection location is obtained through the unique mapping of the inspection image name to be detected. The process is as follows: Figure 3 shown.

[0042] In order to apply the spatial structure prior knowledge in the inspection image to the component recognition algorithm, this embodiment proposes to introduce the spatial structure prior knowledge into the self-attention mechanism (English: Self-Attention) in the Transformer encoder.

[0043] Among them, the self-attention mechanism is the core idea of ​​the Transformer encoder-decoder structure which has been very popular in recent years. This attention mechanism was originally designed to capture the relationship between input feature sequences, including their semantic relationship and spatial position relationship. In visual applications, it can better obtain the global semantic information between different regions of the image, making up for the shortcomings of convolutional neural networks in paying attention to global information.

[0044] A standard Transformer encoder-decoder core structure is mainly divided into two points: self-attention and position encoding:

[0045] The self-attention mechanism focuses on the similarity between the input feature sequence X. In the image, it represents the correlation between different image blocks. It is mainly divided into self-attention and multi-head attention.

[0046] First, the input feature sequence X is transformed into three different linear maps, namely W Q , W K , W V , to generate the query matrix Q, keyword matrix K and value matrix V. The specific formula is as follows.

[0047] Q=XW Q , K = XW K , V = XW V

[0048] Secondly, the following formula is used to calculate the self-attention score between the input feature sequences to characterize the similarity between different features in the sequence. Specifically, the query of each vector in the sequence will be multiplied by the key of other vectors in the sequence. At the same time, in order to prevent the inner product of the dot product from being too large, it will be divided by the sequence dimension d k The arithmetic square root of , and finally multiply it by the value Value, and output the final self-attention score.

[0049]

[0050] Finally, in order to obtain richer subspace information from the original feature sequence, the self-attention mechanism is often expanded to a multi-head self-attention mechanism, that is, when generating the query matrix Q, the keyword matrix K, and the numerical matrix V, each attention head corresponds to a set of sub-matrices, each head focuses on a different subspace, and the attention scores of each head are concatenated and then multiplied by the multi-head attention weight matrix W. O The final output sequence is obtained, where the calculation method of the self-attention score of the i-th head and the formula for multi-head attention are as follows.

[0051] h i =Attention(QW i Q , KW iK , VW i V )

[0052] MultiHead(Q,K,V)=Concat(h1,...,h n )W O

[0053] The original input sequence does not contain the position information of the sequence. In sequence semantic analysis, the position change of each feature in the sequence will directly affect the overall semantics. Therefore, it is very important to add position encoding to the input feature sequence. The original Transformer adds a simple one-dimensional position encoding to the input. Its dimension is consistent with the dimension of the input feature sequence. It is directly added to the input feature sequence before entering the self-attention module. The calculation formula is as follows: i is the position of each feature in the sequence, j represents the number of bits corresponding to each value in the position encoding vector, and d feature is the dimension of the feature, and by alternating pairs of sine and cosine functions, a coding vector containing the one-dimensional position information of the feature sequence is formed.

[0054]

[0055]

[0056] Based on the basic theory of spatial structure prior and Transformer self-attention mechanism, how to introduce spatial structure prior knowledge into the self-attention mechanism in the Transformer encoder, so as to enhance the modeling ability of the self-attention mechanism for the long-distance dependency relationship between key components by using spatial structure prior knowledge? To solve this problem, this embodiment proposes the following ideas:

[0057] (1) Considering that the two-dimensional position information of key components is crucial to the component recognition task in the component recognition detection scenario, this embodiment proposes to construct a relative position encoding matrix (Relative Position Bias) with stronger two-dimensional spatial position information representation capability to provide position information for the self-attention mechanism. Based on the relative position information between key components in the spatial structure prior image, a spatial structure prior mask matrix (Spatial Structure Priors Mask, SSPM) is proposed. (2) Based on the spatial structure prior mask matrix SSPM, the relative position encoding matrix B in the Transformer self-attention mechanism is fine-tuned, thereby embedding the spatial structure prior knowledge into the Transformer self-attention mechanism. For the new Transformer self-attention mechanism obtained, this embodiment can also be called a spatial structure prior embedded self-attention module (Spatial Structure Priors Embedded Self-Attention, SSPE-SA). (3) In order to integrate the self-attention mechanism embedded with spatial structure prior knowledge into the component recognition network, this embodiment proposes to use the above-mentioned SSPE-SA to construct a spatial structure prior Transformer encoder (Spatial Structure Priors-Transformer, SSP-T), so as to use the output of the encoder to adjust the existing component recognition model.

[0058] The relative position coding described in (1) is described as follows:

[0059] Relative position encoding is mainly used in visual Transformer encoders, and often achieves better performance than absolute position encoding. For example, the Swin-Transformer encoder uses relative position encoding to replace one-dimensional position encoding and two-dimensional position encoding, and achieves the best performance in visual tasks such as image classification, target detection, and image segmentation. Unlike the practice of adding absolute position encoding directly to the input feature sequence, relative position encoding is directly added to the similarity matrix when calculating the self-attention score matrix. Therefore, relative position encoding can essentially be regarded as a fine-tuning of the self-attention score based on the relative position relationship. The core calculation formula of the self-attention score matrix incorporating relative position encoding is as follows:

[0060]

[0061] Where B represents the relative position encoding matrix.

[0062] The values ​​of the existing relative position encoding matrix B are derived from the learnable relative position offset table B^ , and the two correspond based on the relative position index matrix I, such as Figure 4 As shown, the calculation method of the existing relative position index matrix I is described as follows using a 2*2 input feature map as an example: Figure 4 As shown in , from the original input feature map, we can first get the two-dimensional absolute position matrix of the corresponding image block. The horizontal coordinate of each two-dimensional absolute position in the matrix represents the row position and the vertical coordinate represents the column position. Then, from left to right and from top to bottom, calculate the relative position offset of each image block relative to other image blocks. Specifically, the absolute position index between two image blocks is subtracted to obtain the relative position matrix composed of the relative position offset of each image block relative to all image blocks. Figure 4 As shown, the relative position matrix of each image block is expanded into a vector in the order of rows and columns, and then the vectors after the exhibits corresponding to each image block are spliced ​​to obtain the overall two-dimensional relative position index matrix. For the convenience of indexing, assume that the dimension of the original feature map is M*M, add M-1 to the index coordinate with a range value of [-M+1,M-1], so that its coordinate value becomes [0,2M-2] starting from 0, and multiply the horizontal coordinate by 2M-1, and then add the horizontal and vertical coordinates of the index coordinate to form a simple one-dimensional relative position index matrix with a range of [0,(2M-1)*(2M-1)-1]. Under the 2*2 input feature map, the one-dimensional relative position index matrix has a range of [0,8]. As shown Figure 4 As shown, the one-dimensional relative position index matrix only obtains the index of the relative position type between the Q of each image block and the K of other image blocks, rather than the specific relative position encoding value. The real relative position encoding value is obtained from the relative position offset table B ^ (Relative position bias table) is learned, and its size is (2M-1)*(2M-1), which contains the value of each relative position type. The relative position encoding matrix can obtain the corresponding relative position encoding value through the one-dimensional relative position index matrix, and then it is combined with the self-attention similarity matrix Add together to fine-tune the self-attention score matrix and add relative position information to the recognition network.

[0063] In order to embed spatial structure prior knowledge in the relative position encoding matrix B, the method of this embodiment proposes:

[0064] The existing Transformer self-attention mechanism introduces the relative position encoding matrix B, which takes into account the influence of the relative positions of different regions in the image on the self-attention score. However, in the above-mentioned existing relative position encoding, since the spatial structure prior in the inspection image is not included, the self-attention similarity matrix is ​​only fine-tuned by different relative position types, without considering the difference between different relative positions. For example, in the inspection image, the position relationship between key components is more important, while the relative position relationship between the background is insignificant. Therefore, it is necessary to take certain measures to strengthen the position relationship between key components and curb useless background. To address this problem, this embodiment, based on the existing relative position encoding and the spatial structure prior of the inspection image, proposes a spatial structure prior mask, and adjusts the relative position encoding matrix B through this mask, integrating the spatial structure prior, so that it pays more attention to the relative position relationship between key components in the image and reduces the attention to useless background relationships.

[0065] Preferably, the spatial structure priori mask matrix is ​​calculated as follows:

[0066] like Figure 5 As shown in the figure, the spatial structure prior image contains the position information of key components. In order to make the dimensions of the spatial structure prior mask matrix SSPM to be constructed and the aforementioned relative position encoding matrix B consistent with the dimensions of the input feature map, the spatial structure prior image is first divided into multiple image blocks, whose dimensions are consistent with the dimensions of the input feature map. Here, a 4*4 division method is used as an example. Furthermore, the image blocks containing more than half of any key component position box (IoU) are taken as important image blocks, and the remaining image blocks are taken as background image blocks. The key component absolute position matrix P that is consistent with the inspection image division dimension is obtained, where the important image blocks are set to 1 and the background image blocks are set to 0. This matrix represents the distribution of key components in the overall image.

[0067] Preferably, in order to obtain the relative position relationship between key components, the key component absolute position matrix P is expanded in the order of rows and columns to obtain a row vector, and then the transpose of the row vector is matrix-multiplied with the row vector to obtain the spatial structure prior mask matrix (16*16) between the query Q of each image block and the keyword K of other image blocks. This relative position mask matrix containing the relative position relationship of key components is the spatial structure prior mask matrix (Spatial Structure Priors Mask, SSPM), which is expressed as: SSPM = flatten (P) T flatten(P). That is, the spatial structure prior mask matrix is ​​extracted based on the relative position relationship between the key components in the spatial structure prior image.

[0068] The spatial structure prior mask matrix is ​​as follows Figure 5 As shown in , only the mutual query mask between important image blocks is 1, and the rest are 0, because only the relationship between important image blocks containing key components is focused on by the self-attention mechanism, while the background relationship is expected to be less concerned. At the same time, it can be found from the spatial structure prior mask matrix SSPM that the relative position relationship between important image blocks that truly contain key components is locally concentrated and globally sparse in the overall mask matrix, which is consistent with the relatively small area of ​​key components in the overall image. It also confirms that most of the relative position codes in the relative position coding matrix B obtained by the existing method based on the same input feature map do not actually focus on the key components in the image, but are spent on the relationship between background image blocks that account for a relatively large proportion but do not contain key components.

[0069] Regarding the method described in (2) above, the relative position encoding in the Transformer self-attention mechanism is fine-tuned based on the spatial structure prior mask SSPM, so as to embed the spatial structure prior knowledge into the Transformer self-attention mechanism, and obtain the self-attention module based on spatial structure prior embedding (Spatial Structure Priors Embedded Self-Attention, SSPE-SA), specifically, the relative position encoding matrix B is fine-tuned using the spatial structure prior mask, which can be used as a preferred method, and the specific method is as follows:

[0070] After obtaining the spatial structure prior mask matrix SSPM, the relative position encoding matrix B can be adjusted by using the spatial structure prior knowledge between the key components in SSPM to obtain Figure 6 The Spatial Structure Priors Embedded Self-Attention (SSPE-SA) module shown in the figure combines the spatial structure prior mask SSPM and the relative position encoding matrix, so that the self-attention can better focus on the relative relationship between key components in the inspection image and improve the performance of the model. That is, the spatial structure prior mask is extracted and used to fine-tune the relative position encoding in the Transformer self-attention mechanism, and the spatial structure prior is used to enhance the self-attention mechanism's ability to model long-distance dependencies between key components, which can improve the detection accuracy of key defective components.

[0071] The adjustment rules follow the formula shown below:

[0072]

[0073] Bsspm=B+B*SSPM

[0074] When fine-tuning the Transformer self-attention mechanism, the original relative position encoding matrix B in the self-attention score calculation formula is replaced with the relative position encoding matrix Bsspm embedded with spatial structure prior knowledge. In the specific calculation method of Bsspm, the original relative position encoding matrix B is dot-multiplied with the spatial structure prior mask SSPM. This operation keeps the relative position encoding values ​​between key components unchanged, while the relative position encoding values ​​between background image blocks are cleared. This result is then added to the original relative position encoding matrix B, thereby achieving the purpose of strengthening the relative position encoding between key components and suppressing the relative position encoding between background image blocks.

[0075] The self-attention module SSPE-SA based on spatial structure prior embedding adds the relative position encoding matrix Bsspm embedded with spatial structure prior knowledge to the self-attention similarity matrix. When fine-tuning the self-attention score, it not only pays attention to the impact of different relative position relationships on the results, but also pays more attention to the relative position relationship between key components in the inspection image, so that the spatial structure prior in the inspection image is fully utilized, minimizing the missed inspection of key defective components.

[0076] Regarding the use of the above SSPE-SA in (3) to construct a spatial structure prior Transformer encoder, it can be preferred, and the specific method is as follows:

[0077] In order to better apply the self-attention module SSPE-SA embedded with spatial structure prior knowledge to the existing component recognition model, this embodiment refers to the encoder structure of Transformer and designs the following Figure 6 The Spatial Structure Priors-Transformer (SSP-T) shown in the figure is a spatial structure prior Transformer encoder. The input Inputs is the inspection image feature map obtained after the convolutional neural network feature extraction. According to the dimension of the input feature map, the corresponding spatial structure prior mask SSPM is obtained from the spatial structure prior image, and the relative position code B (obtained by the existing method based on the same inspection image feature map) is obtained to obtain Bsspm. Then, the self-attention similarity matrix is ​​fine-tuned to obtain the self-attention score, and the final output is obtained after residual linking with Inputs through a fully connected neural network.

[0078] Finally, based on the spatial structure prior Transformer encoder, the existing component recognition model is improved as follows:

[0079] Firstly, an existing baseline component recognition model is selected and the spatial structure prior Transformer encoder SSP-T is integrated into the selected baseline component recognition model to improve the baseline component recognition model's ability to extract the global information of spatial structure prior, thereby improving the recognition rate of key components and reducing the missed detection rate.

[0080] The selection process of the baseline component recognition model is as follows:

[0081] In order to better select a suitable baseline component recognition model, this embodiment tests the mainstream baseline component recognition models on the public large-scale target detection dataset COCO and the self-built small EMU bogie component recognition dataset TCD (Train Component Detection) to select the most suitable baseline model. The test environment is the AI ​​server deployed on the EMU site, which is consistent with the actual production environment. The test results are shown in Table 1 below. As a baseline model for target detection, the Faster-RCNN series can meet the requirements in terms of accuracy, but its reasoning speed is too low and is not suitable for real-time tasks; DETR, as the pioneering work of Transformer target detection, provides a new method in terms of thinking, but its accuracy and speed are much worse. The latest RT-DETR has greatly improved in real-time and accuracy, but in terms of reasoning accuracy and reasoning speed, YOLOv5 and YOLOv8 of the YOLO series are better.

[0082] Table 1 Recognition effect of baseline component recognition model

[0083]

[0084] Among them, YOLOv8, which performs best on the COCO large dataset, performs worse than YOLOv5 on the small dataset TCD. In comparison, YOLOv8 is more suitable for large datasets, while YOLOv5, which has a simpler structure, is better on small datasets. At the same time, YOLOv5 is also the most widely used target detection model on industrial small datasets. It stands out in the field of industrial target detection with its simple and effective structure and fast reasoning speed. Therefore, this embodiment selects YOLOv5 as the baseline model for the detection of key components of EMUs.

[0085] About YOLOv5. YOLOv5 can become the most popular target detection model in the industry, combining accuracy and reasoning speed, which is inseparable from its excellent network architecture and data optimization method. Its network structure is as follows Figure 7 As shown in the figure, the main optimization directions are as follows:

[0086] In terms of data enhancement, YOLOv5 uses the Mosaic data enhancement method, which generates new samples rich in small objects by randomly cropping, splicing and scaling a small batch of four samples, enriching the sample distribution of the data set and improving the detection accuracy and adaptability of the model. In the calculation of anchor boxes, YOLOv5 uses the built-in k-means algorithm to cluster the target boxes of the data set to generate anchor boxes of adaptive size and improve the quality of the anchor boxes.

[0087] In the backbone network, YOLOv5 uses an improved Focus module at the input end to speed up data processing. The specific method is to sample the same image into four downsampled images and then splice them into one image, which is equivalent to reducing the plane dimension of the image and increasing the depth. YOLOv5 also borrows from CSPNet to integrate multiple CSP layers into the network backbone to improve the network's feature extraction capabilities. The CSP module is also called the C3 module. Figure 7 In the YOLOv5 shown, the C3 module exists not only in the backbone but also in the neck for feature fusion.

[0088] In the neck, YOLOv5 uses both FPN and PAN. Two feature fusion networks are used as the neck network between the backbone and the detection head. FPN is connected from bottom to top and horizontally, and the feature maps of different scale layers of the backbone network are fused through the upper layer, while PAN is connected from top to bottom and horizontally to FPN. It performs a second multi-scale fusion through downsampling, and finally outputs the fused multi-scale feature map to the detection head. The neck design of FPN+PAN can fully integrate the feature information of different scales of the backbone network, providing feature information at different scale levels for detecting targets of different scales, making it convenient for the three detection heads of different scales to detect targets of different sizes.

[0089] The method of improving the baseline component recognition model based on the spatial structure prior Transformer encoder proposed in this embodiment is as follows:

[0090] The existing mainstream industrial target detection baseline models often use YOLOv5, which has good reasoning speed and detection accuracy. The above verifies the effectiveness of YOLOv5 on the TCD dataset, and its average accuracy and reasoning speed have reached SOTA. However, in the EMU visual defect detection task, the importance of key components with defects is much higher than that of ordinary components. Although YOLOv5 has achieved good average accuracy in the key component recognition task, its performance on the key defective components that are extremely small in number and extremely important is still not ideal.

[0091] In the EMU visual defect detection task, if important defective components such as broken anti-loosening wire are missed, it will cause huge safety hazards to the operation of the EMU. This embodiment will improve the existing baseline component recognition model YOLOv5 based on the spatial structure prior Transformer, namely the SSP-T module, and use the spatial structure prior and self-attention mechanism in the inspection image to extract the structural relationship of key components in different regions to improve YOLOv5's use of global information, thereby reducing the missed detection of key defective components by the component recognition model.

[0092] This embodiment proposes two YOLOv5 models based on SSP-T improvement:

[0093] like Figure 8 As shown in the figure, one is the YOLOv5 model based on backbone improvement (YOLOv5 with SSP-T inBackbone, YOLOv5-SSPT-B). On the basis of YOLOv5, the last layer feature map of the CSPDarknet53 backbone network is added with the SSP-T residual structure, that is, the same-dimensional attention matrix containing spatial structure prior information extracted by SSP-T is added to the feature map output by the last layer of the backbone network and then output to the neck of FPN+PAN for feature fusion. It should be noted that in Figure 8 In the paper, when improving the backbone of YOLOv5 based on SSP-T, the SSP-T module was not added to the other two feature maps involved in feature fusion. This is because the SSP-T module pays more attention to the semantic and structural relationships between different components, and requires more advanced semantic features rather than shallow details. Therefore, the high-level semantic feature map at the last layer of the CSPDarknet53 backbone network is the object of SSP-T attention. At the same time, the dimension of the deep feature map is lower, which can effectively reduce the calculation amount of the self-attention mechanism and ensure real-time performance. YOLOv5-SSPT-B integrates the SSP-T module with spatial structure prior to better extract the key component structure information in the inspection image, strengthen YOLOv5's use of global information, and reduce the missed detection of key defective components.

[0094] Considering that feature maps with higher-level dimensional semantics will have a better effect on SSP-T, and paying attention to the fact that YOLOv5 has three detection heads of different scales, three SPP-T modules of different dimensions are designed accordingly, and the following are proposed: Figure 8The YOLOv5 model based on the improved detection head (YOLOv5 with SSP-T in Head, YOLOv5-SSPT-H) is shown in the figure. In the improvement of the detection head, after the backbone feature map is fused with the neck FPN+PAN features, it is first passed through the SSP-T residual module of the corresponding dimension to extract the spatial structure information before being input into the detection head of each dimension. Different from adding the SSP-T module only to the lowest layer feature map when the backbone network is modified, when the detection head is improved, since the feature maps input to the detection head are obtained after the original backbone feature map is fused with multi-scale features, which contains the most advanced semantic features, the SSP-T module can be added to each detection head branch.

[0095] Among them, illustratively, from top to bottom, the dimensions of each detection head are reduced to 255*80*80, 255*40*40, and 255*20*20, and the spatial structure prior mask in the corresponding SSP-T module is constructed by dividing the corresponding spatial structure prior image into image blocks of corresponding dimensions, which are 80*80, 40*40, and 20*20, respectively, so as to adapt to the output of detection heads of different scales. YOLOv5-SSPT-H constructs corresponding SSP-T branches for output heads of different scales, and integrates the spatial structure information between key components of different scales, helping YOLOv5 to better reduce the missed detection of key components through spatial structure prior in object detection of different scales.

[0096] The method of the present invention has certain applicability to industrial equipment with relatively fixed component structural relationships, such as rail transit vehicle bogies, and has similar applicability to EMU bogies.

[0097] Embodiment 2

[0098] A device component identification method, comprising:

[0099] Collecting an inspection image, and obtaining a spatial structure prior image corresponding to the inspection image based on the inspection position of the inspection image;

[0100] The spatial structure prior image is input into a component recognition model constructed by a component recognition model construction method combining spatial structure prior and Transformer self-attention as described above to obtain a component recognition result.

[0101] The relevant technical solution is the same as that in Embodiment 1 and will not be described in detail here.

[0102] Embodiment 3

[0103] A computer-readable storage medium, characterized in that the computer-readable storage medium includes a stored computer program, wherein when the computer program is executed by a processor, the device where the storage medium is located is controlled to execute a component recognition model construction method combining spatial structure prior and Transformer self-attention as described above.

[0104] The relevant technical solution is the same as that in Embodiment 1 and will not be described in detail here.

[0105] 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 method for building a component recognition model combining spatial structure prior and Transformer self-attention, It is characterized in that include: A component recognition network is trained using a training sample set to obtain a component recognition model; wherein each training sample includes: a spatial structure prior image obtained by annotating key components of an inspection image and its corresponding key component label; the component recognition network includes: a spatial structure prior mask generation unit, a Transformer encoder and a baseline component recognition network; The Transformer encoder is arranged at the output end of the feature extraction or feature fusion unit in the baseline component recognition network, and is used to encode the original feature map output by the output end based on the self-attention mechanism to obtain a new feature map, and input the new feature map into the subsequent functional unit in the baseline component recognition network to obtain a component recognition result; the spatial structure prior mask generation unit is used to divide the spatial structure prior image corresponding to each inspection image into multiple image blocks according to the dimension of the original feature map, so as to extract a spatial structure prior mask matrix SSPM with the same dimension as the original feature map from the prior image; the self-attention mechanism is used to construct a relative position encoding matrix B based on the original feature map corresponding to each inspection image, and fuse B with its corresponding SSPM to obtain a relative position encoding matrix Bsspm of the fused spatial structure prior, which is used to calculate the self-attention score matrix; the Transformer encoder performs the encoding based on the self-attention score matrix.

2. The component recognition model construction method according to claim 1, It is characterized in that The spatial structure priori mask matrix SSPM is extracted as follows: The image blocks that contain more than half of any key component position frame in the spatial result prior image divided into image blocks are taken as important image blocks, and the remaining image blocks are taken as background image blocks. Two different values ​​are used to represent the important image blocks and the background image blocks respectively, and the absolute position matrix P of the key components is obtained; The key component absolute position matrix is ​​expanded in the order of rows and columns to obtain a row vector, and then the transpose of the row vector is matrix-multiplied with the row vector to obtain a spatial structure prior mask matrix SSPM.

3. The component recognition model construction method according to claim 1, It is characterized in that The self-attention mechanism calculates the self-attention score matrix as follows: Bsspm=B+B*SSPM; Where Attention(Q,K,V) represents the self-attention score matrix, Q represents the query matrix, K represents the keyword matrix, V represents the numerical matrix V, d k Represents the sequence dimension.

4. The component recognition model construction method according to claim 1, It is characterized in that The new feature map is added to the corresponding original feature map and then input into the subsequent functional unit in the baseline component recognition network.

5. The component recognition model construction method according to any one of claims 1 to 4, It is characterized in that The baseline component recognition network is YOLOv5.

6. The component recognition model construction method according to claim 5, It is characterized in that The output end is the output end of the backbone feature extraction unit of YOLOv5 for outputting the last layer of high-level language feature map.

7. The component recognition model construction method according to claim 5, It is characterized in that The output ends are all output ends of the neck feature fusion unit of YOLOv5.

8. A method for identifying equipment components, It is characterized in that include: Collecting an inspection image, and obtaining a spatial structure prior image corresponding to the inspection image based on the inspection position of the inspection image; The spatial structure prior image is input into a component recognition model constructed by a component recognition model construction method combining spatial structure prior and Transformer self-attention as described in any one of claims 1 to 7 to obtain a component recognition result.

9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium includes a stored computer program, wherein, when the computer program is executed by a processor, the device where the storage medium is located is controlled to execute a component recognition model construction method combining spatial structure prior and Transformer self-attention as described in any one of claims 1 to 7 and / or a device component recognition method as described in claim 8.

10. An electronic device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.