# Real-Time Object Tracking Algorithm Based on Siamese Network
## 3 Methodology
### Attention Network  
In recent years, Attention Model has been widely used in various types of deep learning tasks, such as natural language processing [28; 29], image recognition [30; 31] and speech recognition [32; 33]. It is one of the core technologies of deep learning that deserves the most attention and in-depth understanding. The attention mechanism gathers the information of a certain part and focuses on a certain area in the image in terms of image processing. In other words, the attention mechanism gathers the most effective information of the target to better apply it in all aspects. The attention mechanism mainly involves two parts. First, it is necessary to confirm which part should gain more attention; second, it extracts features from the critical parts with the intention of gaining significant information. Since targets in complex scenarios will be affected by background interference, appearance distortion and other problems, the attention mechanism was introduced into the task of terrorist tracking in order to extract the target in the video frame from the background, so as to focus on the target of the tracking model and reduce the background interference to a certain extent. In this paper, the attention mechanism combining channel attention and spatial attention was used, as is displayed in Figure 3.  
Figure 3: Dual-attention Module. Figure 2: Architecture for Optical Flow Motion Estimation. To be specific, the channel attention module uses a feature map as a unit. Each channel of the feature map is able to be considered as a special feature detector, which uses the feature vector \(\alpha=\{\alpha_{1},\alpha_{2},\ldots,\alpha_{d}\}\) obtained by the feature \(\text{M}\in R^{w^{\prime}h^{\prime}d}\) passing the global average pooling layer as the input of the completely connected layer to maintain the adaptability of the target appearance in the deep network. ReLU is the activation function, after passing the next fully connected layer, the Sigmoid function was selected as the non-linear activation function. So as to strengthen the non-linear relationship between the channels to promote better mutual learning, the output vector obtained \(\beta=\{\beta_{1},\beta_{2},\ldots,\beta_{d}\}\) was multiplied with the input feature for the purpose of gaining the channel attention feature map \(\text{N}\in R^{w^{\prime}h^{\prime}d}\). The spatial attention module uses each pixel in the feature map as a unit. For the sake of uplift the feature representational capacity of the model, the structural dependency of spatial information was first established, and then weight was assigned to each pixel in the feature map. First, the input feature map x was convolved using a \(1\times 1\) convolution kernel, and then transformation functions \(f(x)\), \(g(x)\) and \(h(x)\) were used in order to transform three convolutions, respectively. As shown in Equation (2). \[f(x)=W_{1}\cdot x,\ g(x)=W_{2}\cdot x,\ h(x)=W_{3}\cdot x \tag{2}\]  
where, \(W_{1}\), \(W_{2}\), \(W_{3}\) represent the weight of \(f(x)\), \(g(x)\) and \(h(x)\), respectively. After that, the result output by the function \(f(x)\) was transposed for matrix multiplication with the output result, and the result obtained was calculated by utilizing the Softmax function with the intention of obtaining the spatial attention map. The spatial attention is calculated by the following Equation (3). \[Y_{b,a}=\frac{e^{f(x_{a})^{T}g(x_{b})}}{\sum_{k=1}^{WH}e^{f(x_{a})^{T}\cdot g(x _{b})}} \tag{3}\]  
where, \(a\) and \(b\) represent the \(a\)-th and the \(b\)-th position on the input image, respectively. After that, matrix multiplication was performed on the obtained spatial attention map and the function \(h(x)\). The feature map which is regulated by the spatial attention module is calculated as Equation (4) follows. \[O_{b}=x_{b}+\alpha\cdot\left(\sum_{a=1}^{WH}Y_{b,a}\cdot h(x_{a})\right) \tag{4}\]  
where, \(\alpha\) is the weight parameter.