# A Novel Metric-Learning-Based Method for Multi-Instance Textureless Objects' 6D Pose Estimation
## 2 Methodology
### Masked Circle Loss for Matching Dense Correspondences  
The core operation in dense 2D-3D correspondences matching is to calculate the similarity between the pixelwise deep features from an image and the nodewise deep features from a 3D model. The cosine similarity is used to measure the distance between the features  
\[\mathcal{S}_{k}=F_{M}^{k}A_{k}F_{I} \tag{2}\]  
where \(\mathcal{S}_{k}\) denotes the similarity matrix for object \(k\). In [26], the softmax cross-entropy loss--which is the most generally used loss function for traditional classification problem--was chosen to select the corresponding node from 3D model for each image pixel that belongs to the target object. The lost function can be described as  
\[\mathcal{L}_{i}=-log\frac{e^{s_{i}}}{\sum\limits_{j=1}^{n}e^{s_{j}}} \tag{3}\]where \(s_{ij}\) denotes the similarity between the \(i\)-th pixel in the image and the \(j\)-th node from the 3D model. \(l\) is the correct label for the matching. The softmax step \(p_{iq}=\frac{e^{s_{il}}}{\sum\limits_{j=1}^{n}e^{s_{ij}}}\), \(q=1\ldots n\) turns each similarity \(s_{ij}\) into a probability \(p_{ij}\). Then, the \(p_{ij}\) is used to calculate the cross entropy with the one-hot vector, which only the true class equals to one, while all the other classes remain zero. The gradient of the \(j\)-th node in the softmax cross entropy loss is  
\[\frac{\partial\mathcal{L}_{i}}{\partial s_{ij}}= \begin{cases}p_{ij}-1,&i=l\\ p_{ij},&i\
eq l\end{cases} . \tag{4}\]  
As shown in Equation (4), the gradient of the true class is \(p_{il}-1\), which means the network is trained to make the similarity of the true class to be one, while the similarity of the false class to be zero. However, in the case of feature matching, the divergence among the classes is not as large as that in the traditional classification problems. As shown in Figure 2, the red point denotes the true class matching from the image pixel \(i\) to the node \(j\) in 3D model. The green circle denotes a nearby region for node \(j\). As in the softmax cross-entropy loss, all the nodes in the green circle are trained to have zero similarities with respect to pixel \(i\) while the node \(j\) is trained to have a similarity of one. This situation is apparently not reasonable for the training. In fact, the main purpose of the correspondence matching is to find the _most similar_ node from 3D model for pixel \(i\) instead of the _same_ node from 3D model. Thus, it is more suitable to learn a distance metric for the 2D-3D correspondences. Metric learning, which is also known as similarity learning, is a conventional research area before the deep learning era. Deep metric learning introduces deep neural networks into conventional metric learning. One of the most popular metrics of learning loss is contrastive loss  
\[\mathcal{L}_{\mathcal{C}}= \begin{cases}\parallel f_{i}-f_{j}\parallel_{2}^{2},&c_{i}=c_{j}\\ max(0,m-\parallel f_{i}-f_{j}\parallel_{2}^{2}),&c_{i}\
eq c_{j}\end{cases}  \tag{5}\]  
where \(m\) is a margin among different classes and \(c_{i}\) denotes the \(i\)-th class. Another well-known metric loss is triplet loss  
\[\mathcal{L}_{\mathcal{T}}=max(0,m+\parallel f_{i}-f_{j}\parallel_{2}^{2}- \parallel f_{i}-f_{k}\parallel_{2}^{2}),\qquad c_{i}=c_{j},ci\
eq c_{k} \tag{6}\]  
The main difference between these two methods is that triplet loss stops the optimization of the inner class distance \(\parallel f_{i}-f_{j}\parallel_{2}^{2}\) when the condition \(m+\parallel f_{i}-f_{j}\parallel_{2}^{2}-\parallel f_{i}-f_{k}\parallel_{2} ^{2}<0\) is fulfilled, while the contrastive loss always optimizes the distance among  
Figure 2: The illustration for the dense matching correspondences using softmax cross-entropy. features that belong to the same class. Apparently, triplet loss is more suitable for the task of dense feature matching, as the similarity of the true correspondences does not have to be one, it only needs to be more similar with its correspondence compared with the others.