{'fraction_non_alphanumeric': 0.030476144946935655, 'fraction_numerical': 0.01288364088344966, 'mean_word_length': 4.832566569078489, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Revisiting Stereo Depth Estimation From a Sequence-to-Sequence Perspective with Transformers

Stereo depth estimation relies on optimal correspondence matching between pixels on epipolar lines in the left and right images to infer depth. In this work, we revisit the problem from a sequence-to-sequence correspondence perspective to replace cost volume construction with dense pixel matching using position information and attention. This approach, named STereo TRansformer (STTR), has several advantages: It 1) relaxes the limitation of a fixed disparity range, 2) identifies occluded regions and provides confidence estimates, and 3) imposes uniqueness constraints during the matching process. We report promising results on both synthetic and real-world datasets and demonstrate that STTR generalizes across different domains, even without fine-tuning.


Introduction
Stereo depth estimation is of substantial interest since it enables the reconstruction of 3D information. To this end, corresponding pixels are matched between the left and right camera image; the difference in corresponding pixel location, i. e. the disparity, can then be used to infer depth and reconstruct the 3D scene. Recent deep learning-based approaches to stereo depth estimation have shown promising results but several challenges remain.
One such challenge relates to the use of a limited disparity range. Disparity values can, in theory, range from zero to the image width depending on the resolution/baseline of the cameras, and their proximity to the physical objects. However, many of the best performing approaches are constrained to a manually pre-specified disparity range (typically a maximum of 192 px) [23]. These methods rely on "cost volumes" in which matching costs are computed for multiple candidate matches and a final predicted disparity value is computed as the aggregated sum. This self-imposed disparity range is necessary to enable memory-feasible implementations of these methods but is not flexible to properties of the physical scene and/or the camera setup. In applications such as autonomous driving and endoscopic intervention, it is important to recognize close objects irrespective of camera setup (with disparity values potentially larger than 192) to avoid collisions, suggesting the need to relax the fixed disparity range assumption.
Geometric properties and constraints such as occlusion and matching uniqueness, which led to the success of nonlearning based approaches such as [19], are also often missing from learning-based approaches. For stereo depth estimation, occluded regions do not have a valid disparity. Prior algorithms generally infer disparities for occluded regions via a piece-wise smoothness assumption, which may not always be valid. Providing a confidence estimate together with the disparity value would be advantageous for down-stream analysis, such as for registration or scene understanding algorithms, to enable weighting or rejection of occluded and low-confidence estimates. However, most prior approaches do not provide such information. Moreover, pixels in one image should not be matched to multiple pixels in the other image (up to image resolution) since they correspond to the same location in the physical scene [31]. Although this constraint can be clearly useful to resolve ambiguity, most existing learning-based approaches do not impose it.
The aforementioned problems largely arise from shortcomings of the contemporary view of stereo matching which attempts to construct a cost volume. Approaches that consider disparity estimation from a sequence-to-sequence matching perspective along epipolar lines can avoid these challenges. Such methods are not new, to our knowledge, the first attempt using dynamic programming was proposed in 1985 [31], where intra-and inter-epipolar line information is used together with a uniqueness constraint. How- ever, it only used similarities between pixel intensities as matching criteria, which is inadequate beyond local matching, and thus restricted its performance. Recent advances in attention-based networks that capture long-range associations between feature descriptors prompt us to revisit this perspective. We take advantage of the recent Transformer architecture [39] proposed for language processing and recent advances in feature matching [34], and present a new end-to-end-trained stereo depth estimation network named STereo TRansformer (STTR). The main advantage of STTR is that it computes pixel-wise correlation densely and does not construct a fixed-disparity cost volume. Therefore, STTR can mitigate the drawbacks of most contemporary approaches that were detailed above with little to no compromises in performance. We report competitive performance on synthetic and real image benchmarks and demonstrate that STTR trained only on synthetic images also generalizes well to other domains without refinement. We make the following technical advances to enable the realization of STTR: -Instead of pixel-wise intensity correlation in traditional stereo depth estimation methods like [31], we adopt a Transformer with alternating self-and cross-attentions combined with the optimal transport theory previously demonstrated in sparse feature matching [34]. This design allows us to match pixels explicitly and densely while imposing a uniqueness constraint.
-We provide a relative pixel distance encoding to the feature descriptor and use a customized attention mechanism to define discriminative features during the matching process. This helps resolve ambiguity during the matching process.
-We devise a memory-feasible implementation of STTR which enables the training of the proposed model on conventional hardware. For seamless distribution and reproducibility, our code is available online 1 and only uses existing PyTorch functions [32].

