# Stripe-Assisted Global Transformer and Spatial-Temporal Enhancement for Vehicle Re-Identification
## 3 Methodology
### SaGT
#### 3.1.3 Model Optimization  
To optimize the model, we combined the ID loss and SaGL for global and stripe-based feature learning. The global ID loss \(\mathcal{L}_{ID}^{S}\) based on cross-entropy loss with label smoothing [33] is defined as follows:  
\[\mathcal{L}_{ID}^{S} =-\frac{1}{N}\sum_{i=1}^{N}\sum_{m=1}^{M}\log(\hat{y}_{i}[m])q(y_ {i},m), \tag{9}\] \[\hat{y}_{i}=\text{softmax}\Big{(}\text{FC}\Big{(}\text{BN} \Big{(}f_{g}^{i}\Big{)}\Big{)}\Big{)},\] \[q(y_{i},m)=(1-\varepsilon)(1|y_{i}=m)+\frac{\varepsilon}{M},\]where \(N\) and \(M\) denote the number of training samples and the number of training identity labels, respectively. \(\hat{y}_{i}\) represents the predictive probability distribution over identities of the \(i\)th sample, obtained using the softmax function. FC refers to the fully connected layer \(f_{S}^{i}\) is the global feature of the \(i\)th sample; \(y_{i}\) represents the ground-truth label of the \(i\)th sample; \(q(y_{i},m)\) is the modified probability of \(y_{i}\); \((1|y_{i}=m)\) equals 1 for \(y_{i}=m\) and 0 for otherwise; and \(\varepsilon\), set to 0.1 in this work, is the weight coefficient of label smoothing.  
Similar to the global ID loss, the local ID loss \(\mathcal{L}_{ID}^{l}\) is described as follows:  
\[\begin{split}\mathcal{L}_{ID}^{l}=-\frac{1}{N\times K}\sum_{i=1 }^{N}\sum_{k=1}^{K}\sum_{m=1}^{M}\log(\hat{y}_{i,k}[m])q(y_{i},m),\\ \hat{y}_{i,k}=\text{softmax}\left(\text{FC}\left(\text{BN}\left( f_{l}^{k,i}\right)\right)\right),\end{split} \tag{10}\]  
where \(K\) denotes the number of stripe-based features for each vehicle image. \(\hat{y}_{i,k}\) is the predictive probability distribution over identities corresponding to the \(k\)th stripe-based feature of the \(i\)th sample, and \(f_{l}^{k,i}\) is the \(k\)th stripe-based feature of the \(i\)th sample; \(q(y_{i},m)\) still represents the modified probability of \(y_{i}\) and is defined in the same manner as \(\mathcal{L}_{ID}^{g}\).  
In particular, to encourage the global feature to learn more discriminative details from stripe-based features, we designed an SaGL inspired by the triplet loss. Given a training batch containing \(M\times N\) vehicle images, with \(M\) vehicles identities and \(N\) images for each identity, the SaGL \(\mathcal{L}_{SaGL}\) is defined as follows:  
\[\begin{split}\mathcal{L}_{SaGL}=&\sum_{i=1}^{M}\sum _{a=1}^{N}[m+\text{d}(f_{S}^{a,i}f_{S}^{p,i})+\frac{1}{K}\sum_{k=1}^{K}\text{ d}(f_{l}^{a,i,k},f_{l}^{p,i,k})\\ &-\text{d}(f_{S}^{a,i},f_{S}^{n,j})-\frac{1}{K}\sum_{k=1}^{K} \text{d}(f_{l}^{a,i,k},f_{l}^{n,i,k})]_{+},\\ p=&\text{arg max}_{p\in(1,\cdots,N)}\text{d}(f_{S} ^{a,i},f_{S}^{p,i}),\\ n,j=&\text{arg min}_{\begin{subarray}{c}j\in(1, \cdots,M)\\ n\in(1,\cdots,N)\end{subarray}}\text{d}(f_{S}^{a,i},f_{S}^{n,j}),\end{split} \tag{11}\]  
where \(K\) denotes the number of stripe-based features for each vehicle image. \(f_{S}^{x,y}\) denotes the global feature corresponding to the \(x\)th image of the \(y\)th vehicle in the above-mentioned batch. Similarly, \(f_{l}^{x,y,k}\) denotes the \(k\)th stripe-based feature corresponding to the \(x\)th image of the \(y\)th vehicle in the same batch. The function \(\text{d}(\cdot)\) represents the Euclidean distance. The margin \(m\) is a hyperparameter set to 0.6 in this work. The notation \([x]_{+}\) denotes the maximum value between 0 and \(x\). Note that all features are normalized.  
Therefore, the total loss \(\mathcal{L}_{total}\) is formulated as follows:  
\[\mathcal{L}_{total}=\mathcal{L}_{ID}^{g}+\mathcal{L}_{ID}^{l}+\mathcal{L}_{SaGL}. \tag{12}\]