# Occlusion Vehicle Target Recognition Method Based on Component Model
## 2 Occlusion Vehicle Target Segmentation and Recognition Scheme Design
### Design of Vehicle Component Feature Mask Module Based on Swin Transformer
#### 2.2.1 Swin Transformer Unit  
The Swin Transformer unit is shown in Figure 3, which is composed of the Patch Partition layer, linear Embedding layer, Patch Merging layer, and Swin Transformer Block. The Patch Partition layer can divide the input vehicle saliency segmentation image into fixed-size image blocks and the linear embedding layer projects these segmented images onto the specified dimensions to form sub-images so that a complete image is encoded into a sequence. Then, it is input into the Swin Transformer Block to extract the regional features of the target vehicle parts, and the regional features of the target vehicle image can be obtained. In the second step, the Patch Merging layer is used to fuse the feature images of vehicle parts. Two self-attention mechanisms, W-MSA and SW-MSA, are used in the Swin Transformer block, as shown in Figure 4.  
W-MSA is a window-based multi-head self-attention mechanism. In the feature extraction of vehicle components, its self-attention objects are the windshield, side glass, black wheels, blue license plates, and front and rear lights of the vehicle. For the extracted salient region, W-MSA divides the entire input salient region into several windows and performs matrix multiplication and SoftMax operations in each window, which can constrain the calculation range of the attention mechanism and reduce the calculation amount. The computational complexity is as follows:  
\[O(W-MSA)=4 twC^{2}+2M^{2}twC \tag{3}\]  
In Equation (3), \(h\) and \(w\) represent, respectively, the number of the patches in the height and width of images, \(M^{2}\) is the number of the patches in the window, and \(C\) is the number of the channels in the window. Since the number of patches inside the window is much smaller than the number of image patches, and the number of windows remains unchanged, the computational  
Figure 4: Swim Transformer block structure. complexity of the W-MSA is linearly related to the image size, which greatly reduces the computational complexity of the module. W-MSA reduces the computational complexity while maintaining local dependence. W-MSA divides the feature map into several small Windows and sends them to MSA The MSA calculation process is shown in the following steps:  
1. The input features are mapped linearly to obtain query matrix \(Q\), keyword matrix \(K\), and value matrix \(V\). 2. The score matrix \(S\) between vectors of different input elements is calculated according to Equation (4). The score determines the degree of attention of the encoding at the current position to other vectors. \[S=Q\cdot K^{T}\] (4)
3. Each element is normalized according to Equation (5) to enhance the stability of the gradient. \[S^{\prime}=S/\sqrt{d_{k}}\] (5)
4. Perform a Softmax operation on \(S^{\prime}\) to get each element of the attention matrix obtained by the operation of Equation (6). \[a_{i,j}=\frac{e^{S^{\prime}_{i,j}}}{\sum\limits_{u=1}^{N}e^{S^{\prime}_{i,j}}},1\leq i\leq N,1\leq j\leq N\] (6)  
In Equation (6), \(a_{i,j}\) represents the correlation between the \(i\)-th element and \(j\)-th element in input X. This step converts the scores between pixels into probabilities. Based on the above expression, the MSA calculation sub-step can be summarized into a functional Equation (7), which is expressed as follows:  
\[Attention(Q,K,V)=Softmax\left(\frac{Q\cdot K^{T}}{\sqrt{d}}+B\right)\cdot V \tag{7}\]  
In the Equation (7), \(Attention\) denotes the self-attention matrix, \(d\) represents the vector dimension of the mapping matrix \(Q\) and \(K\), and \(B\) is the bias matrix. Although W-MSA can reduce computational complexity and calculate vehicle component features, there is a lack of information exchange between the non-coincident windows. Therefore, the next step is to enter the SW-MSA layer through a MLP with a GELU activation function. The role of the layer is to introduce a cross-window connection through a movable window so that the information between different local windows is integrated and the ability to extract global features is improved.