Stereo Depth Estimation
In general, the stereo depth estimation task involves two key steps (1) feature matching and (2) matching cost aggregation [23]. Traditionally, the task is solved by dynamic programming techniques where matchings are computed using pixel intensities and costs are aggregated either horizontally in 1D [31] or multi-directionally in 2D [19].
More recently, learning-based methods that match features by dot-product correlation have emerged. Early ones such as [6] compute feature similarities based on a patch of features and refine the matching using a Markov Random Field. Subsequent approaches [27,24] take advantage of learning-based feature extractors and compute similarities between the feature descriptors for each pixel. [42] further advances the performance with cross-scale information aggregation.
Concurrently, networks such as [22,5] build a 4D feature volume by concatenating features at different disparities and learn to compute/aggregate the matching cost by 3D convolutions. In [47], additional semi-global and local cost aggregation layers are proposed to improve the performance. Following the same idea of computing matching cost by learnt 3D convolutions, other works [43,7,44,16] attempt to enable high resolution inference, mitigate the memory constraint, and/or leverage richer context information via a multi-resolution approach.
Hybrid approaches like [17] have also emerged, which combine explicit correlation and 3D convolutions for matching and cost aggregation respectively. Other works follow different design concepts, such as [2] with a classification-based approach for disparity estimation.
However, none of the above prior work exploits the sequential nature and geometric properties of stereo matching, which led to the success of non-learning based works such as [31,19]. Moreover, whether matching is computed by correlation or learnt by 3D convolutions, a maximum disparity is set to mitigate memory and computation demands in the above works. For each pixel, there is a fixed and finite set of discretized locations where a pixel can be mapped, thus generating a matching cost volume. For disparities beyond this pre-defined range, these approaches simply cannot infer the correct match. This limits the generalization of the networks across different scenes and stereo camera configurations. In addition, most learning-based approaches do not handle occlusion explicitly, even if the disparity in occluded regions can theoretically be arbitrary. Lastly, no explicit uniqueness constraint is imposed during the matching process, which can inhibit performance due to inconsistencies of matching.

Comparison of STTR to Previous Learningbased Stereo Paradigms
We use a convolutional neural network as the feature extractor that feeds into a Transformer to capture long-range associations between pixels. STTR exploits the sequential nature and geometric properties of stereo matching.
STTR vs. Correlation-based Networks: STTR imposes a uniqueness constraint during the matching process to resolve ambiguities. STTR also alternates between intra-and inter-image correlation operations, named selfand cross-attention, and updates the feature representations by considering both image context and position information.
STTR vs. 3D Convolution-based Networks: STTR explicitly and densely computes the correlation between pixels in the left and right images. Instead of using 3D convolutions to aggregate a cost volume, we first match along epipolar lines and then aggregate the information across epipolar lines via 2D convolutions.

Attention Mechanism and Transformer
Attention has already proven to be an effective tool in natural language processing [39]. Recently, attention-based architectures has found applications in computer vision tasks, such as image classification [11], object detection [4], panoptic segmentation [40], and homography estimation and visual localization [34], improving on the results of pure CNN architectures. This is likely because attention can capture long-range associations which is of particular importance for the work presented here. We adopt a Transformer to revisit the sequence-to-sequence stereo matching paradigm originally proposed in [31].

The Stereo Transformer Architecture
In the following sections, we denote the height and width of the rectified left and right pair of images as I h and I w . We denote the channel dimension of feature descriptors as C.

Feature Extractor
We use an hourglass-shaped architecture similar to [25], with the exception that the encoding path is modified with residual connections and spatial pyramid pooling modules [5] for more efficient global context acquisition. The decoding path consists of transposed convolution, dense-blocks [20], and a final convolution layer. The feature descriptors for each pixel, denoted as vector e I of size C e , encode both local and global context. The final feature map is at the same spatial resolution as the input image.

