Boundary-Gated Global Attention for Optical Flow

Optical flow networks estimate, for every pixel, where it moved between two video frames. To fill in pixels whose motion is ambiguous, such as occluded pixels or textureless patches, modern networks copy motion from distant pixels that look similar. The copying mechanism is attention: a learned similarity score between every pair of pixels. Attention measures only whether two pixels look alike. It ignores whether they belong to the same moving surface. When a running character's arm and the wall behind it share a color, attention mixes their motions, and the sharp edge of the moving object dissolves into a smear. We propose to make this similarity score depend on the path between the two pixels as well as their appearance. Before a pixel can borrow motion from a distant one, the network sums a learned "motion boundary" cost along a short path between them. The cost is predicted from the network's own current flow estimate. Motion then travels far within a surface but cannot cross a silhouette.

The idea is a learned, end-to-end descendant of a classical trick. EpicFlow interpolated sparse matches using distances measured along paths over an edge map, so motion could not leak across edges (EpicFlow). We keep the path idea and change three things. The barriers come from estimated motion discontinuities instead of color edges. They are recomputed at every refinement step of the flow network. And the path costs are computed cheaply along rows and columns, borrowing the two-pass row-and-column attention pattern of CCNet (CCNet).

Core Claim

The file describes a direct contradiction between two papers. GMA propagates motion into occluded pixels by attending over the whole frame by appearance similarity, and it reports 13.6% and 13.7% error reductions over RAFT on Sintel Final and Clean (GMA). It assumes, however, that similar-looking regions move alike. GAFlow shows that unconstrained global attention produces flat, noisy similarity maps that blur boundaries. Its fix is a learnable Gaussian distance prior, which pulls attention back toward local windows (GAFlow). That prior sacrifices reach in order to protect boundaries.

Our claim is that the trade-off comes from measuring the wrong distance. Euclidean distance in the image, which GAFlow penalizes, does not predict whether two pixels share a motion. The number of motion boundaries crossed on the way from one to the other does. An attention score with the form

$$a_{ij} \propto \exp\!\left(q_i^\top k_j/\sqrt{d} \;-\; \lambda \, C(i \to j)\right),$$

where $q_i, k_j$ are the usual query and key vectors of dimension $d$, $C(i \to j)$ is the summed predicted boundary strength along a row-then-column path from pixel $i$ to pixel $j$, and $\lambda$ is a learned scale, should keep GMA's long-range filling inside a surface. It should also give GAFlow-level or better sharpness at silhouettes.

There is a structural reason that ordinary attention cannot learn this on its own. "Is there an edge between $i$ and $j$" is a property of the path between the two pixels, not of either pixel. An inner product of per-pixel features cannot represent it in general.

Research Program

We build the module on top of GMA, the cleanest testbed. GMA's global aggregation is the component whose homogeneous-motion assumption we target, and it runs at 1/8 resolution, where cost matters least.

At each recurrent update, a small head predicts a per-pixel boundary probability $b \in [0,1]$. Its inputs are cues the motion-boundary literature found informative: the current flow and its spatial gradients, the photometric error after warping frame two to frame one, and context features. Learning to detect Motion Boundaries used similar cues to reach 68.5% mean average precision against 58.0% for flow-gradient baselines on Sintel Final (Learning to detect Motion Boundaries), which is evidence these cues carry boundary signal beyond the flow itself.

Along each row and each column we take prefix sums of $b$. The boundary cost between any two pixels on the same row is then the difference of two prefix sums, computed in constant time per pair. Following CCNet's recurrent criss-cross scheme, attention runs in two passes. Pass one covers each pixel's row and column with the gated logits. Pass two composes the results, so every pixel reaches every other pixel through one corner. Total cost scales as $O(N\sqrt{N})$ for $N$ pixels, not $O(N^2)$. This is where Direction 1 enters: the factorized long-range pattern is what makes path costs cheap.

A known weakness of factorized attention is that it can miss diagonal structure. We treat this as a question to measure, and we compare against a dense-attention version at 1/8 resolution. The barrier head receives weak supervision from Sintel's ground-truth flow, with boundary targets taken from discontinuities in that flow. The main flow loss also shapes it end to end.

