## 2 Materials and Methods
### Image Similarity Calculation  
In the similarity-calculation phase, it is necessary to compare the similarity of two images through a similarity-measurement method. In Siamese neural networks, the image features extracted by the convolutional neural network as a sub-network are unordered,  
Figure 11: New College Dataset Image Sequence Example. Figure 12: Visualization of transformed feature matrix. disregarding the spatial-position information of the features. NetVLAD [37] is a feature-encoding method that enhances the interrelation of features to improve the recognition ability of neural networks. It can capture the relative distribution of features in space. When combined with features compressed by KL transformation, it generates descriptors with stronger representational and anti-interference capabilities. The training objective of NetVLAD is to solve and optimize the positions of cluster centers and the weights of each descriptor belonging to a cluster center after the KL transformation compression. It calculates the weighted residual between the feature map descriptor and the cluster centers, using it as the image descriptor vector. This vector is designed to have the greatest similarity with other descriptors with minimal cosine distance during image similarity detection. The NetVLAD structure based on ResNet152 is illustrated in Figure 13.  
Select the output of the convolutional layers from ResNet152, and after the features are compressed through KL transformation, the feature dimensions become \(\text{W}\times\text{H}\times\text{D}\). Subsequently, \(\text{W}\times\text{H}\times\text{D}\)-dimensional local descriptors are provided as an input to the NetVLAD layer, with K \(\times\) D cluster centers from the clustering algorithm as parameters. The computation of the elements in the image description matrix \(V\) involves calculating the weighted residuals of \(\text{W}\times\text{H}\times\text{D}\) features concerning the cluster centers, and the formula for \(V\) is as follows:  
\[V(j,k)=\sum_{i=1}^{N}\pi_{k}(Y_{t})(y_{i}(j)-c_{k}(j)) \tag{19}\]  
where \(y_{i}(j)\) represents the \(j\)-th feature value of the \(i\)-th local feature and \(c_{k}(j)\) denotes the \(j\)-th feature value of the \(k\)-th cluster center. The computation involves calculating the distance weights from each local feature to the cluster centers, adjusting the weights of local feature descriptors \(Y_{l}\) under each cluster to be in the range of 0-1. Higher weights indicate that the feature is closer to a certain cluster center. Finally, \(V\) is transformed into vector form, normalized, and output as the image's feature description vector, resulting in a VLAD vector of length K \(\times\) D. This vector serves as the original image's feature descriptor. The network architecture designed in this paper takes images as input in the form of a sequence, and the network output is a set of feature vectors for a sequence of images, where each element corresponds to the VLAD feature descriptor for the respective image. Therefore, in similarity detection, we directly compute the similarity between two sequences. If the distance between two sequences is close, that result indicates the presence of loops in the sequence, and the higher the similarity between the sequences, the more loops may exist. Conversely, a lower similarity suggests that there are fewer or no loops in the sequence. Figure 13: Structure Diagram of NetVLAD based on ResNet152. Let the input sequence at the current time be \(S_{p}\) and the selected historical sequence at a previous time be \(S_{h}\), both sequences having a length of \(l\). The corresponding VLAD feature vectors for the two sequences are denoted as \(V_{S_{p}}\) and \(V_{S_{h}}\):  
\[ \begin{array}{l}V_{S_{p}}=\left[VLAD_{p1},VLAD_{p2},\ldots,VLAD_{pl}\right]\\ V_{S_{h}}=\left[VLAD_{h1},VLAD_{h2},\ldots,VLAD_{hl}\right]\end{array}