Transformer
An overview of the Transformer architecture used here is provided in Fig. 2. We adopt the alternating attention mechanism in [34]: Self-attention computes attention between pixels along the epipolar line in the same image, while cross-attention computes attention of pixels along corresponding epipolar lines in the left and right images. Details on both attention modules follows in Section 3.2.1. As shown in Fig. 2, we alternate between computing self-and cross-attention for N − 1 layers. This alternating scheme keeps updating the feature descriptors based on the image context and relative position, as discussed in Section 3.2.2.
In the last cross-attention layer, we use the most attended pixel to estimate the raw disparity. We add operations exclusive to this layer, including optimal transport for compliance with the uniqueness constraint (Section 3.2.3) and an attention mask for search space reduction (Section 3.2.4).

Attention
Attention modules [39] compute the attention between a set of query vectors and key vectors using dot-product similarity, which is then used to weigh a set of value vectors.
We adopt multi-head attention, which increases the expressivity of the feature descriptor by splitting the channel dimension of feature descriptors C e into N h groups C h = C e /N h , where C h is the channel dimension of each head and N h is the number of heads. Therefore, each head can have different representations, and similarities can be computed per head. For each attention head h, a set of linear projections are used to compute the query vectors Q h , key vectors K h and value vectors V h using feature descriptors e I as input: We normalize the similarities via softmax and obtain α h as The output value vector V O can be computed as: where W O ∈ R Ce×Ce and b O ∈ R Ce . The output value vector V O is then added to the original feature descriptors to form a residual connection: For self-attention, the Q h , K h , V h are computed from the same image. For cross-attention, Q h is computed from the source image while K h , V h are computed from the target image. Cross-attention is applied bi-directionally so in one case source→target is left→right and the other case is right→left.

Relative Positional Encoding
In large textureless areas, similarities between pixels can be ambiguous. This ambiguity, however, may be resolved by considering relative positional information with respect to prominent features, such as edges. Thus, we provide data-dependent spatial information via positional encoding e p . We choose to encode relative pixel distances instead of absolute pixel locations due to its shift-invariance. In the vanilla Transformer [39], the absolute positional encoding e p is directly added to the feature descriptor In that case, attention between the i-th and j-th pixel in Equation 2 can be expanded [10] (ignoring biases for simplicity) as (1) data-data As shown, the term (4) entirely depends on position and should thus be left out, as disparity fundamentally depends on image content. Instead, we use relative positional encoding and remove the term (4) as where e p,i−j denotes the positional encoding between the i-th and j-th pixel. Note that e p,i−j = e p,j−i . Intuitively, the attention depends on both content similarity and relative distance. Concurrent to our development, [18] found that a similar attention mechanism is beneficial for NLP tasks. However, the computational cost of relative distance is quadratic in the image width I w since for each pixel, there are I w relative distances, and this computation needs to be done I w times. We describe an efficient implementation which reduces the cost to linear. The details of the implementation follow in Appendix A.

Optimal Transport
Enforcing the uniqueness constraint of stereo matching was attempted in [31], where each pixel in the right image gets assigned to at most one pixel in the left image. However, this hard assignment prohibits gradient flow. By contrast, entropy-regularized optimal transport [9] is an ideal alternative due to its soft assignment and differentiability, and was previously demonstrated as beneficial for the related task of sparse feature [34] and semantic correspondence [26] matching. Given a cost matrix M of two marginal distributions a and b of length I w , the entropy-regularized optimal transport attempts to find the optimal coupling matrix T by solving where E(T ) is the entropy regularization. If the two marginal distributions a, b are uniform, T is also optimal for the assignment problem, which imposes a soft uniqueness constraint [33] and mitigates ambiguity [26]. The solution to Equation 8 can be found via the iterative Sinkhorn algorithm [9]. Intuitively, values in T represent the pairwise matching probabilities, similar to softmaxed attention in Equation 2. Due to occlusion, some pixels cannot be matched. Following [34], we augment the cost matrix by adding dustbins with a learnable parameter φ that, intuitively, represents the cost of setting a pixel unmatched.
In STTR, the cost matrix M is set to the negative of the attention computed by the cross-attention module in Equation 2, but without softmax, as optimal transport will normalize the attention values.

