A loop detection and optimization method based on second-order attention mechanism

By integrating the SOA-NetVLAD network model of VGG16 and the second-order attention module, combined with knowledge distillation and local sensitive hashing, the robustness problem of the existing loop detection method under illumination and viewpoint changes is solved, and a higher level is achieved. Pose estimation accuracy and real-time performance.

CN114926742BActive Publication Date: 2024-09-24NANTONG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210690435.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-17
Publication Date
2024-09-24
Estimated Expiration
2042-06-17

AI Technical Summary

Technical Problem

Existing loop detection methods lack robustness in the face of illumination changes and viewpoint changes, resulting in insufficient pose estimation accuracy and real-time performance, making it difficult to effectively correct cumulative drift errors.

Method used

The SOA-NetVLAD network model that integrates VGG16 and second-order attention modules is used, combined with knowledge distillation and local sensitive hashing, to extract global features and reduce dimensionality of the image. It also eliminates mismatches and improves loop closure through geometric verification and random sampling consistency algorithms. Detection accuracy and robustness.

Benefits of technology

It improves the accuracy of loop detection, reduces pose drift errors, enhances the robustness to illumination changes and viewpoint changes, reduces the amount of calculation, and improves the real-time performance of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114926742B
    Figure CN114926742B
Patent Text Reader

Abstract

The present invention discloses a loop detection and optimization method based on a second-order attention mechanism, which belongs to the field of computer vision image technology and solves the problem that the traditional method ignores the correlation between local features of the image. The technical scheme is as follows: comprising the following steps: step 1), constructing a network model SOA-NetVLAD integrating VGG16, a second-order attention mechanism and NetVLAD; step 2), training the network model by knowledge distillation to obtain the optimal parameters; step 3), extracting the global features of the image; step 4), using the local sensitive hashing method to reduce the dimension of the global features of the image, and calculating the cosine similarity between the images; step 5), using the geometric verification method to perform loop verification; step 6), using the random sampling consistency algorithm to eliminate mismatching. The beneficial effects of the present invention are: the attention mechanism is added to the network model of the present invention, which can effectively learn the correlation between local features.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer vision image technology, and in particular to a loop detection and optimization method based on a second-order attention mechanism. Background Art

[0002] Simultaneous Localization and Mapping (SLAM) plays a key role in the field of autonomous mobile robots and intelligent transportation. It can build maps in unknown environments and accurately estimate the robot's position. However, due to the influence of environmental conditions, the robot's estimated trajectory will have some cumulative drift. Loop detection is an important component of the SLAM system. It can correct the cumulative error by identifying whether the robot has returned to its previous position. True loop detection can provide accurate pose estimation and improve the accuracy of the entire SLAM system.

[0003] Loop detection improves the performance of SLAM. Currently, loop detection methods are mainly divided into two categories: traditional methods and deep learning methods. The bag-of-words (BoW) framework (Gálvez-López D, Tardos J D. Bags of binary words for fast place recognition in image sequences [J]. IEEE Transactions on Robotics, 2012, 28 (5): 1188-1197.) has been widely used in traditional methods. Most loop detection methods using the BoW framework quantize the descriptor space into visual words and then apply the TF-IDF technology to represent the image using a compact vector. Finally, the method combined with the sorting index quickly calculates the similarity between the current query image and the previous image to find the loop candidate frame. However, traditional methods lack robustness to changes in illumination and viewpoint, and are overly dependent on texture information, which is prone to perceptual confusion. When faced with real scenes, such as changes in illumination and viewpoint, the performance of the descriptor may be reduced. There are many methods based on deep learning. R. Arandjelovic et al. proposed the NetVLAD (Arandjelovic R, Gronat P, Torii A, et al. NetVLAD: CNN architecture for weakly supervised place recognition [C] / / Proceedings of the IEEE conference on computer vision and pattern recognition. 2016: 5297-5307.) network, but this method ignores the similarity between local features and is sensitive to viewpoint changes. It may fail in complex environments.

[0004] The current problem is that the accuracy and real-time performance of loop detection need to be further improved. How to solve the above technical problems is the subject of the present invention. Summary of the invention

[0005] In order to solve the above technical problems, the purpose of the present invention is to provide a loop detection and optimization method based on a second-order attention mechanism, which helps the robot determine whether to return to a previously visited place by comparing the global features of the image, thereby improving the accuracy of loop detection, reducing posture drift errors, further improving positioning accuracy, and greatly reducing the amount of calculation, and performing better in real-time.

