# Object-Tracking Algorithm Combining Motion Direction and Time Series
## 3 Methods
### Tracking Result Scoring Module  
The TRSM module is comprised of three components. In the first stage, the image features of the tracking results are obtained and transformed into vector sequences that can be processed by the attention mechanism. In stage 2, the Transformer structure is utilized to encode the vector sequence using the self-attentive mechanism in the encoding phase and integrate the time series information using the cross-attentive mechanism in the decoding phase. In stage 3, a fully connected network is employed to output the tracking result's reliability score. The overall architecture of the module is illustrated in Figure 3.  
The TRSM module operates on a set of historical tracking results and the current frame tracking results, using them as templates for the input.  
Stage 1. We apply a fully convolutional network \(\varphi\) to extract the template features. The structure of the convolutional network \(\varphi\) is not restricted to any particular design. The module receives an input template \(T=\{T_{1},T_{2},\ldots,T_{t},T_{\text{result}}\}\), where \(T\in\mathbb{R}^{3\times H\times W\times(l+1)}\), and \(T_{\text{result}}\) represents the current tracking result template, while \(T_{\text{history}}=\{T_{i},i=1,2,\ldots,t\}\) denotes the historical tracking result templates. The template \(T\) is mapped to \(\mathbb{R}^{C\times\frac{H}{s}\times\frac{H}{s}\times(l+1)}\) via network \(\varphi\), then flattened and connected to form a vector sequence \(T^{\prime}\). The length of \(T^{\prime}\) is \(\frac{H}{s}\times\frac{W}{s}\times(t+1)\), and its dimension is \(C\).  
Stage 2. \(T^{\prime}\) is fed into the encoding stage, which contains \(N\) layers of encoders. Each encoder layer is processed using a multi-headed self-attentive mechanism and a feed-forward network. The encoder captures the dependencies between individual sequence elements and enhances features based on contextual information to exploit temporal features between individual templates. In the decoding stage, unlike the decoder in the Transformer architecture, only the cross-attention mechanism and the feed-forward network are employed to construct the decoder, with no self-attention mechanism. A query vector is used to query the temporal features of the current and historical tracking results in the N-layer decoder, and a feature vector with strong discriminative power is generated.  
Stage 3. We composed a three-layer fully connected network that takes the feature vector outputted by the decoder as input and produces a score value through a sigmoid activation function. A higher score value outputted by the TRSM module indicates that the tracking results and the historical results have stronger similarity, which results in higher tracking result reliability and enhances the performance of the algorithm by improving the quality of template update. The loss function utilized to train the TRSM module is the binary cross-entropy loss function, denoted by \(L_{\text{TRSM}}\), which is expressed as follows:  
\[L_{\text{TRSM}}=y_{i}\log(P_{i})+(1-y_{i})\log(1-P_{i}), \tag{7}\]  
where \(y\) represents the ground truth value and \(P_{i}\) is the estimated value outputted by the TRSM module.