{'fraction_non_alphanumeric': 0.03312534146131064, 'fraction_numerical': 0.014463582252638238, 'mean_word_length': 4.95513698630137, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
ASpanFormer: Detector-Free Image Matching with Adaptive Span Transformer

Generating robust and reliable correspondences across images is a fundamental task for a diversity of applications. To capture context at both global and local granularity, we propose ASpanFormer, a Transformer-based detector-free matcher that is built on hierarchical attention structure, adopting a novel attention operation which is capable of adjusting attention span in a self-adaptive manner. To achieve this goal, first, flow maps are regressed in each cross attention phase to locate the center of search region. Next, a sampling grid is generated around the center, whose size, instead of being empirically configured as fixed, is adaptively computed from a pixel uncertainty estimated along with the flow map. Finally, attention is computed across two images within derived regions, referred to as attention span. By these means, we are able to not only maintain long-range dependencies, but also enable fine-grained attention among pixels of high relevance that compensates essential locality and piece-wise smoothness in matching tasks. State-of-the-art accuracy on a wide range of evaluation benchmarks validates the strong matching capability of our method.


Introduction
Image matching lays the foundation for various geometric computer vision tasks, including Structure from Motion (SfM) [1,2], visual localization [3], and Simultaneous Localization And Mapping (SLAM) [4,5]. As a widely accepted pipeline for image matching, cross-image correspondences are usually established by matching a set of detected and described sparse keypoints, such as SIFT [6], ORB [7], or their learning-based counterparts [8,9,10,11,12]. Despite its general effectiveness, this detector-based matching pipeline struggles in extreme situations, including large view point changes and textureless areas, due to the reliance on keypoint detector and context loss in feature description.
Concurrent with detector-based matching, another line of works focus on generating correspondences directly from raw images [13,14,15,16,17,18,19,20,21], Particularly, in the top row, a rectangle with 8 × 8 uniform sampling grid is drawn to explain the position and size of adaptive attention span. In addition, three typical types of correspondences are visualized. Easy match in green with rich texture, which can be well localized and matched with small local contexts. Hard match in yellow with little texture, which requires larger contexts to guide matching. Impossible match in red in non-overlapping or occluded region, which has a very large attention span to avoid falsely fitting to certain regions. With this design, we enable Transformer to adaptively capture necessary context according to matching difficulty.
where richer context can be leveraged while keypoint detection step can be eschewed. Earlier works [16,22,17] in detector-free matching often rely on iterative convolution upon correlation or cost volume to discover potential neighbourhood consensus. Recently, some works [13,14,21] base their methods on Transformer [23,24] backbone for better modeling of long-range dependencies. As a representative work, LoFTR utilizes self and cross attention blocks to update cross-view features, where Linear Transformer [25] is adopted to replace global full attention in order to achieve manageable computation cost. Although proven effective, a concern about LoFTR is the lack of fine-level local interaction among pixel tokens, which could limit its capability to extract highly accurate and welllocalized correspondences. This concern is deepened by the findings [21] of Tang et al., which reveals that the cross attention map generated by LoFTR's Linear Transformer tends to diffuse among large areas instead of sharply focusing on actual corresponding regions.
To capture both global context and local details, we propose a Transformerbased detector-free matcher, equipped with a hierarchical attention framework. Our foundation processing blocks, referred to as Global-Local Attention (GLA) block, performs a coarse-level global attention at low resolution to acquire longrange dependencies, meanwhile, conducts fine-level local attention at high resolution within only a concentrated region around a current correspondence found through dense flow prediction.
The key challenge for fine-level local attention is to determine the size of the attention span. A naive approach is to regard its size as a fixed hyper parameter, which, however, neglects the intrinsic matchability of different regions where the dependency of context varies. As shown in Figure 1, regions in rich texture areas can be easily matched within a small neighbourhood, while the textureless areas are more uncertain about their correspondences and require larger context for matching, not to mention areas that lie out of overlapping regions and are impossible to be matched. To mitigate this issue, we introduce an adaptive attention span driven by probabilistic modelling, which can be adjusted for different locations based on underlying matching difficulty. We summarize our contributions in three aspects: -A hierarchical attention framework is proposed for feature matching, where attention operations are performed at different scales to enable both global context awareness and fine-grained matching. -A novel uncertainty-driven scheme, based on probabilistic modelling of flow prediction, is proposed to adaptively adjust local attention span. Through this design, our network assigns varying size of contexts to different locations according to their essential matchability and context richness. -State-of-the-arts results on extensive set of benchmarks are achieved. Our method outperforms both detector-free and detector-based matching baselines in two-view pose estimation. Further experiments on challenging visual localization also proves our method's potential to be integrated into c omplicated down-stream applications.

Detector-Free Image Matching
Differing from detector-based matching methods, which typical involve detecting [11,9,10,8], describing [26,27,28,12,29] and matching [30,31,32,33,34,35,36] a set of keypoints, detector-free matching consumes a pair of images and output correspondences in one shot. Thanks to the removal of keypoint detection stage, detector-free matching is able to capture richer contexts from original images, thus exhibits strong potential to match in extreme situations, such as low texture areas and repetitive patterns. Despite the potential merits of detector-free matching, its popularity hardly outperforms detector-based methods during early deep learning times due to the intrinsic difficulties in robust and distinctive features. Recently, with the help of deep neural network, possibility is explored to build high performance detector-free matching frameworks based on deep features, which can roughly be classified into two categories: cost volume-based methods [16,18,15,22,17,37] and Transformer-based methods [13,14,21]. Both kinds of methods leverage strong signals in deep features' correlation, either in form of correlation layer or cross attention, to guide correspondence search and feature update. Our method follows works on Transformer-based methods and employs multilevel cross attention for mutual feature update, encoding two-view contexts into original features for both global and local consensus.

Global-Local Structure
Balancing receptive field and interaction granularity is a long-standing issue for both cost volume-based and Transformer-based matching. To ensure global receptive field, cost volume based methods are often designed to perform convolution on large global correlation volume, while Transformer-based methods need to conduct attention among all pixel tokens in image pairs. Due to the high cost of global interaction, the input features are usually downsampled into coarse resolution [17,18,14] or being projected into low rank [13], which to some degree limits the networks' capability for fined grained feature update.
Complementary to global interaction, some methods propose to perform local interaction only within a certain region instead of a global field, enabling to process fine level features given a limited computation budget. This practice is especially common in cost volume based methods and are referred to as local correlation layer [18,38,15,39], where the cost volumes/vectors are only constructed around neighbourhood of each correspondence estimation. Intuitively, the idea of complementary global-local interaction can also be introduced to Transformer-based matcher. In our method, a global-local attention block is proposed for message passing across images, ensuring both global receptive field and fine level feature processing. Specially, instead of fixing span for local attention, we design an adaptive mechanism to determine the size of area that each pixel should attend to.

Flow Regression and Uncertainty Modeling
Flow maps depicts correspondence coordinates, which can either be absolute or relative, for each location in an image. Predicting correspondence coordinates from an image pair has been intensively investigated by works in optical flow estimation [40,38,41,39] and general dense image matching [18,15,37]. In these works, the flow maps are regressed from structured correlation volumes which are implicitly position-aware. Recently, a Transformer-based method, COTR [14], proves that flows can also be retrieved from positional-embedded features after several turns of attention update.
Naturally, the reliability of flow estimation in each location is not equal and predicting associated confidence scores is essential for many scenarios. As an elegant framework for uncertainty prediction, some works [15,42,43,44,45] propose to use probabilistic model to jointly explain both flows estimations and their confidence. Inspired by above works, we propose a network that regresses a flow map for each attention block to guide local attention region and adjust the attention span adaptively based on uncertainty prediction.  Fig. 2. We use CNN backbone to extract initial features. After initialization, the features are fed into iterative GLA blocks for updating. A matching module is used to determine final matches.

Methodology
We present an overview of our network structure in Figure 2. Taking an image pair I A , I B as input, our network produces reliable correspondences across images. The matching process starts with a CNN-based encoder to extract initial features F 0 A , F 0 B for both images separately. After initialization, these features are turned into F 1 A , F 1 B and fed into the proposed Adaptive Span Transformer (ASpanFormer) module for updating, which is composed of iterative global-local attention (GLA) blocks with hierarchical structure. Particularly, for each GLA block, we regress auxiliary flow maps φ A , φ B describing correspondence coordinates (flows) and their uncertainty. Instead of adopting these flow maps as our correspondence output, we use them to guide local cross attention, enabling adaptive local attention span according to matching uncertainty. After N GLA blocks, the updated features F are use to construct coarse level matches, which will be further refined into final correspondences.
In the following part, we demonstrate the details of each individual block as well as the underlying insights.

Preliminary
Before introducing the structure of our network, we first clarify necessary notations and concepts.
Attention. As the key operation in Vision Transformer, attention is defined over a set of query (Q), key (K) and value (V ) vectors as where Q, K, V are linear projections of upstream features F and M is retrieved message. More specially, in the context of cross attention, Q are derived from source features F s and K, V vectors are derived from target features F t . M is used to update source features F s through a feed forward network (FFN), which involves concatenation, layer normalization and linear layers.
Typically, in each pass, the position of source/target features can be switched and cross attention is performed symmetrically.
Flow map. Flow maps φ A , φ B ∈ R H×W ×2 depict the correspondence relationship between an image pair I A , I B ∈ R H×W , such that for any location (i, j) in an image, Here, ↔ denotes that the points on two sides are correspondences. Instead of depicting simple correspondences, a stream of works [15,42,43,44,45] proposes to model flow field with a probabilistic framework. Following these works, we model the flow field as a Gaussian distribution defined by a set of parameters. More specifically, assuming conditional independence among pixels, x , u ij y ) are estimated correspondence coordinates and (σ ij x , σ ij y ) are standard deviations. The probability for Instead of thresholding flow estimation with uncertainty, we use it to adjust the search region for subsequent network interaction, as described in later sections.