[0006] The inventive concept of the present invention is as follows: the present invention constructs a network model SOA-NetVLAD that integrates VGG16, a second-order attention module (SOA) and NetVLAD; and uses knowledge distillation to train the network model to obtain optimal parameters; preprocesses the image and inputs it into the SOA-NetVLAD network to extract the global features of the image; uses the local sensitive hashing (LSH) method to reduce the dimension of the global features of the image, and calculates the cosine similarity between images, and obtains loop candidate frames based on the similarity; uses a geometric verification method to perform loop verification; and uses a random sampling consensus algorithm (RANSAC) to eliminate mismatches. The loop detection and optimization method based on the second-order attention mechanism can effectively learn the correlation between local features, overcome the problems of traditional loop detection methods being sensitive to viewpoint changes and illumination changes, and the addition of a geometric verification method can further verify the results of the loop detection, thereby improving the accuracy of the loop detection.

[0007] The present invention is implemented by the following measures: a loop detection and optimization method based on a second-order attention mechanism, comprising the following steps:

[0008] Step (1), construct the network model SOA-NetVLAD that integrates VGG16, second-order attention mechanism (SOA) and NetVLAD: crop VGG16, then add the SOA module after the conv5_3 layer of VGG16, and add the pooling layer NetVLAD to the last layer;

[0009] Step (2), using knowledge distillation to train the network model to obtain the optimal parameters;

[0010] Step (3), step (3), preprocessing the query image and the database image, and then inputting them into the SOA-NetVALD network to extract the global features of the query image and the database image;

[0011] Step (4), using the local sensitive hashing (LSH) method to reduce the dimension of the global feature vector obtained in step (3), and calculating the cosine similarity between images, sorting the database images according to the similarity scores, and taking the first k sorted database images as loop closure candidate frames;

[0012] Step (5) introduces geometric verification to determine whether the query image and the loop candidate image constitute a true loop. First, the SURF features of the query image and the loop candidate image are extracted, and then the CasHash algorithm is used to perform pairwise image matching.

[0013] Step (6): Use the random sampling consensus algorithm (RANSAC) to eliminate false matches and select the final loop candidate frame.

[0014] Furthermore, in the above method, in step (1), a network model VGG-VLAD integrating VGG16, second-order attention mechanism (SOA) and NetVLAD is constructed: specifically:

[0015] Step (1-1), modify the VGG16 network, delete the pooling layer and fully connected layer after the last convolutional layer conv5_3, including the RELU activation function, and connect the SOA module to the convolutional layer conv5_3 to obtain the second-order feature map. Finally, connect the NetVLAD layer to the back of the SOA module as a new pooling layer. The NetVLAD layer introduces the idea of ​​VLAD into the convolutional neural network.

[0016] Step (1-2), for the C×W×H-dimensional feature map x∈R output by VGG16 C×W×H , which can be regarded as a total of W×H C-dimensional local descriptors x ij (i=1, 2, ...W, j=1, 2, ..., H). We first generate two maps denoted as f(x) and g(x) by 1×1 convolution with D output channels, followed by batch normalization layer and swish activation, where D=2×C. The maps f(x) and g(x) are then flattened to a size of D×HW. The result of the second-order attention map is as follows:

