# Improving Re-Identification by Estimating and Utilizing Diverse Uncertainty Types for Embeddings
## 3 Uncertainty Estimation in Neural Networks -- Mathematics and Algorithm
### Uncertainty Estimation for Embedding Vectors
#### 3.3.8 Training  
The objective of person re-identification (ReID) is to train a model that enables the comparison of images depicting a single person each, with the goal of identifying images that depict the same subject. Each image is cropped around the subject, such that the subject is centered in the image. The comparison is conducted based on a learned feature embedding, such that each input image \(x\) can be described by a \(d\)-dimensional feature vector \(z\in\mathbb{R}^{d}\). Learning a Feature Embedding  
As described in Figure 3 above, in our architecture, we compute the feature vector \(z=\mu\). In the training phase, batch normalization followed by a fully connected layer and a Softmax function are applied to the feature vector \(z\). These serve as a classification layer, and thus map the feature vector \(z\) to a classification output \(y\). For the purpose of the classification task, every person in the training dataset is treated as a single category. Cross-entropy serves as classification loss. During the training phase, batches are sampled such that they contain several images per individual. Therefore, each training batch contains both matching and non-matching image pairs. Given that the classification layer comprises a limited number of parameters, the model is compelled to learn a robust feature embedding to facilitate accurate classification. In addition to the classification task, triplets comprising an anchor image, a matching image, and a non-matching image present within the training batch are employed as input for the triplet loss function. All other loss terms in Equation (18) serve the purpose of forcing the model to learn adequate uncertainties. After training, the classification layer is no longer required and thus discarded. Benchmarking  
For benchmarking, a set of \(Q\) query images \(\mathcal{X}^{\mathcal{Q}}\) (Equation (20)) is compared to a set of \(G\) gallery images \(\mathcal{X}^{\mathcal{G}}\) (Equation (21)). \[\mathcal{X}^{\mathcal{Q}} =\left\{x_{1}^{\mathcal{Q}},x_{2}^{\mathcal{Q}},\ldots,x_{Q}^{ \mathcal{Q}}\right\} \tag{20}\] \[\mathcal{X}^{\mathcal{G}} =\left\{x_{1}^{\mathcal{G}},x_{2}^{\mathcal{G}},\ldots,x_{G}^{ \mathcal{G}}\right\} \tag{21}\]  
The objective of ReID is to identify those gallery images that depict the same individual as each of the query images. Therefore, each image \(x_{i}^{\mathcal{Q}}\) of the query set \(\mathcal{X}^{\mathcal{Q}}\) is described by a feature vector \(z_{i}^{\mathcal{Q}}\in\mathbb{R}^{d}\). All of the query feature vectors are then combined to form a matrix \(Z^{\mathcal{Q}}\in\mathbb{R}^{Q\times d}\) (Equation (22)). Similarly, the gallery images \(\mathcal{X}^{\mathcal{G}}\) are each described by a feature vector \(z_{i}^{\mathcal{G}}\in\mathbb{R}^{d}\). All of the gallery feature vectors are then combined to form a matrix \(Z^{\mathcal{G}}\in\mathbb{R}^{G\times d}\) (Equation (23)). \[Z^{\mathcal{Q}} =\left[z_{1}^{\mathcal{Q}}\,z_{2}^{\mathcal{Q}}\,\ldots\,z_{Q}^{ \mathcal{Q}}\right]^{T} \tag{22}\] \[Z^{\mathcal{G}} =\left[z_{1}^{\mathcal{G}}\,z_{2}^{\mathcal{G}}\,\ldots\,z_{G}^{ \mathcal{G}}\right]^{T} \tag{23}\]  
Based on the query features \(Z^{\mathcal{Q}}\) and gallery features \(Z^{\mathcal{G}}\), a distance matrix \(D\in\mathbb{R}^{Q\times G}\) is computed. This is accomplished by applying a given distance function \(\delta:\mathbb{R}^{d}\times\mathbb{R}^{d}\rightarrow\mathbb{R}\), which can be used to compare two vectors (Equation (24)). In our case, we use the cosine distance \(\delta_{cos}\) (Equation (25)).