Feature Extractor
As the first part of our network, a convolutional neural network (CNN) is used As is shown in previous works [10,8,9,12,28,27,26,29], CNN exhibits strong capability to capture local context and generates high-level features, which can be directly used to perform nearest neighbour matching. However, since these features are processed independently for each image and critical cross view contexts are missed. To enrich features with long range and cross view contexts, the initial features are further fed into our proposed Transformer module for updating.

Initialization
Our Transformer-module starts with a fast initialization block, which conducts (1) positional encoding and (2) two-view contexts initialization. Positional encoding. As validated in Transformer networks [13,30,14], positional encoding is critical in maintaining spatial information for the flattened tokens. Following the same formulation in LoFTR [13], 2D sinusoidal signals in different frequencies are used to encode position information and are added to initial features. Specially, we apply normalization when testing resolution differs from training resolution. We provide more details in Appendix A.5. Two-view contexts initialization. At each local attention phase, our network requires regressing an auxiliary flow map as guidance, which requires cross view contexts. To this end, we pass positional embedded features to a light-weight cross attention block. More specifically, These features are downsampled to low resolution H 0 , W 0 and two global cross attention blocks are used for feature processing. After initialization, the features are upsampled back to original input resolution, denoted as F 1 A , F 1 B , and sent to iterative global-local attention blocks for further processing.

