Paper Notes: From Coarse to Fine: Robust Hierarchical Localization at Large Scale

0 Background

Visual localization is the task of estimating the camera pose for any given image in a large-scale scene when a map of the environment is available. A popular approach is to localize in two stages, from coarse to fine. First, image retrieval finds the closest keyframe. Then, local features in the query image are matched to those in that keyframe. Since the keyframe’s pose is known, a method such as PnP can estimate the pose of the current frame. This two-stage approach avoids the computational cost of matching directly against every keyframe and the memory cost of loading the entire map.

This paper builds on the authors’ earlier work “Leveraging Deep Visual Descriptors for Hierarchical Efficient Localization”, in which the authors used MobileNetVLAD for image retrieval and local features such as FREAK and SIFT for pose estimation.

Before reading this paper, it’s worth taking a look at the CVPR 2020 Long-term Visual Localization challenge:

The combination of HF-Net from this paper and SuperGlue topped the rankings for handheld device localization, showing how competitive it is in practice.

1 Introduction

There are two main approaches to visual localization. The first is the so-called end-to-end approach, exemplified by PoseNet. These methods train directly on images and their ground-truth poses, then regress a 6DoF pose for a given image from the same scene. The advantage is that the database is very small: a single network can cover a large scene, and although training requires ground-truth poses, it does not require explicit 3D reconstruction. The drawback is just as clear: these methods simply learn a mapping from images to poses, which in essence amounts to matching images by similarity. As a result, they cannot recover the exact ground-truth pose or generalize to unseen scenes.

An approach that has been more successful in recent years is visual localization based on image retrieval. It proceeds from coarse to fine: global features are used to retrieve keyframes from the database (coarse localization), and local feature matching is then used to estimate the 6DoF pose (fine localization). The diagram below illustrates the process:

The paper makes three main contributions:

  • The proposed method achieves state-of-the-art (SOTA) performance on several large-scale localization datasets.
  • The paper introduces HF-Net, which produces the feature outputs needed for the coarse-to-fine pipeline in a single multitask network.
  • The paper demonstrates the effectiveness of knowledge distillation for multitask learning in real-world scenarios.

2 Hierarchical Localization

The diagram above shows HF-Net’s hierarchical localization pipeline, which consists of the following steps:

Prior retrieval
First, kNN search retrieves the k closest keyframes from the full database. The authors argue that because an SfM model contains far more feature points than keyframes, retrieving keyframes first is more efficient than matching feature points directly.

Covisibility clustering
The poses of the k retrieved keyframes are clustered, and the keyframes whose positions are most tightly grouped are selected as candidates.

The diagram already explains the idea behind hierarchical localization clearly, so there’s no need to go over it again here.

Local feature matching
This stage combines local feature matching with geometric verification using standard methods such as RANSAC to establish the final 3D–2D correspondences.

3 HF-Net (Hierarchical Feature Network)

HF-Net is a multitask network that combines global and local feature extraction. It produces three outputs directly from a single image: keypoints, local descriptors, and a global feature. This makes it well suited to performance-critical tasks such as SLAM.

3.1 HF-Net Architecture

The authors combine image retrieval and local feature extraction in a single network called HF-Net. It uses MobileNet as its backbone and then splits into two branches: NetVLAD outputs a global image descriptor, while SuperPoint outputs keypoints and their corresponding descriptors. The architecture is shown below. During training, knowledge distillation from teacher networks helps the lightweight network approach their accuracy while maintaining high inference speed.

As shown above, the overall architecture follows MobileNetVLAD. Its main components are:

  • Backbone: MobileNet is used for speed;
  • Global features: NetVLAD takes the MobileNet output and produces a global descriptor;
  • Local features: The output of the first seven MobileNet layers feeds into the SuperPoint decoder, which produces keypoints and dense local descriptors.

The code below shows exactly which layer’s output is used:

            'global_endpoint': 'layer_18',
            'local_endpoint': 'layer_7',

The authors also provide a detailed diagram of the network architecture in the appendix:

3.2 Training Process