[0017] m=softmax(α·f(x) T g(x)

[0018] Where α is the scaling factor, f(x) T is the transpose of f(x). The resulting second-order attention map m has a size of HW×HW, and its value represents the correlation between local descriptors in the feature map m. Finally, the feature map x and the second-order attention map m are combined to obtain the output of the second-order attention module SOA(x):

[0019] SOA(x)=x+v(m′)

[0020] Where m′ is a tensor of shape HW×H×W obtained by resizing the attention map m, and v is a 1×1 convolution function that restores the channel size from HW to C. The size of the second-order feature map SOA(X) is C×W×H, the same as the size of the input feature map x.

[0021] Step (1-3), add a trainable NetVLAD layer after the second-order attention module, which can aggregate the second-order feature map SOA(x) into a compact global descriptor. VLAD is a description method commonly used in image retrieval and image classification. It constructs a vector from the aggregated local descriptors and uses the vector as the global descriptor of the image. If the input of VLAD is N D-dimensional feature vectors {x i}, the parameter is K cluster centers c k , the output is a K×D-dimensional feature vector, which is written in the form of a matrix, denoted as V, and the calculation formula is as follows:

[0022]

[0023] where x i (j) and c k (j) represents the jth element of the i-th eigenvector and the k-th cluster center, respectively. k (x i ) represents the weight of the i-th feature vector corresponding to the k-th cluster center. When the feature belongs to this cluster center, the weight is 1, otherwise it is 0. Since VLAD is a discrete function and cannot be back-propagated, the NetVLAD layer adopts an approximate method to convert a k (x i ) is softly assigned to multiple cluster centers to make it differentiable:

[0024]

[0025] where w k =2αc k , b k =-α||c k || 2 , α is a parameter greater than 0, when α→∞, The above formula is the softmax function. The feature vector output by the NetVLAD layer is:

[0026]

[0027] Furthermore, in the above method, in step (2), the network model is trained by knowledge distillation to obtain the optimal parameters, specifically:

[0028] Step (2-1) uses knowledge distillation to train and build a network model on the Google Landmark dataset to obtain the optimal parameters.

[0029] Step (2-2), use the global feature extraction network SOA-NetVLAD as the student network and the pre-trained NetVLAD network with VGG16 as the backbone as the teacher network. Train our global feature extraction network by minimizing the mean square error (MSE) loss between the global features predicted by the teacher network and the global features predicted by the student network;

[0030] Furthermore, in step (3), the query image and the database image are preprocessed and then input into the convolutional neural network to extract features, specifically:

[0031] Step (3-1), first resize the image to 224×224 pixels and subtract the mean data of the RGB channels. Then input the image into the network model that has been trained on the dataset, and use the output of the last NetVLAD layer as the global feature representation of the image.

[0032] Furthermore, in the above method, in step (4), the global feature vector obtained in step (3) is reduced in dimension using the local sensitive hashing (LSH) method, and the cosine similarity between the images is calculated, and the loop candidate frame is obtained according to the similarity, specifically:

[0033] Step (4-1), the output of the last NetVLAD layer is used as the global feature of the image represented as V i (I) Where I represents the image and d represents the dimension of the global feature vector. For our global features, the hash function is defined as follows:

[0034]

[0035] Where r is a spherically symmetric random vector of unit length generated from a d-dimensional space, and v represents the global feature vector of the image. By defining k random vectors r, the dimensionality reduction of the convolution feature vector can be achieved, that is, the feature vector can be represented by bytes of length k. For two global feature vectors u and v, then:

[0036]

[0037] Therefore, the cosine similarity between u and v can be obtained:

[0038] sim(u,v)=cos(θ(u,v))=cos((1-P r [h r (u) = h r (v)])π)

[0039] Step (4-2), calculate the cosine similarity between the query image and the global feature vector of the database image, and sort the database images from high to low according to the cosine similarity. Select the top k database images in the sorting result as loop closure candidate images.

[0040] Furthermore, in the above method, in step (4-1), during the database image acquisition process, there is a high similarity between adjacent images, which may lead to false loops. In order to prevent the adjacent images of the query image from becoming loop candidate frames and causing false positives, we introduce a constraint to limit the query image matching range. The query image matching range is specifically:

[0041] R=Nf·T

[0042] Among them, R represents the matching range of the query image; N represents the set of all images before the query image; f is the frame rate of the camera; T is a predefined parameter; f·T is the set of f·T frame images before the current image. By adding this constraint, the false positive problem of loop closure detection can be avoided.

[0043] If the database image is within the matching range R of the query image, the similarity between the two images is calculated based on the global feature vectors corresponding to the two images.

[0044] Furthermore, in the above method, in step (5), SURF features are extracted from the query image and the loop candidate image respectively as follows:

[0045] For the current query image I i and loop candidate image I n The process of extracting SURF features is the same. For the features of the image, they are mapped from coarse to fine into binary codes through CasHash. The CasHash algorithm uses an m-bit hash table L, and then each feature p is assigned to a bucket g. l (p). L function g l (q) is expressed by the following formula, where h s,l (1≤s≤m, 1≤l≤L) are independently and uniformly randomly generated from a local sensitive family H.

[0046] g l (q)=(h 1,l (q), h 2,l (q), ..., h m,l (q)), l = 1, 2, ..., L

[0047] The original SURF features have 128-dimensional floating point descriptors, while using CasHash these features can be changed to m-bit binary encodings.

[0048] Furthermore, in the above method, in step (5), matching the descriptors of the two images is specifically performed as follows:

[0049] Binary coding is used for ratio testing, and the binary ratio test threshold ε is defined as:

[0050]

[0051] Where H(·) represents the Hamming distance, C a is image I a Medium descriptor f a The binary encoding of and is image I b The two closest descriptors and The binary code of . 2 Low feature matches are considered good matches and are fed to RANSAC to compute the fundamental matrix T between the query and loop candidate images. If a loop candidate cannot compute T or the number of inliers between the two images is less than the parameter τ, the loop candidate is ignored.

[0052] Compared with the prior art, the present invention has the following beneficial effects:

[0053] 1. The present invention improves and redesigns the NetVLAD network model, takes VGG16 as the backbone of the network, and adds a second-order attention module, which can effectively learn the correlation between features. Then, a trainable local aggregation descriptor vector (NetVALD) is added to the last layer of the network to generate global features of fixed length. The present invention adds an attention mechanism to make the global features generated by the network model more robust in scenes with viewpoint changes and illumination changes.

[0054] 2. The present invention uses a geometric verification method to determine whether a loop is formed between the loop candidate image and the current query image. First, the SURF features of the image are extracted, and then converted into binary hash codes through the CasHash algorithm to perform feature matching between images. After each feature is encoded as a hash code, it occupies a small memory space, which is very important in the application of mobile robots. Therefore, this method can not only reduce the amount of calculation, but also verify whether the loop is correct. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.

[0056] Figure 1It is the overall structure flow chart of the present invention.

[0057] Figure 2 Schematic diagram of the network model based on VGG16, SOA and NetVLAD.

[0058] Figure 3 This is the network structure diagram of the SOA module. DETAILED DESCRIPTION

[0059] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0060] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0061] Example 1