Global-Local Attention Block
The basic structure of our Transformer network is global-local attention (GLA) block. As is shown in Figure 2, for each GLA block, attention is performed upon a 3-level coarse-to-fine feature pyramid built by strided average pooling. For The FFN in our network is defined as LN stands for layer normalization. Specially, we adopt a 3×3 convolution Conv 3 in FFN for locality modeling, which compensate for the absence of self attention within each feature map. Empirically, we find 3 × 3 convolution in FFN works better than the combination of linear projection FFN and self attention, more details can be found in Appendix A.5.

/
[ , ] * * Local cross attention with adaptive attention span. To facilitate finegrained attention with modest cost, we adopt local attention on medium and fine level feature maps, where attention span focuses on the neighbourhood regions around current correspondences estimation.
A key problem for local attention is how to define the size of neighbourhood region. A naive approach is to define neighbourhood with a fixed radius r for all pixels, neglecting the fact that the optimal attention span for different regions varies. For instance, it is sufficient to match regions with distinctive features using small contexts, while regions that are harder to match require larger contexts. Instead of using fixed attention span for all pixels, we propose to adaptively adjust the attention span according to the uncertainty of flow estimation. This design lets each area balance their local receptive fields with uncertainty awareness. Regions with high confidence in flow estimation can sharply focus on a small region for fine level matching, while larger contexts are extracted in low confidence areas for better convergence.
Formally, for the i-th GLA block, we first regress flow maps φ i A , φ i B from input features F i A , F i B in fine level with an MLP, while the medium level flow map are obtained by strided average pooling. For each scale level, we partition the corresponding query map Q into cells with size S × S. For each cell, we use the mean flow estimation to generate a rectangle region upon K, V map and uniformly sample a fixed number of tokens. Attention is performed between each cell and the sampled tokens. The detailed process is defined in Algorithm 1. An illustration for local attention is given in Fig. 3. Since number of sampled tokens for each location is fixed, the whole process retains linear complexity.