Attention Mask
Let x L , x R be the projected location of the same physical point onto the left and right epipolar lines respectively (+x from left to the right). The spatial arrangement of the cameras in a stereo rig ensures that x R ≤ x L for all points after rectification. Therefore, in the last cross-attention layer, it is sufficient for each pixel in the left image to only attend to pixels that are further to the left of the same coordinate in the right image (i.e., attend only to points x in the right image where x ≤ x L ). To impose such a constraint, we introduce a lower-triangular binary mask on the attention. Additional visualization can be found in Appendix B.

Raw Disparity and Occlusion Regression
In most prior work, a weighted-sum of all candidate disparity values is used. We instead regress disparity using a modified winner-take-all approach [38], which is robust against multi-modal distributions.
The raw disparity is computed by finding the location of the most probable match, denoted as k, from the optimal transport assignment matrix T and build a 3 px window N 3 (k) around it. A re-normalization step is applied to the matching probabilities within the 3 px window such that the sum is 1. The weighted sum of the candidate disparities is the regressed raw disparityd raw (k). Denoting the matching probability in assignment matrix T to be t, we havẽ The sum of probabilities within this 3 px window represents an estimate of the confidence of the network with the current assignment, in the form of an inverse occlusion probability. Therefore, we can regress the occlusion probability p occ (k) using the same information as

Context Adjustment Layer
The raw disparity and occlusion maps are regressed over epipolar lines and thus lack context across multiple epipolar lines. To mitigate this, we use convolutions to adjust the estimated values conditioned on the input image with cross epipolar line information. The overview of the context adjustment layer is in Fig. 3.
The raw disparity and occlusion maps are first concatenated with the left image along the channel dimension. Two convolution blocks are used to aggregate the occlusion information, followed by ReLU. The final occlusion is estimated by a Sigmoid activation. Disparities are refined by residual blocks which expand the channel dimension before ReLU activation then restores it to the original channel dimension. The expansion before the ReLU is to encourage better information flow [46]. Raw disparity is repeatedly concatenated with the residual block for better conditioning. The final output of the residual blocks is added to the raw disparity via a long skip connection.

Loss
We adopt the Relative Response loss L rr proposed in [25] on the assignment matrix T for both sets of matched pixels M and sets of unmatched pixels U due to occlusion. The goal of the network is to maximize the attention on the true target location. Since disparity is subpixel, we use linear interpolation between the nearest integer pixels to find the matching probability t * . Specifically, for the i-th pixel in the left image with ground truth disparity d gt,i , where interp denotes linear interpolation and t i,φ is the unmatched probability. We use smooth L1 loss [14] on both raw and final disparities, denoted as L d1,r and L d1,f . The final occlusion map is supervised via a binary-entropy loss L be,f . The total loss is the summation: where w are the loss weights.

Memory-Feasible Implementation
The memory consumption of the attention mechanism is quadratic in terms of the sequence length. Specifically, for a float32 precision computation, For example, given I w = 960, I h = 540 and N h = 8, training a N = 6 layer Transformer consume approximately 216 GB, which is impractical on conventional hardware. Following [8], we adopt gradient checkpointing [15] for each self-and cross-attention layer, where the intermediate variables are not saved during the forward pass. During the backward pass, we run the forward pass again for the checkpointed layer to recompute the gradient. Thus, the memory consumption is bounded by the requirement of a single attention layer, which in theory enables the network to scale infinitely in terms of the number of attention layers N . Moreover, we use mixed-precision training [30] for faster training speed and reduced memory consumption.
Lastly, we use an attention stride s > 1 to sparsely sample the feature descriptors, which is equivalent to a downsampling of the feature map.
Complexity Analysis: In existing cost-volume paradigms, correlation-based networks have a memory complexity of O(I h I w D), while 3D convolution-based networks have O(I h I w DC), where D is the maximum disparity value and C is the channel size. D is generally set to a fixed value less than I w , sacrificing the ability to predict disparity values outside the range. STTR is of O(I h I 2 w /s 3 ), which offers an alternative trade-off where no maximum disparity is set. Given s, STTR runs at a constant memory consumption across different disparity ranges compared to prior work. During inference, s can be adjusted to a larger value which reduces memory consumption and maintains the maximal disparity range at the slight sacrifice of task performance. Quantitative analysis of the trade-off between performance and memory of s is in Appendix G.
We also introduce a lightweight implementation of STTR without the flexibility to adjust s in Appendix H for faster speed and lower memory consumption. Comparison of inference speed/memory between STTR and prior work is in Appendix I.

