{'fraction_non_alphanumeric': 0.0377074892170958, 'fraction_numerical': 0.015161416808260358, 'mean_word_length': 4.968408736349454, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learning Local Features with Context Aggregation for Visual Localization

Keypoint detection and description is fundamental yet important in many vision applications. Most existing methods use detect-then-describe or detect-and-describe strategy to learn local features without considering their context information. Consequently, it is challenging for these methods to learn robust local features. In this paper, we focus on the fusion of low-level textual information and high-level semantic context information to improve the discrimitiveness of local features. Specifically, we first estimate a score map to represent the distribution of potential keypoints according to the quality of descriptors of all pixels. Then, we extract and aggregate multi-scale high-level semantic features based by the guidance of the score map. Finally, the low-level local features and high-level semantic features are fused and refined using a residual module. Experiments on the challenging local feature benchmark dataset demonstrate that our method achieves the state-of-the-art performance in the local feature challenge of the visual localization benchmark.


Introduction
Visual localization is an important research topic in computer vision since it plays a critical role in many tasks such as loop closure detection and re-localization. Three approaches are commonly used to solve this problem, including 3D structure-based methods [26] [14][36] [30], 2D image-based methods [1] [16][25] [32] and learning-based methods [5][3] [13]. Among these methods, 3D structurebased methods are more accurate than other methods.
For a 3D structure-based method, correspondences are first generated between 2D local features in the query image and 3D points constructed by dense Structure-from-Motion(SfM) models. The 6DoF camera pose is then recovered by PnP. Consequently, local features learning plays a vital role in visual localization.
Traditional local feature learning methods commonly detect keypoints in the first stage and then describe each key-point as a local descriptor. In general, a good local feature should have three types of properties, i) High repeatability: robust local features can be detected in different images. ii) High reliability: each local feature in an image should be descriminative. iii) High efficiency: the number of local features is much less than the number of pixels. Aiming for these properties, many handcrafted local features have been presented. For keypoint detection, corners [12] or blobs [15] are considered as low-level image information. Meanwhile, numerous handcrafted descriptors (such as histograms of gradient (HOG) [8] and its variants [2]) have also been proposed.
However, handcrafted methods are limited by the prior knowledge and easily influenced by the change of illumination, weather and season. With the development of deep learning, recent methods jointly learn keypoint detectors and descriptors in an end-to-end manner. Some methods learn the correspondences from dense SfM models produced by Colmap [28]. SuperPoint [9] learns the simple homography transformation using an artifact dataset. Sarlin et al. [24] proposed highly robust correspondances using teacher-student networks in HFNet. Revaud et al. [22] proposed EpicFlow [23] to produce semi-sparse matches and then learn correspondences. However, high-level semantic information of the image patches around local features is not fully considered in these.
Besides, visual localization still suffers from day-night and season variations. It is difficult to recover camera poses due to the weakness of local features when images are acquired across a long time. In contrast, high-level semantic information of an image is more robust and invariant than local features under these cases. To achieve robust performance, it is therefore reasonable to fuse low-level textural information with high-level semantic information.
In this paper, we propose a robust method to learn and combine high-level semantic information with its corresponding low-level textual features. Since high-level semantic information is constant under different conditions, the repeatability and reliability of the fused local features can be finally improved. Following the previous work R2D2 [22], we use the repeatability map and the reliability map to generate the score map. Then, we use the score map to mask the semantic features produced by HR-Net [29]. This local-guided module is employed to choose semantic features adaptively. Next, we apply a multi-scale aggregation module to aggregate semantic features in a specific neighborhood. Finally, we design a residual module to refine the fused features.
Compared to recent local feature learning approaches [17][10] [22] [18], our work makes the following contributions: 1) Different from Contextdesc [17], we fuse semantic information with local features before keypoint detection to obtain robust keypoints and descriptors. 2) We design a residual module to refine low-level textual features automatically. 3) Compared to R2D2, no additional constraint is required by our work.

