# Research on Vehicle Re-Identification Algorithm Based on Fusion Attention Method
## 2 Our Model Architecture
### Vehicle Global Feature Fusion with Attention Module  
The attention goal of vehicle re-identification is to focus on vehicle-related features while removing irrelevant background. Inspired by successful ideas in the field of segmentation, this paper integrates two complementary attention mechanisms, that is, the channel attention module (CAM) and position attention module (PAM). Depending on how the attention works, it can be divided into the spatial domain [13], channel domain [14], and hybrid domain [15]. Spatial attention refers to the attention to different spatial locations of features. Channel attention refers to the attention of features learned by different channels. The attention mechanism of the mixed domain combines the regions that different attention mechanisms pay attention to and learns the weight matrix corresponding to different channels and different spatial locations. For features of size H \(\times\) W \(\times\) C, weight matrices of the same size are learned, i.e., corresponding weights are learned for each pixel of all channels. Channel attention is different from spatial attention, so it can be combined to obtain more discriminative vehicle feature maps. First, the Max pooling and Average pooling operations aggregate the input feature channel information, and two feature maps with spatial information are output, which are \(S_{avg}\in R^{1\times H\times W}\) and \(S_{max}\in R^{1\times H\times W}\). Spatial-attention Ms is computed as Equation (1). \[\text{Ms}=\text{sigmoid}\ (\text{f}^{\gamma\times 7}(\text{W}_{0}[S_{avg}+S_{ max}])) \tag{1}\]  
In the formula, sigmoid represents the activation function, and \(\text{f}^{\gamma\times 7}\) represents the convolution operation \(7\times 7\). The vehicle image is input into the global feature extraction network model fused with the spatial attention module, and the feature maps layer-2 (\(f_{2}=256\times 96\times 96\)) and layer-3 (\(f_{3}=512\times 48\times 48\)) generated by the ResNet-50 network are sent to the channel attention module and the spatial attention module, respectively. Then, the channel attention model is applied to \(f_{2}\) and \(f_{3}\) to obtain channel attention matrices \(M_{c1}\) and \(M_{c2}\). The values in matrices \(M_{c1}\) and \(M_{c2}\) are weights; that is, the importance of the position of each region obtained after the image is input. In general, the higher the focus, the greater the position weight. The expression formula is shown in Formulas (2) and (3). \[M_{c1}=soft\text{max}(conv(f_{2})) \tag{2}\]  
\[M_{c2}=soft\text{max}(conv(f_{3})) \tag{3}\]  
The size of the convolution kernel is \(1\times 1\), and conv represents the convolution operation, which can effectively reduce the dimension. After softmax normalization, each local area obtains a corresponding weight, indicating the importance of each area's attention in the current scene. Then feature maps of \(f_{2}^{\prime}\) and \(f_{3}^{\prime}\) are multiplied with the corresponding elements of the attention map \(M\) to obtain the feature maps \(f_{2m}\) and \(f_{3m}\) for \(f_{2}\) and \(f_{3}\), as shown in Formulas (4) and (5). \[f_{2m}=f_{2}^{{}^{\prime}}\times M_{c1} \tag{4}\]  
\[f_{3m}=f_{3}^{{}^{\prime}}\times M_{c2} \tag{5}\]  
Due to the vehicle's complex background information, there may be some errors in the attention matrix and some interference noise, and some critical information in the original image may be lost. Therefore, it is necessary to add the input vehicle image and the previous feature image, as shown in Formulas (6) and (7). \[f_{2 cm}=f_{2}+f_{2m} \tag{6}\]  
\[f_{3 cm}=f_{3}+f_{3m} \tag{7}\]  
\(f_{2 cm}\) and \(f_{3 cm}\) represent the new feature maps obtained by combining the two feature maps after processing. The new spatial attention matrix is obtained by mapping the featuresof the attention module of the fused channels to the spatial attention module used as input, thus obtaining a vehicle feature map that combines the attention of the channels with the global attention to obtain more distinguishable vehicle features.