Experiments, Results, and Discussion
Datasets: Scene Flow [27] FlyingThings3D subset is a synthetic dataset of random objects. MPI Sintel [3] is a synthetic dataset from animated film that contains various realistic artifacts such as specular reflections and motion blur. Hyperparameters: In our experiments, we use 6 selfand cross-attention layers with C e = 128. We run the Sinkhorn algorithm for 10 iterations. We use attention stride of s = 3 during training. We use AdamW as the optimizer with weight decay of 1e-4. We set all loss weights w to 1. We pre-train on Scene Flow for 15 epochs using a fixed learning rate of 1e-4 for feature extractor and Transformer, and 2e-4 for the context adjustment layer. To simulate realistic stereo artifacts, we use asymmetric (i. e. different for left and right images) augmentation, including RGB shift, Gaussian noise, brightness/contrast shift, vertical shift and rotation. For KITTI 2015 benchmark submission, we finetune the pre-trained model using the exponential learning rate scheduler with a decay of 0.99 for 400 epochs. We conduct our experiments on one Nvidia Titan RTX GPU. We use both 3 px Error (percentage of errors larger than 3 px) and EPE (absolute error) as evaluation metrics. Please note that all quantitative metrics reported in the remainder of this section refer to non-occluded regions only; we use IOU to evaluate occlusion estimation.

Ablation Studies
We conduct ablation studies using the Scene Flow synthetic dataset, and provide quantitative results for the effects of the attention mask, optimal transport layer, context adjustment layer and positional encoding summarized in Table 1. Following prior work, we validate on the test split directly since Scene Flow is only used for pre-training.
Uniqueness Constraint: The soft uniqueness constraint is imposed via the optimal transport layer by taking the interaction between pixels along the same epipolar line into account. We find it improves the result in all metrics, especially for occlusion IOU (row 3 in Table 1). Relative Positional Encoding: To visualize the effect of positional encoding, we use PCA to reduce the feature map to R 3 . Given an image with a large textureless area, such as the table shown in Fig. 4(a), the features directly extracted from the feature extractor shown in Fig. 4(b) exhibit similar patterns. In the case of no positional encoding, as the layers progress deeper, the feature map merely changes throughout the process as shown in Fig. 4(c-d). By providing relative positional encoding to all layers, strides that are parallel to the edges emerge in layer 4 as shown in Fig. 4(e) and eventually the strides propagate to the entire region in layer 6 as shown in Fig. 4(f). This suggests that the Transformer needs relative positional information to resolve ambiguity in textureless areas. With positional encoding added to all layers, the result improves for all three metrics (row 5 in Table 1).  Generalization of Attention: In principle, STTR allows the disparity range to scale with the image width since pixels are densely compared. Nonetheless, we evaluate if STTR indeed generalizes beyond the disparity range that it is trained on. We train another model by only computing losses on pixels with disparities smaller than 192 px (0.2I w ) and ignoring pixels outside this range. During testing, the maximal disparity prediction made within 1 px error margin is 458 px (0.48I w ), which demonstrates the generalization.
Attention Span: We analyze the attention span (i. e., the distribution of attention values over all pixels) of each layer of self-and cross-attention [36,37]. Our results (detailed in Appendix D) show that both self-and cross-attention start from relatively global context (300 px, 0.31I w ) and shift to the local context (114 px, 0.12I w for self-attention and 15 px, 0.01I w for cross-attention). Since the attention span decreases in deeper layers, we conclude that the global context is predominantly used in early layers but does not contribute substantially to disparity refinement in the late layers. This suggests an opportunity for future work to gradually reduce the search window based on previous layers' attention span to improve efficiency.

Scene Flow Benchmark Result
The pre-training results on Scene Flow are shown in Table 3. STTR performs on par with prior work when evaluated only on pixels with disparity less than 192 (2nd -3rd columns). However, STTR outperforms prior work by a large margin in unconstrained settings due to its unbounded disparity estimation (4th -5th columns) while the maximal disparity is fixed at D = 192 for the other methods. To compare fairly, we evaluate again with D = 480 (which covers all disparity values in the test dataset) for prior work. STTR's performance remains the same as D = 192 setting and comparable to prior work. Moreover, as shown qualitatively in Fig. 1 and quantitatively in Table 1, STTR can accurately identify occluded areas, which was not attempted in prior work.

