Transformers for images tell attention how far apart two patches are by counting pixels: two steps right, three steps down. On a fisheye camera, that count is misleading. A 190° lens squeezes the edge of the scene into a thin rim of pixels. The same pixel offset can therefore mean a few degrees of view near the image center and many degrees near the edge, and the direction of that offset rotates with position. We propose to measure relative position between tokens on the sphere of viewing directions rather than on the pixel grid.
Concretely, each token is back-projected through the lens model to the 3D ray it sees. The offset between two tokens becomes the angular displacement between their rays, written in a local tangent frame. Attention gets a bias computed from that angular offset. Because the lens is fixed for a given camera, the whole bias table can be computed once and cached, so the per-image cost matches an ordinary learned relative-position table. The tokens themselves stay on the usual rectangular feature map, so any multi-scale transformer backbone can use the encoding without resampling the image. We pair it with a two-branch block whose design follows from a specific hypothesis about where distortion actually hurts, and we test that hypothesis directly.
Core Claim
Distortion is smooth. Over a 3×3 neighborhood, a fisheye warp looks like a local change of scale and rotation, which convolutions already handle through data variety and multi-scale features. The nonlinearity only becomes severe over long offsets, and long offsets are exactly what global attention compares.
Our claim is that geometric correction belongs in the attention bias, keyed to viewing direction, and not in the local operators. A block that runs a plain pixel-grid depthwise convolution in parallel with ray-space-biased attention should match or beat designs that make every operator distortion-aware. A testable prediction follows. The benefit of ray-space encoding over Cartesian encoding should grow with attention span, and so with backbone stage and with distance from the optical center. Adding distortion awareness to the local branch should give little further gain.
Relation to Prior Work
The closest work is DarSwin, which supplies the key motivating evidence. DarSwin rebuilds Swin on a polar patch grid: it samples pixels per radial patch using the lens profile, uses angular relative encodings over incident angle and azimuth, and merges patches only along azimuth. Trained on low distortion and tested on high, it keeps about 88% accuracy where Swin falls to roughly 40%.
We keep DarSwin's insight that relative geometry should be angular, and drop its commitment to a polar tokenization. DarSwin's design has three consequences we avoid:
- It cannot slot into standard pyramid backbones or dense-prediction decoders.
- It resamples the image, which adds interpolation.
- Its azimuth-only merging changes the multi-scale structure.
We also evaluate on real dense fisheye tasks rather than mainly on synthetically distorted classification.
The encoding machinery comes from the Cartesian relative-encoding line:
- Bello et al. and BoTNet add learned horizontal and vertical offset tables to attention scores.
- iRPE shows that directed offsets, bucketed coarsely for far tokens, improve both DeiT and DETR at under 1% extra compute.
We reuse iRPE's directed, piecewise-bucketed bias form. The only change is that its argument becomes an angular offset instead of a pixel offset. iRPE also found that detection still needs absolute position, which constrains our design. On a fisheye, absolute incident angle carries real information, since object scale depends strongly on it. We therefore add a scalar absolute-angle embedding alongside the relative bias.
SegFormer is the direct counter-position. It drops explicit position encodings in favor of zero-padded depthwise convolutions in the feed-forward layer, a design validated only on pinhole images. No paper in our file tests whether that implicit cue survives radial distortion, and our ablations answer it.
The two-branch literature motivates the block topology:
- Dual-stream Network runs a high-resolution convolutional stream in parallel with self-attention to avoid mixing local and global signals.
- RoadFormer+ argues for scale-aware decoupling in driving-scene parsing.
Both work on rectilinear images and give no geometric reason for the split. We supply one, and we treat the split as a hypothesis to test rather than an assumption.
Finally, DSA handles fisheye segmentation with learned deformable offsets in parallel decoder branches, without calibration. It is the strongest reported dense baseline. It also constrains us, because it reports that deformable attention alone hurt some categories and cost 16 ms per image.
Research Program
Each token $i$ at stage $s$ has a pixel center $p_i$. Inverting the lens model gives its incident angle $\theta_i$ and azimuth $\phi_i$, hence a unit ray $u_i$. For WoodScape, this inversion uses the fourth-order polynomial $r(\theta)$ supplied by WoodScape. For a query token $i$ and key token $j$, we define the offset
$$\delta_{ij} = \big\langle \log_{u_i}(u_j),\, e^{(1)}_i \big\rangle,\ \big\langle \log_{u_i}(u_j),\, e^{(2)}_i \big\rangle,$$
where:
- $\log_{u_i}(u_j)$ is the tangent vector at $u_i$ pointing toward $u_j$, with length equal to the angle between them.
- $e^{(1)}_i, e^{(2)}_i$ are an orthonormal basis of the tangent plane at $u_i$.
Attention logits then become $q_i^\top k_j/\sqrt{d} + g(\delta_{ij})$. Here $g$ is an iRPE-style directed "product" bucketing of $\delta_{ij}$ into learned per-head scalars, with fine buckets for small angles and coarse ones for large.
The tangent basis matters. For vehicle-mounted cameras, we align $e^{(2)}_i$ with the projection of the camera's vertical axis, so "up" means the same thing everywhere. For overhead cameras, where objects rotate with azimuth as RAPiD shows, we align it with the radial direction. The choice between the two frames is an explicit ablation.
The encoding is used in both backbones:
- SegFormer-style backbone. Attention compares full-resolution queries with spatially reduced keys. Each reduced key takes the ray of its pooled region's center, so the encoding is consistent across all four stages.
- Swin-style windowed backbone. Used for the classification comparison with DarSwin.
The two-branch block replaces SegFormer's serial attention-then-convolution ordering. The local branch is a depthwise 3×3 convolution plus a pointwise projection on the pixel grid, with no geometry input. The global branch is spatial-reduction attention with the ray-space bias. Both branches produce outputs on the same full-resolution query grid. This removes the cross-resolution alignment problem that parallel designs usually face. The two outputs are summed through learned per-channel gates, followed by a shared MLP.
Calibration dependence is a known weakness of DarSwin and F2BEV. We address it modestly rather than claim to solve it. During training, we jitter the polynomial coefficients. At test time, we measure accuracy under controlled miscalibration. For FishEye8K, where our file lists no per-camera lens parameters, we fit a one-parameter equidistant model from the visible image circle and the stated 180° field of view. This crude calibration is itself a robustness test.
Baselines
Naive reference points. The first is SegFormer (MiT-B2 scale) trained directly on raw fisheye images with Mix-FFN and no explicit position encoding, which is the do-nothing option. The second is the same model trained on rectified images, with predictions warped back for scoring. We add a third naive point: identical architecture with the ray-space bias replaced by an all-zero bias. This separates the effect of the block topology from the effect of the encoding.
Strongest dense competitor: DSA. The strongest reported dense-prediction result is SegNeXt-DSA on WoodScape, at 65.33% mIoU and 74.5% of what DSA calls MAP. Its own SegNeXt baseline scores 64.11% mIoU. Because we cannot confirm DSA's exact split, we will not compare against its printed number. Instead, we retrain SegNeXt and SegNeXt-DSA on our WoodScape split with the same:
- crop size and schedule,
- ImageNet pretraining,
- hyperparameter-search budget (an equal number of learning-rate and weight-decay trials per method).
Beating DSA means exceeding the retrained SegNeXt-DSA by at least one mIoU point averaged over three seeds, at lower latency than its reported 16 ms overhead.
Encoding ablations. The key ablation holds everything fixed and swaps ray-space iRPE for Cartesian iRPE with the same bucketing and parameter count. This isolates the choice of geometry from the addition of a relative bias. We also retain a Mix-FFN-only variant to answer the SegFormer tension.
Classification against DarSwin. We reimplement DarSwin at Swin-S scale on the synthetically distorted 200-class ImageNet protocol. The file lists no code resource for DarSwin. Its reported numbers are:
- about 88% accuracy when trained on low and tested on high distortion, where Swin drops to roughly 40%;
- 92.6% top-1 at unseen distortion level $\xi=0.4$, versus 87.9% for Swin and 91.5% for the undistorted baseline.
Matching DarSwin's cross-distortion accuracy within one point, without polar resampling, counts as success, because our goal there is parity with a more general mechanism. Our reimplementation must first reproduce DarSwin's figures within two points before the comparison counts.
FishEye8K detection. The reference is YOLOR-P6 at [email protected] of 0.6632 at 1280×1280, as reported by FishEye8K. We attach a standard detection head to our backbone. We will compare against the same head on a Cartesian-encoded backbone rather than against YOLOR, since the detector families differ.
Why not just…?
Why not just rectify the image and use SegFormer? Rectification stretches the rim and discards or resamples peripheral content. Two results in our file show native processing winning:
- F2BEV reports 0.9106 mIoU on height maps working directly on distorted features, versus 0.8612 for BEVFormer on undistorted input.
- DarSwin beats its undistorted baseline, 92.6% versus 91.5%.
Neither result is on WoodScape segmentation, so we run rectified SegFormer ourselves. We break the scores down by radius band, where we expect rectification to lose mostly at the rim.
Why not just use deformable attention and learn the geometry from data? DSA reports that deformable attention alone hurt some categories and added latency. Learned offsets also carry no notion of viewing angle. That should show up as poor transfer when the lens changes. Our cross-camera test (train on front and rear WoodScape cameras, test on side cameras) and our miscalibration sweep probe exactly this. If DSA-style offsets transfer as well as ray-space encoding, the geometric prior is not earning its place, and we will report that.
Why not just add ray-space encoding to an unmodified SegFormer, with no second branch? This is the most serious alternative. It may capture most of the gain. We therefore run it as a first-class arm with the same parameter count. The two-branch block is kept only if it beats this serial version by a margin larger than seed variance, concentrated at large radii. If it does not, the paper's contribution narrows to the encoding and the geometric analysis, and we say so.
Why not just use DarSwin? DarSwin binds angular encoding to polar tokens and azimuth-only merging, and it has been shown mainly on classification. Our classification parity test and the WoodScape results together show whether a grid-native encoding keeps its robustness while plugging into standard dense pipelines.
Why not trust Mix-FFN's implicit position cue? Mix-FFN's cue comes from zero padding at the image border. On a fisheye, that border is a circle whose relation to viewing angle depends on the lens. The Mix-FFN-only arm, evaluated across distortion tiers, tests whether this cue survives.
Proposed Experiments
Datasets:
- WoodScape semantic segmentation is the primary benchmark. We report mIoU overall and in four radius bands. We also report per-class IoU for small classes such as pedestrians, which DSA flags as hardest at the periphery.
- Synthetically distorted ImageNet provides the controlled distortion sweep.
- FishEye8K detection tests an overhead-style camera with crude calibration.
The decisive check is the mechanism prediction, not the headline number. The gain of ray-space over Cartesian encoding should rise from stage 1 to stage 4 and from the center band to the rim. We measure this by swapping encodings one stage at a time. If the gain is flat across stages and radii, the "nonlinearity lives at long range" account is wrong, even if accuracy improves.
A second check tests the division of labor. We replace the local branch's plain convolution with a ray-resampled one. The hypothesis predicts under half a point of further gain.
A third check is the miscalibration sweep: we scale the polynomial coefficients by ±5%, ±10%, and ±20%. We then report the point at which ray-space encoding falls below Cartesian encoding. This gives an honest limit on how much calibration the method needs.
All arms are trained with three seeds under matched compute. Latency is measured on one GPU at WoodScape resolution with the cached bias tables.
References
- DarSwin: Distortion Aware Radial Swin Transformer
- Attention Augmented Convolutional Networks
- Bottleneck Transformers for Visual Recognition
- Rethinking and Improving Relative Position Encoding for Vision Transformer
- SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
- Dual-stream Network for Visual Recognition
- RoadFormer+: Delivering RGB-X Scene Parsing Through Scale-Aware Information Decoupling and Advanced Heterogeneous Feature Fusion
- DSA: Deformable Segmentation Attention for Multi-Scale Fisheye Image Segmentation
- WoodScape: A Multi-Task, Multi-Camera Fisheye Dataset for Autonomous Driving
- RAPiD: Rotation-Aware People Detection in Overhead Fisheye Images
- FishEye8K: A Benchmark and Dataset for Fisheye Camera Object Detection
- F2BEV: Bird's Eye View Generation from Surround-View Fisheye Camera Images for Automated Driving