Matches Determination
We inherit the scheme in LoFTR [13] to generate final correspondences, including a coarse matching stage and a sub-pixel refinement stage.

Algorithm 1 Local Cross Attention
Input: Q, K, V ∈ R H×W ×C , φ ∈ R H×4 , span coefficient n, sample number w, window size S Output: Retrieved message M ∈ R H×W ×C 1: Partition Q into cells set Qp with window size S × S, there will be H S × W S cells in total 2: M = [ ] 3: for each cell Qpi ∈ R S 2 ×C in Qp do in parallel 4: Retrieving flow φp ∈ R S 2 ×4 from flow map φ according to the location of Qpi 5: Let [ux, uy, σx, σy] = φp = j φp[j, :] 6: Let Γ be a rectangle area with center [ux, uy], width n * σx and height n * σy 7: Uniformly sample w 2 tokens in Γ region from K, V , denoted as KΓ , VΓ ∈ R w 2 ×C 8: Attention mi = Att(Qpi, KΓ , VΓ ) 9: Append mi to M 10: Reshaping M into R H×W ×C 11: return M After being updated by N GLA blocks, we flatten the output features intõ F A ∈ R n×c ,F B ∈ R m×c and construct correlation matrix C = τF AF T B ∈ R n×m , where τ is a temperature parameter and n, m are feature numbers of two images. By applying dual-direction softmax in both column/row dimensions, a score matrix is given by S = softmax row (C) · softmax col (C), from which we retain coarse-level matches M c by mutual nearest neighbour (MNN) and filtering scores below a certain threshold θ. The coarse matches M c are further fed into a correlation-based refinement block, which is the same with LoFTR [13], to obtain the final matching results.

Loss Formulation
We formulate the final loss from three parts, (1) coarse matches loss L c , (2) fine-level loss L f and (3) flow estimation loss L f low For coarse level loss L c , the ground truth matches M gt is determined by reprojection using depth and camera poses in datasets. We supervise the dual-softmax score matrix S with cross entropy loss The fine-level loss is supervised directly with L2-distance between each refined coordinates M f (i, j) and ground truth reprojection coordinates, which are further normalized by the coordinate variance. For flow estimation supervision, we minimize the log-likelihood for each estimated distribution. Formally, given flow estimation Φ from each layer and ground truth flow D gt , L f low is defined as In our implementation, this log-likelihood formulation can be further substituted and decomposed into a more compact form, which is elaborated in Appendix B.

Implementation Details
Our network shares the same ResNet-18 [46] CNN feature extractor with LoFTR. After feature extraction and flow initialization, we use 4 GLA blocks for updating. For adaptive attention span, we set n = 5, meaning that using 5 standard deviation to crop local neighbourhood region for each token. We uniformly sample 8 × 8 features in each cropped local region. We train two different models specified for indoor and outdoor scenes respectively. Both models are optimized using Adam with learning rate 1 × 10 −3 for 30 epochs on 8 V-100 GPUs. Indoor model is trained on ScanNet [47]