Cross-Domain Generalization
We examine the domain generalization of STTR by comparing it to prior work also trained only on the Scene Flow synthetic dataset in Table 2. Note that we do not refine the models to the test dataset. For a fair comparison, we set maximum disparity D = 192 for prior work and only evaluate pixels in this range. We also trained prior work with the same asymmetric augmentation technique used for STTR to avoid inconsistency [41], while keeping the original training scheme (optimizer, learning rate, loss and num- ber of epochs). Although asymmetric augmentation improves generalization in some cases (confirming findings of [41]), it is not consistent. Regardless, STTR generalizes comparably and maintains a high occlusion IOU across four datasets. STTR performs well in terms of 3 px Error, but not always for EPE. This is because if a pixel is wrongly identified as occlusion, a zero disparity is predicted, resulting in a large EPE. We visualize the generalization mechanism of STTR in Appendix E.

KITTI Benchmark Result
Since the KITTI benchmark provides a reasonable number of images for fine-tuning and it is commonly used in prior work, we choose the KITTI benchmark for comparisons after fine-tuning. The result on KITTI 2015 benchmark is shown in Table 4 2 . STTR performs comparably to several competing approaches, even compared with multiresolution networks designed for better context aggregation.

Shortcomings in Challenge Design
While STTR performs comparatively to prior work, it is worth mentioning that the test sets in these real-world datasets are rather small. Specifically, the test sets accompanying KITTI 2015, Middlebury 2014, and SCARED contain 200, 15, and 19 images, respectively. To achieve a more comprehensive estimate of performance, much larger test datasets are required. This paucity of data is further compounded by the observation that performance differences between competing models on these datasets are on the or-2 Full result of KITTI benchmark.
der of < 1 % after refinement and a few percent for crossdomain generalization. Consequently, we cannot conclude if there is a significant performance difference between the approaches presented. Additionally, KITTI only reports on disparities less than 192 and does not have metrics related to some of the benefits central to STTR (i. e., unlimited disparity and occlusion detection). As such, results on this benchmark likely cannot give a complete picture of performance comparisons.
Despite the above limitation, certain advancements have brought substantial performance improvements for costvolume approaches. The shift from low-res (e. g. PSMNet [5]) to multi-res using feature pyramids for better context aggregation (such as LEAStereo [7]) appears to be a fruitful path, where LEAStereo [7] is further optimized within this structure using neural architecture search. Our future work aims to incorporate these developments into our design.

Conclusion
In conclusion, we have presented an end-to-end network architecture named STereo TRansformer that synergizes advantages of CNN and Transformer architectures. We revisit stereo depth estimation from a sequence-to-sequence matching perspective. This approach 1) avoids the need to pre-specify a fixed disparity range, 2) explicitly handles occlusion, and 3) imposes a match uniqueness constraint. We experimentally demonstrate that STTR generalizes to different domains without fine-tuning and report promising results on benchmarks with refinement. Future work will include increasing the context information via multiresolution techniques.
The attention with relative positional encoding is computed as In the following context, we use term (2) data-position (D2P) as an example. For simplicity, we denote e T I,i W T Q as Q i and W K e p,i−j as K r,i−j . In term (2) for any i, j, the relative distance follows a fixed pattern [10] shown as Q1Kr,0 ··· Q1K r,−Iw +2 . . .
where the first row starts with a relative distance of 0 and ends with a relative distance of −I w + 1. Subsequent rows simply offset the first row by increasing amounts. Furthermore, since the relative distance is bounded by I w − 1 and −I w + 1, therefore we can pre-compute all possible values of K r,i−j asK We then sliceK r with an increasing offset, which can be done computation-lightly to obtain Kr,0 ··· K r,−Iw +2 . . . The term (2) D2P can then be computed as a matrix product between Q and K r . The term (3) position-data can be computed similarly, thus, reducing the computation cost of relative position.

