# A Person Re-Identification Method Based on Multi-Branch Feature Fusion
## 3 Multi-Branch Feature Fusion Network
### Multiple Loss  
The cross-entropy loss is used as the loss of the classification model to measure the dissimilarity between the predicted values and the actual ground truth. In the context of the person re-ID task, a smaller cross-entropy value indicates that the model's judgment of the pedestrian category aligns more closely with the true label. The cross-entropy loss function \(L_{ce}\) is defined as follows in Equation (4):  
\[L_{ce}=\frac{1}{N}{\sum_{i}L_{i}}=-\frac{1}{N}{\sum_{i}\sum_{c=1}^{M}y_{ic}}{ \log(p_{ic})} \tag{4}\]  
where \(M\) indicates the number of categories (person ID), \(y_{ic}\) indicates 1 when the true category of sample \(i\) is \(c\), otherwise 0, and \(p_{ic}\) represents the probability that the sample \(i\) is predicted as class \(c\).  
Hard sample triplet loss is used as the metric loss. In every training batch, \(P\) pedestrians are randomly chosen, and \(K\) images are selected for each pedestrian. Therefore, a batch contains \(P\times K\) pictures in total. For each image \(a\) in the batch, a hard positive sample and a hard negative sample are selected to create a triplet. Here, the set of images from the same pedestrian as \(a\) is denoted as \(A\), and the set of images from different pedestrians as \(a\) is denoted as \(B\). The hard sample triplet loss function \(L_{TriHard}\) is defined as follows in Equation (5):  
\[L_{TriHard}=\frac{1}{P\times K}{\sum_{a\in batch}}{\left({\max_{P\in A}}{d_{a, p}}-{\min_{n\in B}}{d_{a,n}}+a\right)_{+}} \tag{5}\]  
where \(a\) is the threshold parameter set independently. In contrast to the traditional triplet loss, the hard sample triplet loss can expedite the convergence of the network and facilitate the learning of superior representations.  
KL divergence is used to strengthen the information exchange between different branches and avoid model collapse. Using KL divergence allows each branch to propagate its own knowledge to other branches. By learning from each other, the local branches can gain the ability to perceive specific scenes. Meanwhile, the global branch gathers insights from a broader range of scenes, thereby decreasing the likelihood of overfitting and enhancing the overall robustness. Equation (6) is used to calculate the probability \(p\) that the category of the pedestrian sample \(x_{i}\) is m.  
\[p_{m}(x_{i})=\frac{\exp(\gamma W_{m}f)}{\sum_{k=1}^{M}\exp(\gamma W_{k}f)} \tag{6}\]  
where \(M\) denotes the total number of pedestrian IDs, \(\gamma\) denotes the scale factor, which is kept constant to expedite the training process, \(W_{m}\) and \(W_{k}\) are the weight vectors related to categories \(m\) and \(k\) in the final classification layer, and \(f\) denotes the normalized features. Therefore, the KL divergence of the current branch can be expressed as shown in Equation (7):  
\[L_{ML}^{\Theta}=\frac{1}{S-1}{\sum_{s=1,s\
eq\Theta}^{S}{\sum_{i=1}^{N}{\sum_ {m=1}^{M}{p_{m}(x_{i})log\frac{P_{m}^{\Theta}(x_{i})}{p_{m}^{\Theta}(x_{i})}}}}} \tag{7}\]  
where \(\Theta\) indicates the current branch, and \(S\) represents the total number of branches.  
The final loss function for each branch is formulated as follows:  
\[L^{\Theta}=L_{ML}^{\Theta}+L_{ce}+L_{TriHard} \tag{8}\]