Experiments
In this section, we demonstrate the performance of our method on two-view pose estimation and visual localization tasks, among both indoor and outdoor scenes. Besides, we conduct ablation study to validate the effectiveness of key design components of our method.

Two-view Pose Estimation
We resort to two popular datasets, ScanNet [47] and MegaDepth [48], introduced below, to demonstrate the matching ability of our method in indoor scenes and outdoor scenes, respectively. We also provide additional results on YFCC100M [49] and Image Matching Challenge(IMC) 2022 in Appendix C. Indoor two-view matching dataset. ScanNet dataset [47] is composed of 1613 sequences, each of which contains RGB images exposing large view changes and repetitive or textureless patterns, with ground-truth depth maps and camera poses associated. For fair comparison, we follow the same training and testing protocols used by SuperGlue [30] and LoFTR [13], where 230M and 1.5K image pairs are sampled for training and testing, respectively. In congruent with LoFTR, we resize all test images to 480 × 640. Outdoor two-view matching dataset. MegaDepth [48] consists of 196 3D reconstructions from 1M Internet images, whose camera poses and depth maps are initially computed from COLMAP [1] and then refined as ground-truth. We perform two view pose estimation on 1.5k testing pairs. All test images are resized so that their longest dimension is 1152.
Evaluation protocols. Following previous works [30,13], we train and evaluate our method separately on the two datasets. Two-view pose is recovered by solving essential matrix from correspondences produced, while pose accuracy is measured by AUC at multiple error thresholds (5 • , 10 • and 20 • ). A pose is only considered accurate if both its angular rotation error and translation error is under a certain threshold compared with ground-truth poses.

Visual Localization
Apart from evaluation on two-view pose estimation task, we further integrate our network into a visual localization pipeline, and use two popular datasets, InLoc [53] and Aachen Day-Night v1.1 [54,3,55] datasets, to demonstrate performance on multi-view matching in indoor scenes and outdoor scenes, respectively.
Indoor localization dataset. InLoc dataset [53] contains a database of 9, 972 RGBD indoor images that are geometrically registered to form the reference scene model, while 329 RGB query images are provided for visual localization, annotated with manually verified camera poses. Great challenge is posed in matching textureless or repetitive patterns under large perspective differences.
Outdoor localization dataset. Aachen Day-Night v1.1 dataset [54] depicts a city whose reference scene model is built upon 6, 697 day-time images. For visual localization, the dataset provides another 824 day-time images and 191 night-time images as queries. Great challenge is posed in identifying correspondences from, in particular, night-time images under extremely large illumination changes.
Evaluation protocols. We follow the instructions from Long-Term Visual Localization Benchmark [56] to compute query poses. For both datasets, we use pretrained HLoc [57] to retrieve candidate pairs, and recover camera poses with the model trained on MegaDepth dataset following SuperGlue [30] and LoFTR [13]. More details on localization pipeline are elaborated in Appendix A.4.
Results. On InLoc dataset, as shown in Table 3, our methods achieves overall best results compared with multiple comparative methods. On Aachen V1.1, as shown in Table 4, our method outperforms all other methods except SuperGlue. We partially ascribe this to the fact that we use only coarse matches for database reconstruction (see Appendix A.4.), causing localization error that harms pose estimation. In general, our method generalizes well in practical pipelines.

Ablation Study
To validate the effectiveness of different design components of our method, we conduct ablation experiments on ScanNet dataset [47] following the same setting in Section 4.1. Specifically, we compare three designs of attention structure: -Single-Level Attn.: A design with only global attention at coarsest feature maps without the need of flow estimation. In this design, global context is well captured, whereas essential locality in motion smoothness is omitted and fine-grained message exchange becomes difficult. -Multi-Level Attn.: A design with the hierarchical attention framework proposed in this paper, except that the size of local attention span is fixed to 13 px, i.e., the statistical mean of the adaptive attention span used in our network. -Adaptive Span Attn.: Our full design that enables hierarchical attention with adaptive attention span. By this means, the need of context for different pixels is dynamically decided regarding different matchability.
As presented in Table 5, both hierarchical global-local attention and adaptive attention span improve overall performance by a considerable margin, validating the essentiality of our network designs.

