# CNN Attention Enhanced ViT Network for Occluded Person Re-Identification
## 3 Method
### Spatial Attention Enhancement Module  
Although ViT can obtain more robust global features, its approach of obtaining sequence vectors through patch embedding would have an insufficient focus on local regions and remain challenging in the case of occluded ReID. The SAEM is inspired by the CNN attention mechanism, which aims to enhance ViT's attention to important local information by strengthening the regional information of image feature vectors after patch embedding [46]. Specifically, we generate a 2D spatial attention map produced by exploiting the spatial relationship between the sequence vectors of the patch embedding, and this 2D spatial attention map emphasizes \"where\" the given image is important. The detailed process of SAEM is shown in Figure 5a.  
To calculate the spatial attention map, in the first place, we reshape the sequence vector map \(f\in R^{B\times N\times D}\) after patch embedding in \(N\) dimensions as \(f^{\prime}\in R^{B\times\frac{H}{K}\times\frac{W}{K}\times D}\), where \(B\) is the number of images inferred from one batch, \(K\) is the convolutional size of patch embedding, \(N=HW/K^{2}\) is the number of sequence vector, and \(f\) is denoted as a generalization of the information of \(N\times K\times K\) regions. Second, average pooling and maximum pooling are performed separately along the channel dimension, and the results of both are concatenated to produce a feature descriptor. Along the channel dimension, pooling has been shown to be effective in highlighting local information [22]. A convolution is used on the feature descriptors to generate spatial features corresponding to the \(f^{\prime}\) channel dimension. Finally, the spatial feature is put into a sigmoid activation function to map into a probability distribution for obtaining a spatial attention map. The process of applying the spatial attention map to the sequence vector can be simply defined as:  
\[{f^{\prime}}_{sd}={sigmoid}\big{(}SA\big{(}f^{\prime}\big{)}\big{)}\times f^{ \prime}, \tag{2}\]  
Figure 5: The extraction framework diagram of spatial attention map and channel attention map. (**a**) The extraction framework of spatial attention map. (**b**) The extraction framework of channel attention map.  
where \({f^{\prime}}_{sa}\) denotes the spatial attention-enhanced feature, \({sigmoid(\cdot)}\) denotes the probability mapping function, and \({SA(\cdot)}\) denotes the generation process of spatial attention features, the specific generation process of which can be defined as:  
\[{SA(x)}=Cov^{7\times 7}(cat(AvgPool(x);MaxPool(x))), \tag{3}\]  
where \({AvgPool(\cdot)}\) and \({MaxPool(\cdot)}\) denote the average pooling and maximum pooling, respectively, \(cat(\cdot)\) denotes the splicing operation, and \(Cov^{7\times 7}\) denotes the \(7\times 7\) convolution process.  
The feature vector \({f^{\prime}}_{sa}\) generated by SAEM is a weighted sum with the original feature vector \(f\) by the weighted hyperparameter \(\lambda\); this process can be defined as:  
\[{f_{sa}}=\lambda\times{f^{\prime}}_{sa}+(1-\lambda)\times f, \tag{4}\]  
where \({f_{sa}}\) denotes the weighted vector. It's going to be reshaped as \({B\times N\times D}\) and spliced with the classification representation \({f_{cls}}\). The splicing result and the position embedding are added and input to the Transformer encoder. In the ablation study, we analyzed the weighted hyperparameters \(\lambda\). The overall process of SAEM is shown in the blue part of Figure 4.