During training, the authors use knowledge distillation. Simply put, the outputs of a larger network that has already proven effective serve as supervision signals for a smaller network, allowing the smaller network to approximate the performance of the larger one.

The authors first discuss two main challenges in training this kind of multi-task network:

Problem 1: Data scarcity

For feature matching tasks like SLAM, it is difficult to obtain enough data that includes both global and local descriptions.

Problem 2: Data augmentation

SuperPoint uses extensive data augmentation during training to make its local feature descriptors robust to changes in lighting, blur, noise, and so on. But while aggressive data augmentation can help the network learn local features, it can also make global features harder to learn.

To address these issues, the authors propose multi-task distillation.

Method: Multi-task distillation

The authors draw on a technique from the earlier paper “Multi-task learning using uncertainty to weigh losses for scene geometry and semantics” to design a loss function that learns its weights automatically. This allows a student network S to learn from the teacher networks t_1, t_2, and t_3 at the same time, without having to tune the weights manually.

The resulting loss function is:

\begin{aligned}L &=e^{-w_{1}}\left\|\mathbf{d}_{s}^{g}-\mathbf{d}_{t_{1}}^{g}\right\|_{2}^{2}+e^{-w_{2}}\left\|\mathbf{d}_{s}^{l}-\mathbf{d}_{t_{2}}^{l}\right\|_{2}^{2} \\&+2 e^{-w_{3}} \text { CrossEntropy }\left(\mathbf{p}_{s}, \mathbf{p}_{t_{3}}\right)+\sum_{i} w_{i}\end{aligned}

Here, \mathbf{d}^{g} and \mathbf{d}^{l} are the global and local feature vectors, respectively, \mathbf{p} represents the keypoint scores, and w_{1,2,3} are the weights learned automatically.

This multi-task distillation approach can be used in many settings and can use other networks or even traditional methods.

3.3 Teacher Models

The network design above looks promising, but how do you choose the teachers for a knowledge distillation network? The authors ran the following experiments to select the three teachers:

Global Feature
There isn’t much of a choice here: NetVLAD is currently the go-to method. I covered it in an earlier blog post (Paper Notes: NetVLAD: CNN architecture for weakly supervised place recognition).

Detectors

The authors compared DoG, Harris, SuperPoint, and LF-Net. Based on the detector experiments, they concluded that SuperPoint offered a better balance between repeatability and MLE.

Descriptors

The authors compared several leading methods: Root-SIFT, LF-Net, SuperPoint, and DOAP. From the descriptor experiments, they drew the following conclusions:

  • DOAP blew the other descriptors away on the SfM dataset (no results were reported for HPatches because DOAP was trained on it).
  • SuperPoint performed best on the homography task, but its matching performance was best only when it used its own keypoints. It performed poorly with Harris keypoints.

DOAP and SuperPoint each had their strengths, so the authors ran another experiment:

The authors drew the following conclusions from this experiment:

  • DOAP’s performance dropped noticeably on nighttime datasets and was less consistent, possibly because it did not use the same sophisticated data augmentation as SuperPoint.
  • Comparing NV+SP with NV+HF shows that HF-Net’s local features perform slightly better than SuperPoint’s. This is surprising: since HF-Net was distilled from SuperPoint, you would normally expect a small drop in performance. The authors explain that adding global feature supervision to the same network lets it learn from deeper semantic features, which indirectly improves its shallower keypoint features.

Based on these experiments, the authors ultimately chose SuperPoint to supervise HF-Net’s keypoints and descriptors, and NetVLAD to supervise its global features.

4 Experiments

Illustrations of successful examples:

Public dataset accuracyThe evaluation results are as follows:

On public datasets, the speed benchmark results are as follows:

Some examples on HPatches:

Some SfM examples:

Personal Takeaways

The authors ran fairly detailed experimental comparisons, paying particular attention to the choice of Teacher. The paper’s motivation is clear, and the overall approach comes together naturally. The network architecture also has practical value in real-world applications.

Related Resources

Download the paper:


Source code on GitHub:
https://github.com/ethz-asl/hfnet

Add a Comment

Your email address will not be published. Required fields are marked *