Related Work
Localization Benchmarks. KITTI [4], TorontoCity [33] and the Michigan North Campus Long-Term (NCLT) [11] are commonly used visual localization benchmarks. However, these benchmarks do not exhibit all complex scenes in the real world. To hanlde this problem, Sattler et al. [27] introduced the Aachen Day-Night dataset for local feature and device challenges. The Aachen Day-Night dataset provides several types of challenging scenes, including day-night changes and illumination changes (dawn/noon). Besides, they pproposed the RobotCar Seasons Dataset and the CMU Seasons Dataset for autonomous vehicles challenges, including weather (dust/sun/rain/snow) and seasonal (winter/summer) variations. In this paper, we focus on local feature learning. Therefore, we evaluate our method on the Aachen Day-Night dataset.
Joint Local Feature Learning. Joint learning of feature detectors and descriptors has attracted increasing attention due to its computational efficiency. Yi et al. [35] used three subnetworks to predict keypoints, their corresponding orientations and descriptors. Besides, they replaced the Non-Maximum Suppression (NMS) with the soft argmax function. DeTone et al. [9] used artificial homography transformations to generating image pairs as the training data, which were used to learn point-wise pixel level correspondences. Yuki et al. [20] generated the relative pose and corresponding depth maps of image pairs by SfM. Then, they proposed LFNet to minimize the difference between image pairs. Recently, R2D2 [22] simultaneously estimated descriptors, reliability map and repeatability map. Reliability map and repeatability map are further used to detect keypoints. In D2-Net [10], a describe-and-detect approach is proposed by generating descriptors and keypoints from the same feature maps. However, this method is hard to detect accurate keypoints learned from low-resolution fea-ture maps. Based on D2-Net, Deformable Convolutional Network (DCN) [7] [37] is used in ASLFeat [18] to model geometric variations. Besides, multi-level keypoint detection is integrated into an end-to-end network in ASLFeat. Although dynamic receptive filed is learned by DCN, it still works on low-level textural information. In Contextdesc [17], context information is leveraged to augment local descriptors after keypoint detection. In contrast, we aggregate high-level semantic features with local features before keypoint detection. Consequently, the proposed architecture achieves better performance on both keypoint detection and descriptor learning.

Methods
The backbone architecture in this work consists of two parts: 1) a high-resolution network (HRNet) [29] that extracts high-level semantic features, and 2) a R2D2 network [22] that jointly learns local features, reliability maps and repeatability maps.

Prerequisites
High-resolution network (HRNet) [29] is able to maintain a high resolution without recovering the resolution through a low-to-high process. Different from other existing methods, HRNet can boost the high-resolution representation by fusing low-resolution representations at different scales. Consequently, better high-level semantic features can be produced for local feature learning.
R2D2 [22] enables repeatability and reliability prediction for descriptors. Based on L2Net [31], the last 8×8 convolutional layer is replaced by three successive 2 × 2 convolutional layers to improve computational efficiency. Based on the output of L2Net, an L2-normalization layer is used in R2D2 to obtain dense feature descriptors. Meanwhile, a reliability map and a repeatability map are predicted in R2D2 using an element-wise square operation, a 1 × 1 convolutional layer and a softmax operation. In addition, a selfsupervised loss is introduced in R2D2 to learn repeatable and reliable keypoints and descriptors.

Network Architecture
The network architecture is illustrated in Figure 1. Following R2D2 [22], we replace the last 8 × 8 convolution of L2-Net by three 3 × 3 convolutions, resulting in a 128dimension tensor. Then, we predict initial descriptors, initial repeatability and reliability maps using the tensor. Next, the initial repeatability and reliability maps are used to obtain the score map by element-wise multiply operation. To extract high-level semantic features, we apply the HRNet-W48 model. Then, we design a local-guided module using the score map to obtain the selective semantic features. Besides, we introduce a multi-scale aggregation module to aggregate the context information of the selective semantic  features. The residual of low-level textual features can be obtained by a 1 × 1 convolution. After fusing the low-level textual features with the high-level semantic features, we use the same module as R2D2 to learn the final prediction.

Local-guided module
To extract useful information from high-level semantic features, we use repeatability map and reliability map as the guidance, as shown in Figure 1. Following R2D2 [22], we perform element-wise multiplication between the repeatability map and the reliability map to obtain score maps during keypoint detection. Then, we use a sigmoid function to normalize the score map into a probability map. Each value in the probability map represents the probability of becoming a potential keypoint for a pixel.
where i, j represent the position of pixel (i, j). Then, we use this score map to choose the high-level semantic features by an element-wise multiplication operation. Finally, the selective semantic features is obtained.

