# Loop Closure Detection in RGB-D SLAM by Utilizing Siamese ConvNet Features
## 2 Materials and Methods
### Siamese ConvNet Architecture for Loop Closure Detection
Here, we attempt three strategies for feature learning: softmax supervision, contrastive supervision, and multi-task supervision. * Softmax supervision:  
Softmax supervision. The softmax_1 and softmax_2 layers output the probability of 205 scene classes. We compute the cross-entropy of once iteration and select the softmax loss as supervision, which can be represented as follows:  
\[L_{cls}(\mathbf{f}^{k},l^{k},\theta_{cls})=-[\sum_{i=1}^{n}1\Big{\{}i=l^{k}\Big{\}} \log P(i=l^{k},\theta_{cls})] \tag{2}\]  
where \(\mathbf{f}^{k}=\Big{\{}\mathbf{f}^{k}_{1},\mathbf{f}^{k}_{2}\Big{\}}\) is the \(k\)-th extracted feature vectors, \(l^{k}=\{l^{k}_{1},\,l^{k}_{2}\}\) denotes the class label, \(\theta_{cls}\) is the parameter of softmax classifier, and \(1\{\cdot\}\)is the indicator function:  
1[a true statement] = 1 and  
1[a false statement] = 0. \[P\Big{\{}\cdot\Big{|}\mathbf{f}^{k},\theta_{cls}\Big{\}}\] represents the predicted probability of each class. Softmax supervision has been widely used in various image classification tasks, but the learned features are not well suited for our application of matching tasks, which will be validated by the experiment in Section 4. * Contrastive supervision:  
The full7_1 layer and full7_2 layer outputs 2048-d feature vectors of \(\mathbf{f}^{k}=\Big{\{}\mathbf{f}^{k}_{1},\mathbf{f}^{k}_{2}\Big{\}}\). We apply the L2-normal distance to quantify the similarity between pairs of feature vectors and define a contrastive loss as supervision, which can be represented as follows:  
\[L_{cls}(\mathbf{f}^{k},l^{k},\theta_{cst})=\left\{ \begin{array}{ll}\frac{1}{2} \Big{|}\Big{|}\mathbf{f}^{k}_{1}-\mathbf{f}^{k}_{2}\Big{|}\Big{|}^{2}_{2}&if\,\,l^{k} _{1}=l^{k}_{2}\\ \frac{1}{2}\text{max}\Big{\{}0,m-\Big{|}\Big{|}\mathbf{f}^{k}_{1}-\mathbf{f}^{k}_{2} \Big{|}\Big{|}^{2}\Big{\}}^{2}&if\,\,l^{k}_{1}\
eq l^{k}_{2}\end{array} \right. \tag{3}\]  
Optimizing the contrastive loss equals minimizing the L2-norm distance between feature vectors, when \(\mathbf{f}^{k}_{1}\) and \(\mathbf{f}^{k}_{2}\) are from the same class (\(l^{k}_{1}=l^{k}_{2}\)), and maximize the L2-norm distance between feature vectors, when \(\mathbf{f}^{k}_{1}\) and \(\mathbf{f}^{k}_{2}\) are from the different class(\(l^{k}_{1}\
eq l^{k}_{2}\)). \(\theta_{cst}=\{\text{m}\}\) is the parameter to be learned in the contrastive loss function. Although contrastive supervision can be applicable in matching tasks, we consider it to be a suboptimal solution due to the lack of regularization items. * Multi-task supervision:  
We can jointly learn the softmax entropy loss and contrastive loss by optimizing the multi-task loss function. We can define multi-task supervision as follows:  
\[L(x^{k},l^{k},\theta)=L_{cls}+\lambda\cdot L_{cst}+\Big{|}\Big{|}\theta_{net} \Big{|}\Big{|}\Big{|}^{2}_{2}+\Big{|}\Big{|}\theta_{cst}\Big{|}\Big{|}^{2}_{2 }+\Big{|}\Big{|}\theta_{cls}\Big{|}\Big{|}^{2}_{2} \tag{4}\]  
where \(L_{cls}\) is the softmax entropy loss, \(L_{cst}\) is the contrastive loss, and \(\lambda\) is the hyperparameter balance of the softmax entropy loss and the contrastive loss. \(\theta_{net}\), \(\theta_{cls}\), and \(\theta_{cst}\) are the parameters to be learned. We use the stochastic gradient descent algorithm to update the related parameter and the proposed multi-task learning strategy is summarized in Algorithm 1. **Input:** training set \(X=\left\{x^{1},x^{2},x^{3},\ldots,x^{k}\right\}\), \(x^{k}=\left\{x_{1}^{k},x_{2}^{k},\hat{t}_{1}^{k},\hat{t}_{2}^{k}\right\}\), initialized parameters \(\theta_{net}\), \(\theta_{cls}\) and \(\theta_{est}\). learning rate \(\eta(t),\ t\gets 0\), times of iteration \(N\), batch size \(k\).