# An Efficient Multi-Scale Focusing Attention Network for Person Re-Identification
## 3 Methods
### Loss Function  
Our proposed MSFANet is trained in an end-to-end manner. For person re-identification, it can be considered as a classification task. Various studies have assessed the influence of loss function for a ReID task. In this work, we adopt the widely used softmax loss and Triplet loss with batch hard mining to train MSFANet in opening ReID datasets.  
**Softmax loss.** For a classification training task, softmax loss is very suitable, regarded as a cross-entropy loss using the softmax function. It is defined in the following Equation (4), where \(S_{j}\) is the \(j\)th value of the output vector S of the softmax layer, representing the probability that this sample belongs to the \(j\)th category. \(y_{j}\) represents a \(1*T\) vector,  
Figure 4: An illustration of the MSFA block, which aggregates three branches with 1, 3, and 5 FA blocks, introduced in Figure 3, to extract multi-scale receptive field features.  
and \(T\) denotes the number of categories, of which only one value is 1, and the other \(T-1\) values are all 0.  
\[L_{softmax}=\sum_{j=1}^{T}y_{j}\log S_{j}. \tag{4}\]  
**TriHard Loss [30].** Triplet loss with batch hard mining is an improved version of triplet loss, which is able to improve the generalization ability of a ReID network. TriHard loss's mathematical form is shown in Equation (5), where \(P\) denotes the number of different person IDs randomly selected, and \(K\) represents the number of pictures randomly chosen for each person ID. The goal is that for each picture \(a\) in the batch to select a hardest positive sample and a hardest negative sample to form a triple with it.  
\[L_{tri\_h}=\frac{1}{P\times K}\sum_{a\in batch}(\max_{p\in A}d_{a,p}-\min_{n \in B}d_{a,n}+\alpha) \tag{5}\]  
**Fusion Loss.** Softmax loss and TriHard loss both have their respective advantages in ReID model's training. However, there are some problems when we use softmax loss alone. As presented in the top part (1) and middle part (2) of Figure 5, we can observe that the softmax loss can distinguish positive and negative sample well to some extent, but is hard to deal with some hard samples. TriHard loss can achieve batch hard sample mining during model training. It can shorten the distance from hard positive samples while maximizing the distance of hard negative pairs [30]. In this work, we combine the two loss functions to improve the generalization of MSFANet, which can alleviate the hard sample differentiation problem shown in bottom part (3) of Figure 5. The fusion loss can be viewed as Equation (6), where \(\alpha\) and \(\beta\) are hyperparameters that can adjust the above two loss functions' weight. In our abundant experiments in different ReID datasets, we found that MSFANet can achieve the best robustness and fastest convergence when \(\alpha\) and \(\beta\) are set 1 and 0.5, respectively. Thus, our subsequent experiments are all based on this parameter setting.  
\[L=\alpha L_{softmax}+\beta L_{tri\_h} \tag{6}\]  
Figure 5: An illustration of comparing different loss functions applying to training data. The top (**1**) shows the result of the softmax loss on easy samples, while the middle (**2**) and bottom (**3**) show the differential results of the softmax loss and fusion loss on hard samples.