Understanding ASpanFormer
Flow estimation. We analyze the flow estimation through multiple iterations. As shown in Table 6, precision of flow regression is gradually improved as attention iterations are performed and converges after four iterations. As for uncertainty estimation, we split all pixels into two categories, matchable and unmatchable pixels, identified by ground-truth camera poses and depths, and report their mean standard deviation (σ). On one hand, mean σ decreases with iterations for matchable pixels, as the network becomes more certain about its flow prediction in later stages. On the other hand, the network gradually increases uncertainty values of unmatchable pixels to prevent over-confidence to a certain region.  Uncertainty map. In Figure 5, we provide visualization of uncertainty map of flow prediction. Overlapping and non-overlapping regions are firstly distinguished, while uncertainty values in textureless regions are usually larger, indicating context of larger size is required during cross attention.
Runtime evaluation. We evaluate the runtime of proposed method and compare it with LoFTR [13] where both methods apply Transformer backend. The runtime speed is tested on 100 randomly sampled ScanNet image pairs (640×480) with a NVIDIA V100 GPU. Runtime differs only on Attention Module compared with LoFTR, as we adopt the same Local Feature CNN backbone and coarseto-fine matching module. As shown in Table 7, the proposed method is overall slightly slower than LoFTR due to the more complicated attention operation.

Conclusion
In this paper, we have proposed a novel Transformer framework based on feature hierarchy, whose attention span is adaptively decided so as to acquire capabilities to capture both long-term dependencies as well as fine-grained details in local regions. State-of-the-art results validates the effectiveness of our method. With more engineering optimizations, we are looking forward to wider application of our method in real use.

Appendix A Implementation Details
In this section, we provide more details about our network implementation.

A.1 Network Settings
We use the same ResNet-18 for initial feature extractor as that in LoFTR, which outputs feature maps in two resolution, 1 8 and 1 2 . The 1 8 feature map is passed into our transformer-based network for updating, while the 1 2 is used in fine matches coordinates refinement. For dual-softmax in coarse matching, we adopt a learnable temperature which is initialized as 10.

A.2 Flow Regression
As stated in Sec. 3.4, we use an MLP to regress auxilary flow map in each GLA block. Given D-dimensional feature in pixel, we use MLP with shape (D,64,4) to regress a 4-dimensional feature f . For corresponding coordinates u x , u y , We normalize the first two values with sigmoid function and recover them to the range of image resolution. For the standard variance σ x , σ y , we regress the last two values as their logarithm. Formally, where H, W are image height and width.

A.3 Training Details
For both indoor and outdoor training, we adopt the same muti-step training strategy as that in officially released LoFTR code. More specifically, the learning rate is linearly warmed-up in this first epoch and then halved every two or three epochs. The learning rate curve is illustrated in Fig. 6.