Multi-scale aggregation module
In Contextdesc [17], descriptors are leveraged by the contextual high-level semantic features. We aggregate selective semantic features before their fusion with low-level textual features, as shown in Figure 1(b). Specifically, we use three successive 3×3 convolutions to aggregate the contextual information from 3 × 3, 5 × 5 and 7 × 7 fields. Short connections between every two consecutive layers are used for all convolutional layers in this module. Consequently, more information can be absorbed from a small field by the multi-scale aggregation module.

Feature fusion and refinement
The feature map produced by the multi-scale aggregation module is considered as the residual of low-level textual features. Specifically, the output of the multi-scale aggregation module is first fused with the low-level textual features by concatenation. Then, channel aggregation is conducted on the concatenated feature map by a 1 × 1 convolution. Next, a refined feature map is obtained by an element-wise add operation between the low-level textual features and the output of the channel aggregation. Finally, the same head of R2D2 is used to predict the final descriptors, repeatability map and the reliability map.

Experimental Evaluation
We evaluate our method on the Aachen Day-Night dataset [27].

Implementation details
Localization Pipeline. We follow the pipeline of Colmap [28] to evaluate local features. First, our local features are imported into the database to generate a SfM model. Mutal NN matcher is used for feature matching. Then, query images are registered to this model. We follow Colmap to conduct the remaining steps, resulting in a 6DoF camera pose for each query image. The predicted 6DoF camera pose is then evaluated with three error tolerances (0.5m, 2 • ) / (1m, 5 • ) / (5m, 10 • ), where the first number in each parentheses represents the position error while the second number represents the orientation error.
The Aachen Day-Night Dataset. It contains 4,479 reference images and 369 query images acquired in Aachen, Germany, containing day-night variations. For the local fea-ture challenge, we only predicted 6DoF camera poses of 98 query images.
Training Details. We used the Oxford and Paris retrieval dataset [21] and some pairs from the Aachen Day-Night dataset [27] as the training data. We trained the network for 25 epoches, using Adam with a batch size of 4, a learning rate of 0.001 and a weight decay of 0.0005. HRNet was pre-trained on the Cityscapes dataset [6].
Loss Function. Given two images I and I of the same scene, their ground-truth correspondences U ∈ R H×W ×2 , and their repeatability maps S and S , a heatmap S U from image I can be warped according to U . A set of overlapping patches P = {p} containing all N × N patches in where L cos and L peaky is defined as Next, the Average Precision (AP) loss is used to learn the reliability in R2D2: where κ ∈ [0, 1] is a hyperparameter, which indicates the minimum expected AP for each patch. λ is also a hyperparameter to balance the initial prediction loss L initial and the final prediction loss L f inal .

Results
We compare our method to previous methods in recent years in Table 1. Our method achieves the state-of-theart performance in two metrics. As shown in Figure 2, our method detects more robust keypoints than the original R2D2 method based on KNN matcher.
We conducted several experiments on the dataset to justify our design modules, the results are shown in Table 2. With the local-guided module, the performance on (1m, 5 • ) is improved from 65.3 to 67.3. Further, the full model with both local-guided and multi-scale aggregation modules obtains better performance in terms of (0.5m, 2 • ) and (5m, 10 • ). These results demonstrate that introducing highlevel semantic information into low-level textual features is beneficial to learn robust local features.  Table 2. Ablation study of our network on the Aachen Day-Night dataset, where + LG and + MA represents the method with the local-guided module and the multi-scale module. Figure 2. Examples of matches obtained by our method (1st col) and the original R2D2 method (2nd col).

Conclusion
In this paper, we adopt R2D2 and HRNet as our backbone to jointly learn local features detectors and descriptors. The local-guided module and the multi-scale aggregation module can successfully fuse low-level textual features and high-level semantic features to improve the robustness of local features. Experimental results on a challenging dataset show that our method achieves the state-of-the-art performance in two metrics.