As a secondary analysis, we ask whether the soft, learned barrier relaxes on motion-blurred regions. The TCU authors found that edge sharpening hurts Sintel Final, where true boundaries are not step functions (TCU). A barrier predicted from warping error might stay low where blur makes the transition genuinely gradual. We will check this by measuring barrier strength in Clean versus Final renders of the same frames.

Baselines

The do-nothing reference is GMA itself. We retrain it under our exact schedule (FlyingChairs, then FlyingThings3D, then Sintel and KITTI fine-tuning), with the same iteration count and batch size. The file gives only relative gains for GMA. Its absolute Sintel Clean figure in the TCU paper is 1.31, falling to 1.18 with TCU's upsampler (TCU).

The strongest competitor on the specific question of global reach versus sharp boundaries is GAFlow. It reports 1.15 Clean and 2.05 Final end-point error on Sintel and 4.42% F1-all on KITTI (GAFlow). It is the only method in the file that directly constrains attention to protect boundaries. We will cite its published numbers and also retrain it under our schedule. Beating it means lower boundary-region error at equal or lower parameter count, without losing its full-image error.

FlowFormer, at 1.144 Clean and 2.183 Final (FlowFormer), serves as a heavier global-attention reference.

Three ablations isolate the key ingredient. The first gates with static image edges in place of learned motion boundaries, which is EpicFlow-style gating made differentiable. The second keeps the learned boundary map but simply concatenates it to queries and keys, with no path cost. The third replaces path cost with GAFlow's Euclidean Gaussian penalty. All variants share parameter budgets within 5% and receive the same small hyperparameter sweep, with three seeds each.

Why not just…?

Why not just feed the boundary map into GMA's attention as an extra feature? This is the most serious threat. A network could learn region-identity-like features that make same-surface pixels similar. Path dependence cannot be written as a pairwise inner product in general, but in practice the gap may be small. The concatenation ablation settles it directly: if it matches the path-gated model on boundary-region error, our core claim fails.

Why not just use GAFlow's local Gaussian prior? GAFlow avoids smearing by shortening attention range. That should cost accuracy on occluded pixels far from any visible surface of the same object, which is exactly the case GMA was built for. We test this by comparing errors on unmatched pixels, binned by distance to the nearest visible pixel with similar motion. We predict GAFlow degrades with distance and our model does not.

Why not just replace the upsampler with TCU? TCU fixes blur created when 1/8-resolution flow is enlarged to full resolution. Our module fixes blur created earlier, when motion is aggregated at 1/8 resolution. If TCU alone recovers most of the boundary gains, the aggregation stage was not the bottleneck. To find out, we run GMA, GMA+TCU, GMA+ours, and GMA+ours+TCU, and look for gains that add up.

Why not just post-process with an edge-aware filter? The file's evidence is that filtering an already blurred field keeps the blur: flow-gradient boundaries reach only 58.0% mAP (Learning to detect Motion Boundaries), and classical variational refinement takes seconds to tens of seconds per frame (FlowFields++). We will still include a bilateral-filtered GMA output as a cheap reference.

Proposed Experiments

The main evaluation uses Sintel Clean and Final. Beyond overall end-point error, we report error near motion boundaries using Sintel's distance-to-boundary bands (0–10 pixels), where the effect should concentrate, and error on unmatched pixels. No reported result was found on Lacuna for any baseline on the 0–10 band, so we compute it for all retrained models.

On Middlebury, we report error inside its motion-discontinuity masks (Middlebury). KITTI 2015 F1-all tests real driving scenes.

On Spring, the high-detail regions are where MS-RAFT+'s outlier rate rose from about 5.7% overall to over 60% (Spring). These regions stress thin structures that a 1/8-resolution barrier may miss. Here we expect to help only when paired with TCU, and we say so in advance.

Two checks decide the outcome. First, path-gated attention must beat the concatenated-boundary ablation and the GAFlow-style Gaussian ablation on 0–10 band error. It must also not lose to GMA on unmatched-pixel error. Winning one of these at the expense of the other means we have only moved along the existing trade-off. Second, barrier quality must matter. Substituting ground-truth boundaries at test time should give an upper bound well below our learned result, and substituting static image edges should fall between GMA and our model. If learned barriers do no better than image edges, the contribution reduces to a differentiable EpicFlow.

We also report memory and runtime at 1080p next to Flow1D's reported 1.42GB versus RAFT's 8.33GB (Flow1D), to show that the row-and-column path computation stays in the efficient regime.