A.4 Visual Localization Details
We refer to hierachical localization pipeline (https://github.com/cvg/Hierarchical-Localization) to perform viusal localization experiments on Aachen Day-Night and InLoc datasets. For Aachen Day-Night, we first triangulate reference models by using only coarse matches across images. We then generate fine level matches between query images and database images, where the database images are taken as left images, so that the fine level matches can be registered to triangulated 3D tracks.
For InLoc dataset, we directly generate fine level matches between query and database images, where the 2D match points on reference images are projected to 3D space through the provided depth map. We omit image pairs with fewer than 25 matches.

A.5 Some Effective Designs
We provide ablations for some additional useful designs in our network: (1) learnable temperature for softmax at each level. (2)Convolution-based FFN. (3) Normalized positional encoding when testing resolution differs from training resolution. An ablation study for these techniques is provided in Tab. 8 and Tab. 9.
Learnable Temperature. As stated in Sec. 3.4, message M f , M m , M c are computed from different levels of feature maps through global or local attention, where softmax are applied to tokens in different numbers. A concern about softmax is the that the number of tokens largely affect the final distribution. To balance the impact of different token number in global/local attention, we adopt three learnable temperature parameters τ f , τ m , τ c for softmax in fine, medium and coarse level features respectively.
Convolutional FFN. As shown in Sec. 3, our networks is fully based on cross attention for cross-view message passing, while self attention is absent. Deviating from common practice that employs self attention for intra-image message passing, we find in our experiment that adopting 3 × 3 convolution in FFN to replace self attention and MLP-based FFN leads to better overall performance.
Normalized Positional Encoding. Positional encoding (PE) in LoFTR is defined as, A concern about this PE is that unseen coordinate will be used in encoding when testing resolution differs from training resolution, which harms the network's capability of precise localization and boundary awareness. To mitigate the issue, we adopt a simple normalization technique, where W/H train/test are width/height of training/testing image. We find this normalization boost the performance of our method when training/testing image resolution differ. Aligning testing/training PE is especially critical for precise flow prediction, since it relies on PE to regress flow coordinate.
In Tab. 9, we provide ablation study results for normalized positional encoding (NPE). The results are obtained on MegaDepth dataset with all images resized to 1152 resolution, while the models are trained in 832 resolution.

B Flow Loss
We formulate flow supervision as most-likelihood estimation for Gaussian distribution P .
where D gt ij = (x ij , y ij ) is the ground truth flow and φ ij = (u ij x , u ij y , σ ij x , σ ij y ) are predicted parameters at location (i, j). Substituting into Gaussian distribution formula, we have In implementation, we let w ij x = logσ ij x , w ij y = logσ ij y and omit constant terms, then (16) Intuitively, this loss formulation is a weighted sum of L2-distance between estimated flows and ground truth flows. w ij x +w ij y is a regularization term encouraging lower uncertainty. The overall effect of flow loss is to minimize uncertainty and flow estimation error simultaneously.

C Additional Quantitative Results
We provide in this part additional experiment results on YFCC100M dataset and Image Matching Challenge 2022 (IMC 2022) kaggle benchmark.

C.1 Results on YFCC100M
YFCC100M contains a collection of internet images across various tourism landmarks. We adopt the test set from 4 selected landmark sequences as is done in previous works [32,30,31]. 1000 image pairs are sampled from each sequence, which yields 4000 pairs test set in total. We use OpenCV ransac for two-view pose estimation, where the RANSAC threshold for all methods is set to 5×10 −4 in normalized image coordinate space. Experiment results are given in Tab. 10, where our method outperforms all comparative methods.

C.2 Results on Image Matching Challenge 2022
We submit our method to Image Matching Challenge (IMC) 2022 and report the results in Tab. 11. We resize the input image to a fixed resolution [1472,832] and use OpenCV USAC MAGSAC to estimate fundamental matrix, where the RANSAC threshold is set to 0.2 pixel. The results show that our method consistently outperforms other strong comparative baselines.

D Additional Visualizations
We provide more visualization results in this part. In Fig 7, we provide qualitative comparisons between SuperGlue, LoFTR and our methods. In Fig 8, we provide flow predictions across GLA block iterations. In Fig 9, we provide additional visualization of uncertainty heatmap and corresponding adaptive attention spans.
Ours LoFTR SP + SuperGlue Ours LoFTR SP + SuperGlue Fig. 7. Visualizations of matches obtained through SuperGlue, LoFTR and ASpan-Former(ours). Our methods produces more accurate and denser matches compared with both SOTA sparse and dense matching networks.

Target Image Source Image
Iter #1 Iter #2 Iter #3 Iter #4 Fig. 8. Visualizations of flow prediction across GLA iterations. We filter flow predictions with high uncertainty. Note that the flow map are in 1 8 (60 × 80) resolution. As more GLA blocks are employed for feature updating, the flow map gradually prune occluded or non-overlap regions. Our network sharply focuses on regions with rich and distinctive textures with small attention span, while larger contexts are extracted for the low texture or uncertain regions. Specially, very large attention spans are generated for non-overlapping or occluded areas, preventing falsely focusing on certain regions.