B. Attention Mask
As described in Sect. 3.2.4, if x L , x R represent the xcoordinates in pixel-space for the projection of a physical point into the left and right images, then x R ≤ x L for all physical points (with positive x-axis pointing to the right). Therefore when searching for correspondences, the network only needs to search for pixels in the right image that are to the left of the current pixel position in the left image. An example is given in Fig. 5(a): If the corner of the table (highlighted with the circle) is to be matched, the network only needs to search to the left of the dashed line in the right image. This can be achieved using a binary attention mask shown in Fig. 5(b), where for each pixel in the left image, the allowable attended pixel locations in the right image marked as white are to the left of source pixel location. Mathematically, this binary attention mask can be achieved by setting the values of forbidden attended pixels (marked as black in Fig. 5(b)) in the attention matrix to negative infinity. Thus, after softmax, the attention values α h in Equation 2 of those pixels will be zero and they'll be excluded from the disparity computation.

C. Relative Positional Encoding
In Fig. 6, we visualize the evolution of feature descriptors as the Transformer updates them without the positional encoding. It is worth noting the textureless region, such as the table, does not have distinct patterns to resolve matching ambiguities.
In contrast, the evolution of feature descriptors with positional encoding in Fig. 7 propagates the edge information into the center of the textureless region progressively, which helps to resolve the ambiguity.

D. Attention Span
We compute attention span of both the self-and crossattention layers, which is the spatial span of pixels that are above the uniform attention value (i. e., 1/I w with I w being image width). The layer-wise attention span in Fig. 8 illustrates how self-and cross-attention shift from a global context to local one as processing moves to higher layers in the network. This is particularly true for cross-attention, where the final attention span is only around 15 pixels (0.01 of image width).
The evolution of self-attention and cross-attention are also visualized in Fig. 9 and Fig. 10, where brighter regions are the more attended regions. It can be observed that the attention span from the source pixel (labeled as a red crosshair) slowly converges to local context as the Transformer progresses, confirming the quantitative result in Fig. 8. Both attention mechanisms stay focused on edges even if they are far away from the source pixel (i.e., not within the local context). In cross-attention, it can be observed that the final attention shrinks towards the target pixel (labeled as a blue cross-hair).

E. Generalization Mechanism
We visualize the input feature maps to the Transformer using UMAP [28] in Fig. 11, where the dimensionality re- duced embedding is trained only on Scene Flow data. Each data point represents a pixel that the Transformer operates on. We observe that the representations learned by STTR cluster into two regions ( Fig. 11(a)). To further understand this clustering phenomenon, we visualize the corresponding pixels using a color mask belonging to one of the clusters. The intensity of a pixel in the color mask is higher if it is closer to the centroids of the cluster. Interestingly, the feature extractor groups pixels into textured (blue) and textureless (red) regions. Pixels with a higher intensity in the color mask are mostly correlated to texture edges. To verify that the blue region indeed contains more texture than the red region, we compute the mean Sobel edge-gradient   on the normalized image intensities of each dataset. The result is summarized in Table 5 where, with the exception of SCARED, all datasets have larger magnitude edgegradients in the blue cluster than red cluster, confirming that blue cluster contains more "texture" than red cluster. In Fig. 11(b), we show that regardless of the domain, the embeddings are always contained within the same space. We additionally show the individual UMAP reduction of features extracted from MPI Sintel, KITTI 2015, Middlebury 2014, and SCARED dataset on top of Scene Flow in Fig. 12(a-d). We hypothesize that this implicitly learnt feature clustering improves the generalization of STTR and makes the Transformer matching process easier.

F. Qualitative result of context adjustment layer (CAL)
We provide visualizations of context adjustment layer's effect in Fig. 13. Comparing the CAL output in Fig. 13(a), the prediction without CAL in Fig. 13(b) the result lacks smoothness due to lack of cross eipolar-line context.

G. Attention Stride
Since the attention module is flexible with respect to the stride of features over which to attend, STTR can run at a faster speed and lower memory footprint at the cost of performance. We do not have to re-train STTR as attention  stride is only an inference hyperparameter. The result is summarized in Table 6.