[0062] See also Figures 1 to 3 , this embodiment provides a loop detection and optimization method based on the second-order attention mechanism, such as Figure 1 As shown, the specific steps include:

[0063] Step (1), build a network model that integrates VGG16, second-order attention mechanism (SOA) and NetVLAD. Figure 2 The following is a schematic diagram of the constructed network model. The network consists of three parts: the VGG16 structure, the SOA module, and the NetVLAD pooling layer. The first part removes the pooling layer and the fully connected layer after the last convolutional layer conv5_3 of VGG16. The SOA module is added later to learn the correlation between all spatial positions. Figure 3 As shown in Figure 2, the NetVLAD layer is used as the last layer of the network.

[0064] Step (2), using knowledge distillation to train the network model to obtain the optimal parameters is as follows:

[0065] Step (2-1) uses knowledge distillation to train and build a network model on the Google Landmark dataset to obtain the optimal parameters.

[0066] Step (2-2), use the global feature extraction network as the student network and the pre-trained NetVLAD network with VGG16 as the backbone as the teacher network. Train our global feature extraction network by minimizing the mean square error (MSE) loss between the global features predicted by the teacher network and the global features predicted by the student network;

[0067] Step (3) preprocesses the query image and the database image, and then inputs them into the SOA-NetVALD network to extract the global features of the query image and the database image:

[0068] Step (3-1), first resize the image to 224×224 pixels and subtract the mean data of the RGB channels. Then input the image into the network model that has been trained on the dataset, and use the output of the last NetVLAD layer as the global feature representation of the image.

[0069] Step (4): Use the local sensitive hashing (LSH) method to reduce the dimension of the global feature vector obtained in step (3), calculate the cosine similarity between the images, and obtain the loop candidate frame based on the similarity:

[0070] Step (4-1), the output of the last NetVLAD layer is used as the global feature of the image represented as V i (I) Where I represents the image and d represents the dimension of the global feature vector. For our global features, the hash function is defined as follows:

[0071]

[0072] Where r is a spherically symmetric random vector of unit length generated from a d-dimensional space, and v represents the global feature vector of the image. By defining k random vectors r, the dimensionality reduction of the convolution feature vector can be achieved, that is, the feature vector can be represented by bytes of length k. For two global feature vectors u and v, then:

[0073]

[0074] Therefore, the cosine similarity between u and v can be obtained:

[0075] sim(u,v)=cos(θ(u,v))=cos((1-P r [h r (u) = h r (v)])π)

[0076] Step (4-2), calculate the cosine similarity between the query image and the global feature vector of the database image, and sort the database images from high to low according to the cosine similarity. Select the top k database images in the sorting result as loop closure candidate images.

[0077] Step (5) introduces geometric verification to determine whether the query image and the loop candidate image constitute a true loop. First, the SURF features of the query image and the loop candidate image are extracted, and then the CasHash algorithm is used to perform paired image matching. Specifically:

[0078] For the current query image I i and loop candidate image I n The process of extracting SURF features is the same. For the features of the image, they are mapped from coarse to fine into binary codes through CasHash. The CasHash algorithm uses an m-bit hash table L, and then each feature p is assigned to a bucket g. l (p). L function g l (q) is expressed by the following formula, where h s,l (1≤s≤m, 1≤l≤L) are independently and uniformly randomly generated from a local sensitive family H.

[0079] g l (q)=(h 1,l (q), h 2,l (q), ..., h m,l (q)), l = 1, 2, ..., L

[0080] The original SURF features have 128-dimensional floating point descriptors, while using CasHash these features can be changed to m-bit binary encodings.

[0081] Step (6) uses the random sampling consensus algorithm (RANSAC) to eliminate mismatches and select the final loop candidate frame as follows:

[0082] Binary coding is used for ratio testing, and the binary ratio test threshold ε is defined as:

[0083]

[0084] Where H(·) represents the Hamming distance, C a is image I a Medium descriptor f a The binary encoding of and is image I b The two closest descriptors and The binary code of . 2 Low feature matches are considered good matches and are fed to RANSAC to compute the fundamental matrix T between the query and loop candidate images. If a loop candidate cannot compute T or the number of inliers between the two images is less than the parameter τ, the loop candidate is ignored.

[0085] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A loop detection and optimization method based on a second-order attention mechanism, characterized in that: The following steps are involved: Step (1), construct the network model SOA-NetVLAD that integrates VGG16, second-order attention mechanism SOA and NetVLAD: crop VGG16, add the SOA module after the conv5_3 layer of VGG16, and add the pooling layer NetVLAD to the last layer; Step (2), using knowledge distillation to train the network model to obtain the optimal parameters; Step (3), preprocessing the query image and the database image, and then inputting them into the SOA-NetVALD network to extract the global features of the query image and the database image; Step (4), using the local sensitive hashing (LSH) method to reduce the dimension of the global feature vector obtained in step (3), and calculating the cosine similarity between images, sorting the database images according to the similarity scores, and taking the first k sorted database images as loop closure candidate frames; Step (5) introduces geometric verification to determine whether the query image and the loop candidate image constitute a true loop. First, the SURF features of the query image and the loop candidate image are extracted, and then the CasHash algorithm is used to perform pairwise image matching. Step (6): Use the random sampling consensus algorithm RANSAC to eliminate false matches and select the final loop candidate frame.

2. According to claim 1, a loop detection and optimization method based on a second-order attention mechanism is characterized in that: The step (1) comprises the following steps: Step (1-1), modify the VGG16 network, delete the pooling layer and the fully connected layer after the last convolutional layer conv5_3, including the RELU activation function, and connect the SOA module to the convolutional layer conv5_3 to obtain the second-order feature map. Finally, connect the NetVLAD layer to the back of the SOA module as a new pooling layer. The NetVLAD layer introduces the idea of ​​VLAD into the convolutional neural network; Step (1-2), for the C×W×H-dimensional feature map x∈R output by VGG16 C×W×H , which is considered as a C-dimensional local descriptor x with a total number of W×H ij , i = 1, 2, ..., W, j = 1, 2, ..., H, first generate two maps denoted as f(x) and g(x) through 1×1 convolution with D output channels, then pass through batch normalization layer and swish activation, where D = 2×C, then flatten the maps f(x) and g(x) to size D×HW, the result of the second-order attention map is as follows: m=softmax(α·f(x) T g(x)) Where α is the scaling factor, f(x) T is the transpose of f(x). The size of the resulting second-order attention map m is HW×HW, and its value represents the correlation between local descriptors in the feature map m. Finally, the feature map x and the second-order attention map m are merged to obtain the output of the second-order attention module SOA(x): SOA(x)=x+v(m′) Where m′ is a tensor of shape HW×H×W obtained by changing the size of the attention map m, v is a 1×1 convolution function that restores the channel size from HW to C, and the size of the second-order feature map SOA(X) is C×W×H, the same as the size of the input feature map x; Step (1-3), add a trainable NetVLAD layer after the second-order attention module to aggregate the second-order feature map SOA(x) into a compact global descriptor. VLAD is a description method commonly used in image retrieval and image classification. The aggregated local descriptors are constructed into a vector and used as the global descriptor of the image. If the input of VLAD is N D-dimensional feature vectors {x i }, the parameter is K cluster centers c k , the output is a K×D-dimensional feature vector, which is written in the form of a matrix, denoted as V, and the calculation formula is as follows: where x i (j) and c k (j) represents the jth element of the i-th eigenvector and the k-th cluster center, respectively. k (x i ) represents the weight of the i-th feature vector corresponding to the k-th cluster center. When the feature belongs to this cluster center, the weight is 1, otherwise it is 0. Since VLAD is a discrete function and cannot be back-propagated, the NetVLAD layer adopts an approximate method to convert a k (x i ) is softly assigned to multiple cluster centers to make it differentiable: where w k =2αc k ,b k =-α‖c k ‖ 2 , α is a parameter greater than 0, when α→∞, The above formula is a softmax function, and the feature vector output by the NetVLAD layer is:

3. The loop detection and optimization method based on the second-order attention mechanism according to claim 1, characterized in that: The step (2) comprises the following steps: Step (2-1), train and construct a network model using knowledge distillation on the Google Landmark dataset to obtain the optimal parameters; Step (2-2), use the global feature extraction network SOA-NetVLAD as the student network, and use the pre-trained NetVLAD network with VGG16 as the backbone as the teacher network, and train the global feature extraction network by minimizing the mean square error MSE loss between the global features predicted by the teacher network and the global features predicted by the student network.

4. According to claim 1, a loop detection and optimization method based on a second-order attention mechanism is characterized in that , the step (3) includes the following contents: Step (3-1): first resize the image to 224×224 pixels and subtract the mean data of the RGB channels. Then input the image into the network model that has been trained on the dataset, and use the output of the last NetVLAD layer as the global feature representation of the image.

5. The loop detection and optimization method based on the second-order attention mechanism according to claim 1, characterized in that: The step (4) comprises the following steps: Step (4-1), the output of the last NetVLAD layer is used as the global feature of the image represented as V i (I) Where I represents the image, d represents the dimension of the global feature vector, and for the global feature, the hash function is defined as follows: Where r is a spherically symmetric random vector of unit length generated from a d-dimensional space, and v represents the global feature vector of the image. By defining k random vectors r, the dimensionality reduction of the convolution feature vector is achieved, that is, the feature vector is represented by bytes of length k. For two global feature vectors u and v, then: Therefore, the cosine similarity between u and v is obtained: sim(u,v)=cos(θ(u,v))=cos((1-P r [h r (u) = h r (v)])π)Step (4-2), calculate the cosine similarity between the query image and the global feature vector of the database image, sort the database images from high to low according to the cosine similarity, and select the top k database images in the sorting results as loop closure candidate images.

6. A loop detection and optimization method based on a second-order attention mechanism according to claim 5, characterized in that , the step (4-2) includes the following contents: In the process of database image acquisition, there is a high similarity between adjacent images, which will lead to false loop closure. In order to avoid the adjacent images of the query image becoming loop closure candidate frames and causing false positives, a constraint is introduced to limit the matching range of the query image. The specific matching range of the query image is: R=Nf·T Among them, R represents the matching range of the query image; N represents the set of all images before the query image; f is the frame rate of the camera; T is a predefined parameter; f·T is the set of f·T frame images before the current image. By adding this constraint, the false positive problem of loop closure detection can be avoided; If the database image is within the matching range R of the query image, the similarity between the two images is calculated based on the global feature vectors corresponding to the two images.

7. A loop detection and optimization method based on a second-order attention mechanism according to claim 1, characterized in that , the step (5) includes the following contents: For the current query image I i and loop candidate image I n The process of extracting SURF features is the same. For the features of the image, they are mapped from coarse to fine into binary codes through CasHash. The CasHash algorithm uses an m-bit hash table L, and then each feature p is assigned to a bucket g. l (p), L function g l (q) is expressed by the following formula, where h s,l , 1≤s≤m,1≤l≤L, is generated independently and uniformly randomly from a local sensitive family H; g l (q)=(h 1,l (q),h 2,l (q),…,h m,l (q)),l=1,2,…,L The original SURF features have 128-dimensional floating point descriptors, while using CasHash these features can be changed to m-bit binary encodings.

8. A loop detection and optimization method based on a second-order attention mechanism according to claim 1, characterized in that , the step (6) includes the following contents: Binary coding is used for ratio testing, and the binary ratio test threshold ε is defined as: Where H(·) represents the Hamming distance, C a is image I a Medium descriptor f a The binary encoding of and is image I b The two closest descriptors and The binary code is better than ε 2 A low feature match will be considered a good match and fed to RANSAC to compute the fundamental matrix T between the query and loop candidate images. If the loop candidate cannot calculate T or the number of inliers between the two images is less than the parameter τ, the loop candidate is ignored.