H. Lightweight Implementation
An additional lightweight model is implemented for STTR for faster inference speed and lighter memory con-sumption while maintaining the similar performance as STTR. The major changes include: -We remove the flexibility in STTR where attention stride s can change during inference but instead fix it to s = 4. Thus, the features extracted do not need to be maintained at the full image resolution any more. This reduces memory consumption.
-As discussed in Equation 13, the memory consumption is proportional to the number of heads N h . On the other hand, the number of parameters is proportional to N h C h . Therefore, we can maintain the same number of parameters while halving memory consumption by increasing C h by two and decreasing N h by two.
We use the same training protocol for the lightweight model as discussed in Sect. 4. We compare the performance of the lightweight STTR and STTR on the Scene Flow benchmark in Table 7 and cross-domain generalization performance on different datasets in Table 8. As shown in Table 7, the performance of lightweight STTR drops compared to STTR in Scene Flow evaluation, especially in terms of 3 px Error and EPE, while inference performance improves with less memory and faster speed. The generalization performance improves in EPE for MPI Sintel, 3 px Error and EPE for Middlebury 2014 and SCARED, while worsens in 3 px Error for MPI Sintel and 3 px error and EPE for KITTI 2015. The occlusion IOU consistently worsens compared to STTR.

I. Inference Memory Consumption and Speed
As discussed in Sect. 3.5, STTR can run at a constant memory and speed without a manually limited disparity range. We compare the inference speed and memory consumption with the prior work where a larger disparity range will consume more memory and slow down inference speed. Since PSMNet [5] uses a feature downsampling rates of 4 and AANet [42] uses a feature pyramid, we set attention stride s = 4 for STTR to match the setting in PSMNet. As shown in Table 9, in order for prior work to predict a larger disparity range, the memory consumption increases while inference speed drops. In comparison, STTR runs with a constant memory consumption and speed.

J. Dataset Information and Pre-processing
Scene Flow [27] FlyingThings3D Full dataset (final pass) provides realistic artifacts but does not provide occlusion information. Therefore, we subsample the Full dataset using the corresponding occlusion information from Disp-Net/FlowNet2.0 dataset. After pre-processing, Scene Flow contains 21818 training images of resolution 960×540, with maximum disparity 602 px (0.67 of image width). The test dataset contains 4248 images with maximum disparity 468 (0.49 of image width). MPI Sintel [3] contains 1063 images of resolution 1024 × 436, with maximum disparity 487 px (0.46 of image width). KITTI 2015 [29] contains 200 images of resolution 1242×375, with maximum disparity of 192 px (0.15 of image width). We note that pixels with disparities larger than 192 are intentionally masked out in the dataset. Middlebury 2014 [35] quarter resolution subset contains 15 images of various image resolution, with maximum disparity of 161 px (0.22 of image width). SCARED [1] requires additional pre-processing since it only provides the depth data and corresponding camera intrinsics parameters. There are 7 subsets in total, containing 27 videos. Since subsets {4,5} contain very large camera intrinsic errors [1], we choose to leave them out of our evaluation since this introduces unnecessary uncertainty. Furthermore, other than the first frames of each video, subsequent frames are interpolated using the kinematics information of the robot with synchronization and kinematics error. Therefore, the depth values for subsequent frames are not accurate. We also exclude those images for reliable evaluation. The left and right 100 pixels were cropped due to invalidity after rectification. After pre-processing, SCARED contains 19 images of resolution 1080 × 1024 with maximum disparity of 263 px (0.24 of image width).

K. Loose Analogy to Biological Stereo Vision
It has been shown that the biological stereo vision system (e. g. that of a human) perceives depth from stereo images by relying on low-level cortex cues. One example that demonstrates this effect is the random-dot stereograms experiment [21], where there is no meaningful texture in the images but only random dots; yet, humans can still perceive the 3D objects. At the same time, the biological vision system imposes geometric assumptions on objects as a piece-wise smoothness prior [13], which involves mid-level cortex processing. In a way, STTR emulates the biological stereo system in that the Transformer processes the images at a low-level to finds matches between features. STTR then locally refines the raw disparity using the context adjustment layer, which is in loose analogy to mid-level vision.

L. Training Time and Number of parameters
The total training time on Scene Flow dataset [27] for STTR is approximately 120 hours on one Titan RTX GPU with batch size 1 for 15 epochs. We note that the training time will vary with the batch size and number/type of GPUs used. The number of parameters of STTR compared with contemporary architectures is summarized in Table 10. Other than LEAStereo [7] which is optimized using Neural Architecture Search, STTR has the least number of parameters.