Paper · 2022-03-27 · cs.CV
DepthFormer: Exploiting Long-Range Correlation and Local Information for Accurate Monocular Depth Estimation
Supervised monocular depth from one image: a Swin Transformer encoder for long-range context, a one-block CNN branch for local detail, and HAHI, a deformable attention module that fuses the two. Author-reported NYU Depth v2 delta1 0.921 and KITTI Eigen delta1 0.975, both above AdaBins; the most competitive KITTI benchmark result at submission.
Monocular depth estimationHierarchical vision transformersDeformable convolutionAttention mechanismmonocular-depthtransformercnn-hybriddeformable-attentiondense-prediction
arXivPDFCodeMarkdown16 min read
AI-compiled by claude-haiku-5-5 on 2026-11-06, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
A single photo does not say how far away each thing is. Monocular depth estimation is the task of guessing a distance for every pixel from that one picture. The authors observed that good guessing needs two kinds of information. The first is the whole scene: which objects are far from which. The second is fine local detail, such as the texture of a nearby object. Transformer networks are good at the first, and convolutional networks are good at the second.
DepthFormer keeps both. A Transformer (a Swin model) reads the whole image, and a small convolutional branch keeps local detail. Those two branches only meet at the end, so the paper adds a module, HAHI, that lets their features exchange information at several scales. Attention over every position of a high-resolution map would need too much memory. HAHI therefore attends only to a few learned sample points around each location.
The authors report that this design beats earlier methods on the NYU Depth v2 and KITTI datasets. On the KITTI online benchmark it was the most competitive result at the time of submission.
TL;DR
- Supervised depth estimation: one RGB image in, one depth value per pixel out §1 §4.1.
- Encoder: Swin Transformer stages for global context, plus a convolution stem for local detail §3.2.
- HAHI, a deformable-attention neck, enhances the Transformer features and models affinity with the convolution features, then feeds a DenseDepth-style decoder §3.3.
- Author-reported: NYU Depth v2 delta1 0.921 vs AdaBins 0.903 tab. 2; KITTI Eigen delta1 0.975 vs 0.964 tab. 3.
- The official Apache-2.0 code differs from the paper in several places (loss weight, reference-point source, fusion kernel, window size, warm-up, and the convolution branch). Read "Paper vs code" before implementing.
Problem
Monocular depth needs global context, because the distance of an object depends on the objects around it, and it needs local detail, because object boundaries and textures carry depth cues §1. The authors argue that a pure CNN encoder has a limited receptive field, so it fails on large regions such as wall decorations and carpets in NYU images §3.1 fig. 3.
A pilot study on KITTI, built on the DPT framework, compared ViT-Base with ResNet-50 §3.1. ViT-Base is better on far objects (60–80 m delta1 0.727 vs 0.600) but worse on near objects (0–20 m delta1 0.955 vs 0.973), and worse overall (0.938 vs 0.952) tab. 1. The authors explain the near-range loss by the Transformer's weak spatial inductive bias and by its fixed-scale tokens §3.1.
Global attention over high-resolution feature maps is too memory-hungry. The paper calls this cost unbearable but gives no memory measurements §3.3. The working assumption is that a few key points are enough to describe the scene structure §3.3 §5.
Method
Overview. DepthFormer has an encoder with two branches on the same input image, a HAHI neck, and a decoder. The decoder is the baseline DenseDepth-style decoder with up-convolution layers §3.3 fig. 2.
- Transformer branch. The image is split into non-overlapping patches. A linear layer embeds them, and then L Transformer layers run. Each layer applies multi-head self-attention and an MLP, with a LayerNorm before each and a residual connection around each §3.2 eq. 1. The paper uses Swin Transformer, which adds local windows, shifted windows and patch merging for hierarchical features §3.2.
- Transformer features F. The paper says it follows DPT and samples and reassembles N = 4 maps from selected Transformer layers, written f^n with C_n channels §3.2 §4.3. See "Paper vs code" for what the code does.
- Convolution branch G. The paper uses only the first ResNet block, with C_g output channels. It argues that deeper blocks wash out low-level features §3.2 §4.5 fig. 12.
- Projection. Each Transformer map goes through a 1×1 convolution to a common width C_h. Then all levels are flattened into one token set X, with a learned level embedding added §3.3.
- Deformable self-attention. Queries, keys and values are linear projections of X eq. 2. Each query attends to a few sampled points around a reference location, with learned attention weights and offsets eq. 3. The paper uses 8 reference points and 8 heads §4.3. The output is split back to the original level sizes, and the enhanced map is fused with the input map by concatenation and a 1×1 convolution §3.3 fig. 5. This gives F_o.
- Cross-attention for affinity. G is projected by a 1×1 convolution to C_h and flattened to queries. Keys and values come from the enhanced Transformer tokens. Reference points are predicted from the query embedding with a linear layer and a sigmoid §3.3.
- Fusion. The cross-attention output is reshaped to G's grid and fused with G by concatenation and a 1×1 convolution, which gives G_o §3.3.
- Loss. Both F_o and G_o go to the decoder. The depth loss is a scale-invariant log error with weights λ = 0.85 and α = 10 §3.3 eq. 4.
# HAHI: enhance the Transformer maps F and model affinity with G [§3.3]
# Input: F, list of 4 maps (B, C_n, H_n, W_n), one per Transformer stage
# G, convolution-branch map (B, C_g, H_g, W_g)
# Output: F_o, list of 4 maps; G_o, map with the shape of G
def hahi(F, G, C_h):
# Project every level to the same width C_h with 1x1 convs [§3.3]
F_h = [conv1x1(f, out_channels=C_h) for f in F]
# Flatten all levels into one token set X; add a level embedding [§3.3]
X = concat([flatten(f) + level_embed[n] for n, f in enumerate(F_h)])
# Deformable self-attention: each query samples a few learned points,
# with 8 reference points [§4.3] [eq. 3]
X_hat = deformable_attention(queries=X, values=X, num_points=8)
# Split X_hat back into the original per-level shapes [§3.3]
F_enh = unflatten(X_hat, shapes_of(F_h))
# Fuse enhanced and input maps per level: concat, then 1x1 conv [§3.3]
F_o = [conv1x1(concat([f, e])) for f, e in zip(F, F_enh)]
# Affinity queries come from G, projected to C_h [§3.3]
Q = flatten(conv1x1(G, out_channels=C_h))
# Keys and values are X_hat; reference points come from the query
# embedding through a linear layer and a sigmoid [§3.3]
points = sigmoid(linear(query_embedding(Q)))
G_att = deformable_attention(queries=Q, values=X_hat, points=points)
# Fuse G_att with G: concat, then 1x1 conv [§3.3]
G_o = conv1x1(concat([unflatten(G_att, shape_of(G)), G]))
return F_o, G_o# Depth loss: scale-invariant log error [§3.3] [eq. 4]
# Input: pred (B, H, W), predicted depth; gt (B, H, W), 0 = no depth
# Output: scalar loss
def depth_loss(pred, gt, lam=0.85, alpha=10.0):
# Keep only pixels with valid ground truth; T is their count [§3.3]
valid = gt > 0
# Per-pixel log difference h_i [eq. 4]
h = log(pred[valid]) - log(gt[valid])
# Mean of h squared minus lam times the squared mean of h [eq. 4]
spread = mean(h ** 2) - lam * mean(h) ** 2
# Weight by alpha [§3.3]
return alpha * sqrt(spread)Key equations, as written in the paper:
Transformer layer l, with the MLP line numbered eq. 1. The source numbers only that line:
\hat{z}^{l} = \mathrm{MSA}\left(\mathrm{LN}\left(z^{l-1}\right)\right) + z^{l-1}
z^{l} = \mathrm{MLP}\left(\mathrm{LN}\left(\hat{z}^{l}\right)\right) + \hat{z}^{l} eq. 1
Queries, keys and values from the flattened tokens X eq. 2:
\mathbf{Q} = X\mathbf{P}_Q, \quad \mathbf{K} = X\mathbf{P}_K, \quad \mathbf{V} = X\mathbf{P}_V eq. 2
Deformable attention for query q eq. 3:
\mathrm{DAttn}(x_q, x_v, p_q) = \sum_{k \in \Omega_k} A_{qk}\, x_v\left(p_q + \Delta p_{qk}\right) eq. 3
The paper normalises A_qk to sum to 1 and uses bilinear interpolation for fractional sampling positions §3.3.
Depth loss, with h_i = log d̃_i − log d_i and T the number of pixels with valid ground truth eq. 4 §3.3:
\mathcal{L}_{pixel} = \alpha \sqrt{\frac{1}{T}\sum_i h_i^{2} - \frac{\lambda}{T^{2}}\left(\sum_i h_i\right)^{2}} eq. 4
Hyperparameters
Values are as the paper states them unless the Notes column says otherwise. "Not stated" means the paper gives no value. Code-only values are marked and are not confirmed by the paper.
| Name | Value | Where | Notes |
|---|---|---|---|
| Encoder (headline rows) | Swin-L, with a ResNet-50 convolution branch | tab. 2 tab. 3 | Swin-T, Swin-B and Swin-L appear in the ablation tab. 6 |
| Encoder pre-training | ImageNet; ImageNet-22K for the "+LP" rows | §4.3 tab. 6 | The text does not say which for the headline rows. Code loads a 22K checkpoint depthformer_swinl_22k_w7_nyu.py |
| Swin window size | 12 | §4.3 | Code uses 7 [code: configs/base/models/depthformer_swin.py#L13] |
| Transformer maps N | 4 | §4.3 | Code uses the four Swin stage outputs depthformer_swin.py |
| Convolution branch | First ResNet block, C_g channels | §3.2 | Code builds the stem only; C_g = 64 depthformer_swin.py [code: configs/base/models/depthformer_swin.py#L31] |
| Common width C_h | Median channel dimension of F | §4.3 | Code hard-codes 512 for Swin-L and 256 for Swin-T depthformer_swinl_22k_w7_nyu.py depthformer_swint_w7_nyu.py |
| Reference points per query | 8 | §4.3 | hahi.py |
| Deformable attention heads | 8 | §4.3 | hahi.py |
| Loss λ | 0.85 | §3.3 | Code writes the same term as 0.15 times the squared mean sigloss.py |
| Loss α | 10 | §3.3 | Code sets loss_weight to 1.0 [code: configs/base/models/depthformer_swin.py#L38-L39] |
| Depth cap, NYU | 10 m | §4.1 | depthformer_swinl_22k_w7_nyu.py |
| Depth range, KITTI | 0–80 m | tab. 3 caption | depthformer_swinl_22k_w7_kitti.py |
| NYU training subset | 50K RGB-depth pairs | §4.1 | Not stated in the paper: crop size 416×544 [code: configs/base/datasets/nyu.py#L6] |
| KITTI training subset | About 26K left-view images, 697 test frames (Eigen) | §4.1 | Code training crop 352×704 [code: configs/base/datasets/kitti.py#L6] |
| Evaluation crop, NYU | Eigen center crop | §4.1 §4.2 | [code: configs/base/datasets/nyu.py#L68] |
| Evaluation crop, KITTI | Garg crop | §4.1 | [code: configs/base/datasets/kitti.py#L57] |
| Optimizer | AdamW, weight decay 0.01 | §4.3 | Code betas (0.9, 0.999) depthformer_swinl_22k_w7_nyu.py |
| Batch size | 2 | §4.3 | Code sets samples_per_gpu=2, which is per GPU depthformer_swinl_22k_w7_nyu.py |
| Learning rate, Swin-L | 1e-4 | §4.3 | depthformer_swinl_22k_w7_nyu.py |
| Learning rate, Transformer | 6e-5 | §4.3 | Same section also gives 1e-4 for the ResNet model. Code Swin-T config uses 6e-5 depthformer_swint_w7_nyu.py |
| Training length | 38.4k iterations | §4.3 | 1600 × 24 iterations depthformer_swinl_22k_w7_nyu.py |
| Warm-up | Linear, first 30% of iterations; the same section also says "first 500 iterations" | §4.3 | Code uses 12800 iterations (33% of 38.4k) depthformer_swinl_22k_w7_nyu.py |
| Decay | Cosine annealing | §4.3 | Code: CosineAnnealing, min_lr_ratio 1e-8 depthformer_swinl_22k_w7_nyu.py |
| Learning-rate policy, alternative | "1-cycle" | §4.3 | Not used by the DepthFormer configs; it is only in the generic schedule file [code: configs/base/schedules/schedule_24x.py#L6] |
| Gradient clipping | Not stated | — | Code: L2 norm, max 35 depthformer_swinl_22k_w7_nyu.py |
| Stochastic depth (drop path) | Not stated | — | Code: 0.3 [code: configs/base/models/depthformer_swin.py#L24] |
| Prediction head | Not stated | — | Code: ReLU plus min_depth 1e-3 decode_head.py |
| Hardware | 8 × NVIDIA V100 32 GB, about 5 hours | §4.3 | Training length as above |
| Test-time augmentation | Not stated in the active text; the mirror-averaging paragraph is commented out in the source | §4.3 | Code averages a horizontal flip [code: configs/base/datasets/nyu.py#L29] encoder_decoder.py |
Results
Author-reported. Baseline numbers are copied from the original papers according to the captions tab. 2 tab. 3 tab. 5. §4.4 also says the authors reproduced AdaBins from its released code and weights §4.4. This conflicts with the captions. Setups:
- NYU Depth v2. 50K training pairs, Eigen center crop, depth capped at 10 m §4.1 §4.2.
- KITTI Eigen split. Garg crop, depth range 0–80 m §4.1 tab. 3.
- KITTI benchmark. Trained on the standard benchmark split, scored by the online server §4.4 tab. 4.
- SUN RGB-D. Trained on NYU only, no fine-tuning, 5050 test images §4.1 tab. 5.
tab. 2 NYU Depth v2, test set:
| Method | δ1 ↑ | δ2 ↑ | δ3 ↑ | REL ↓ | RMS ↓ | log10 ↓ |
|---|---|---|---|---|---|---|
| Eigen et al. | 0.769 | 0.950 | 0.988 | 0.158 | 0.641 | -- |
| Laina et al. | 0.811 | 0.953 | 0.988 | 0.127 | 0.573 | 0.055 |
| StructDepth | 0.817 | 0.955 | 0.988 | 0.140 | 0.534 | 0.060 |
| MonoIndoor | 0.823 | 0.958 | 0.989 | 0.134 | 0.526 | - |
| DORN | 0.828 | 0.965 | 0.992 | 0.115 | 0.509 | 0.051 |
| BTS | 0.885 | 0.978 | 0.994 | 0.110 | 0.392 | 0.047 |
| DAV | 0.882 | 0.980 | 0.996 | 0.108 | 0.412 | -- |
| TransDepth | 0.900 | 0.983 | 0.996 | 0.106 | 0.365 | 0.045 |
| DPT | 0.904 | 0.988 | 0.998 | 0.110 | 0.357 | 0.045 |
| AdaBins | 0.903 | 0.984 | 0.997 | 0.103 | 0.364 | 0.044 |
| DepthFormer | 0.921 | 0.989 | 0.998 | 0.096 | 0.339 | 0.041 |
tab. 3 KITTI Eigen split, 0–80 m:
| Method | Backbone | δ1 ↑ | δ2 ↑ | δ3 ↑ | REL ↓ | Sq ↓ | RMS ↓ | RMS log ↓ |
|---|---|---|---|---|---|---|---|---|
| Godard et al. | ResNet-50 | 0.861 | 0.949 | 0.976 | 0.114 | 0.898 | 4.935 | 0.206 |
| Johnston et al. | ResNet-101 | 0.889 | 0.962 | 0.982 | 0.106 | 0.861 | 4.699 | 0.185 |
| Gan et al. | ResNet-101 | 0.890 | 0.964 | 0.985 | 0.098 | 0.666 | 3.933 | 0.173 |
| DORN | ResNet-101 | 0.932 | 0.984 | 0.994 | 0.072 | 0.307 | 2.727 | 0.120 |
| Yin et al. | ResNeXt-101 | 0.938 | 0.990 | 0.998 | 0.072 | -- | 3.258 | 0.117 |
| PGA-Net | ResNet-50 | 0.952 | 0.992 | 0.998 | 0.063 | 0.267 | 2.634 | 0.101 |
| BTS | DenseNet-161 | 0.956 | 0.993 | 0.998 | 0.059 | 0.245 | 2.756 | 0.096 |
| TransDepth | ViT-B + ResNet-50 | 0.956 | 0.994 | 0.999 | 0.064 | 0.252 | 2.755 | 0.098 |
| DPT-Hybrid | ViT-B + R-50 (C1, C2) | 0.959 | 0.995 | 0.999 | 0.062 | -- | 2.573 | 0.092 |
| AdaBins | Mini-ViT + EfficientNet-B5 | 0.964 | 0.995 | 0.999 | 0.058 | 0.190 | 2.360 | 0.088 |
| DepthFormer | Swin-L + R-50 (C1) | 0.975 | 0.997 | 0.999 | 0.052 | 0.158 | 2.143 | 0.079 |
tab. 4 KITTI benchmark test set (online server, submitted Nov. 16, 2021 per §4.4):
| Method | SILog ↓ | sqErrorRel ↓ | absErrorRel ↓ | iRMSE ↓ |
|---|---|---|---|---|
| DORN | 11.77 | 2.23 | 8.78 | 12.98 |
| BTS | 11.67 | 2.21 | 9.04 | 12.23 |
| BANet | 11.55 | 2.31 | 9.34 | 12.17 |
| PWA | 11.45 | 2.30 | 9.05 | 12.32 |
| ViP-DeepLab | 10.80 | 2.19 | 8.94 | 11.77 |
| DepthFormer | 10.46 | 1.82 | 8.54 | 11.17 |
tab. 5 SUN RGB-D, trained on NYU only, no fine-tuning (baseline numbers from the AdaBins paper per the caption):
| Method | δ1 ↑ | δ2 ↑ | δ3 ↑ | REL ↓ | RMS ↓ | log10 ↓ |
|---|---|---|---|---|---|---|
| Chen et al. | 0.757 | 0.943 | 0.984 | 0.166 | 0.494 | 0.071 |
| Yin et al. | 0.696 | 0.912 | 0.973 | 0.183 | 0.541 | 0.082 |
| BTS | 0.740 | 0.933 | 0.980 | 0.172 | 0.515 | 0.075 |
| AdaBins | 0.771 | 0.944 | 0.983 | 0.159 | 0.476 | 0.068 |
| DepthFormer | 0.815 | 0.970 | 0.993 | 0.137 | 0.408 | 0.059 |
tab. 6 Ablation on NYU. CB is the convolution branch. LP is 22K-ImageNet pre-training:
| Backbone | Components | δ1 ↑ | δ2 ↑ | δ3 ↑ | REL ↓ | RMS ↓ |
|---|---|---|---|---|---|---|
| ResNet-50 | none | 0.811 | 0.961 | 0.991 | 0.145 | 0.482 |
| ResNet-50 | +HAHI | 0.866 | 0.976 | 0.994 | 0.122 | 0.411 |
| ResNet-50 | +HAHI+LP | 0.865 | 0.976 | 0.995 | 0.124 | 0.406 |
| Swin-T | none | 0.847 | 0.975 | 0.993 | 0.131 | 0.432 |
| Swin-T | +HAHI | 0.866 | 0.977 | 0.995 | 0.125 | 0.409 |
| Swin-T | +CB | 0.851 | 0.977 | 0.995 | 0.129 | 0.425 |
| Swin-T | +CB+HAHI | 0.871 | 0.979 | 0.995 | 0.120 | 0.399 |
| Swin-B | +CB+HAHI | 0.892 | 0.984 | 0.997 | 0.109 | 0.373 |
| Swin-B | +CB+HAHI+LP | 0.910 | 0.987 | 0.997 | 0.101 | 0.348 |
| Swin-L | +CB+HAHI+LP | 0.921 | 0.989 | 0.998 | 0.096 | 0.339 |
tab. 7 HAHI ablation on NYU, Swin-T with CB:
| DSA single-level | DSA multi-level | DCA | δ1 ↑ | REL ↓ | RMS ↓ |
|---|---|---|---|---|---|
| no | no | no | 0.847 | 0.131 | 0.432 |
| yes | no | no | 0.850 | 0.131 | 0.427 |
| no | yes | no | 0.867 | 0.124 | 0.408 |
| no | no | yes | 0.828 | 0.143 | 0.443 |
| yes | no | yes | 0.831 | 0.144 | 0.449 |
| no | yes | yes | 0.871 | 0.120 | 0.399 |
tab. 8 Detailed KITTI results for the pilot study and the Swin-T ablation. tab. 1 is the first six rows of this table:
| Backbone | Extra | Range | δ1 ↑ | δ2 ↑ | δ3 ↑ | REL ↓ | RMS ↓ |
|---|---|---|---|---|---|---|---|
| ResNet-50 | -- | 0–20 m | 0.973 | 0.998 | 1 | 0.054 | 0.985 |
| ResNet-50 | -- | 60–80 m | 0.600 | 0.900 | 0.972 | 0.188 | 14.30 |
| ResNet-50 | -- | Overall | 0.952 | 0.994 | 0.999 | 0.065 | 2.596 |
| ViT-Base | -- | 0–20 m | 0.955 | 0.995 | 0.999 | 0.071 | 1.275 |
| ViT-Base | -- | 60–80 m | 0.727 | 0.936 | 0.985 | 0.150 | 11.86 |
| ViT-Base | -- | Overall | 0.938 | 0.992 | 0.999 | 0.080 | 2.695 |
| ViT-Base | +CB | 0–20 m | 0.960 | 0.996 | 0.999 | 0.067 | 1.223 |
| ViT-Base | +CB | 60–80 m | 0.725 | 0.950 | 0.984 | 0.147 | 11.69 |
| ViT-Base | +CB | Overall | 0.942 | 0.994 | 0.999 | 0.076 | 2.644 |
| ViT-Base | +CB+HAHI | 0–20 m | 0.964 | 0.995 | 0.999 | 0.064 | 1.172 |
| ViT-Base | +CB+HAHI | 60–80 m | 0.712 | 0.946 | 0.984 | 0.150 | 11.90 |
| ViT-Base | +CB+HAHI | Overall | 0.948 | 0.993 | 0.999 | 0.073 | 2.596 |
| Swin-T | -- | 0–20 m | 0.972 | 0.998 | 1 | 0.050 | 0.948 |
| Swin-T | -- | 60–80 m | 0.729 | 0.941 | 0.984 | 0.150 | 11.85 |
| Swin-T | -- | Overall | 0.961 | 0.993 | 0.999 | 0.062 | 2.402 |
| Swin-T | +CB | 0–20 m | 0.979 | 0.998 | 1 | 0.049 | 0.934 |
| Swin-T | +CB | 60–80 m | 0.726 | 0.945 | 0.984 | 0.149 | 11.76 |
| Swin-T | +CB | Overall | 0.964 | 0.995 | 0.999 | 0.060 | 2.310 |
| Swin-T | +CB+HAHI | 0–20 m | 0.981 | 0.998 | 1 | 0.049 | 0.911 |
| Swin-T | +CB+HAHI | 60–80 m | 0.744 | 0.939 | 0.981 | 0.146 | 11.61 |
| Swin-T | +CB+HAHI | Overall | 0.966 | 0.996 | 0.999 | 0.059 | 2.261 |
Speed. The paper reports inference time for DepthFormer without HAHI on an RTX 3060 at 352×1216, and says it is faster and more accurate than the compared methods §4.5 fig. 14. No timing table is given.
Training cost. About 5 hours for 38.4k iterations on 8 V100 GPUs §4.3.
Paper vs code
Code: the official toolbox linked in the abstract and footnote §1 §5. The repository's LICENSE file is Apache License 2.0, and its header names the MMSegmentation authors. I cloned it at commit d8aff50e75c4b0c183361c7690959d0269b45a9d. I did not search further, because the paper links the repository.
Each difference below cites both sides. Items are ordered by how much they change the result.
- Loss weight α. The paper uses α = 10 §3.3. The code uses loss_weight = 1.0 and no override in the DepthFormer configs [code: configs/base/models/depthformer_swin.py#L38-L39] sigloss.py.
- Reference-point source. The paper predicts cross-attention reference points from the "affinity query embedding" §3.3. The code feeds a sinusoidal positional encoding built from an all-zero mask through a linear layer and a sigmoid hahi.py. The points therefore do not depend on image content hahi.py.
- Fusion convolutions. The paper fuses with 1×1 convolutions §3.3. The code uses 3×3 convolutions for both fusions hahi.py hahi.py hahi.py hahi.py.
- Common width C_h. The paper sets it to the median channel dimension of F §4.3. The code hard-codes 512 for Swin-L and 256 for Swin-T depthformer_swinl_22k_w7_nyu.py depthformer_swint_w7_nyu.py. For the Swin-L widths 192, 384, 768 and 1536, the median would be 576.
- Window size. The paper says 12 §4.3. The code uses 7 [code: configs/base/models/depthformer_swin.py#L13].
- Convolution branch. The paper uses the first ResNet block §3.2. The code builds the stem only (7×7 stride-2 convolution, BN, ReLU). The max-pool and residual stages run only when num_stages ≠ 0, and the base config sets num_stages = 0 depthformer_swin.py depthformer_swin.py [code: configs/base/models/depthformer_swin.py#L31].
- Transformer maps. The paper follows DPT and reassembles the selected layers §3.2. The code takes the four Swin stage outputs directly into HAHI. The DPT-style reassemble module is not on the DepthFormer path depthformer_swin.py.
- Learning rate. The paper gives 1e-4 for the whole network §4.3. The same section also gives 6e-5 for Transformer models and a "1-cycle" schedule. The code uses cosine annealing, 6e-5 for Swin-T and 1e-4 for Swin-L depthformer_swinl_22k_w7_nyu.py depthformer_swint_w7_nyu.py.
- Warm-up. The paper says 30% of iterations and also "500 iterations" §4.3. The code uses 12800 of 38400 iterations, which is 33% depthformer_swinl_22k_w7_nyu.py.
- Batch size. The paper says batch size 2 on 8 GPUs §4.3. The code's samples_per_gpu = 2 is per GPU, so the global batch is 16 on 8 GPUs unless the paper's 2 is the global value depthformer_swinl_22k_w7_nyu.py. I could not resolve this from the sources.
- Test-time augmentation. The mirror-averaging paragraph in the paper source is commented out §4.3. The active text does not describe test-time augmentation. The code averages the prediction with its horizontal flip at test time [code: configs/base/datasets/nyu.py#L29] [code: configs/base/datasets/kitti.py#L32] encoder_decoder.py.
- Pre-training. The paper says ImageNet pre-training §4.3. The Swin-L headline configs load an ImageNet-22K checkpoint depthformer_swinl_22k_w7_nyu.py.
- Prediction head. The paper does not say how the depth output is produced. The code uses ReLU plus min_depth = 1e-3 by default decode_head.py. Prediction is resized to the ground-truth size before the loss decode_head.py.
- Variance estimator. The paper's formula uses 1/T eq. 4. The code calls torch.var, which divides by T − 1 by default, and adds eps = 1e-3 inside the logs sigloss.py sigloss.py.
- Loss mask. The paper defines T as the number of valid pixels §3.3. The loss mask is target > 0 only, because max_depth is not passed to SigLoss sigloss.py. I did not check whether the loaders clip ground truth above the cap.
- Baseline numbers. The table captions say baselines come from the original papers tab. 2 tab. 3. §4.4 says AdaBins was reproduced §4.4. Which numbers the AdaBins row uses is therefore unclear.
Pitfalls
- Loss scale. The paper's α = 10 makes the loss 10× larger than the code's. The effect on training is untested. The optimizer config clips gradients at max-norm 35 depthformer_swinl_22k_w7_nyu.py, so the loss scale matters at least through that clip.
- Reference points. Because the code's reference points come from a fixed positional encoding, the cross-attention sampling pattern is the same for every image, given the learned weights. The paper's description suggests it depends on the query features. If you follow the released code, use its behaviour; the paper does not settle the question.
- Undefined terms. The paper does not define the "affinity query embedding", the reference points for self-attention, or the C_h "median" rule in the same terms as the code.
- Deformable kernels. The code uses MMCV's MultiScaleDeformableAttention CUDA op hahi.py. A pure PyTorch version is possible, but I did not check whether it matches the op numerically.
- Memory. The paper says global attention is too costly, but gives no memory numbers. The speed claim applies to DepthFormer without HAHI §4.5 fig. 14.
- Ablation arithmetic. The paper says multi-level self-attention gives a 4.9% RMS gain §4.5. From tab. 7 the single-level to multi-level step is 0.427 → 0.408, which is 4.4%. The paper's 2.2% DCA gain (0.408 → 0.399) does match.
- Benchmark claim. The paper says sqErrorRel improves by 16% §4.4. Against ViP-DeepLab's 2.19, DepthFormer's 1.82 is about 17% lower. The KITTI test numbers come from the online server and cannot be reproduced from the repository alone.
- Column labels. In tab. 1, tab. 6 and tab. 8, the third accuracy column is labelled δ2 twice. The values (0.998–1) show it is δ3.
- Interpretation of "first block". The paper says the best result comes from one ResNet block, and that more blocks hurt §4.5 fig. 12. The code's stem is not the same as a ResNet block with residual layers, so the ablation may not be reproducible from the code path alone.
- Budget. Training takes 38.4k iterations at batch size 2 on 8 V100 GPUs, about 5 hours §4.3. Check the batch-size question above before you budget.
Lineage
- Builds on: Swin Transformer for the encoder §3.2. AdaBins supplies the λ = 0.85 and α = 10 loss settings and the warm-up practice §3.3 §4.3. Deformable DETR (cited as zhu2020deformabledetr) supplies the deformable attention §3.3. DPT (cited as ranftl2021dpt) supplies the reassembly and the ViT-based depth framing §3.2. The DenseDepth-style decoder is cited as alhashim2018densedepth §3.3.
- Compared against: AdaBins, BTS, DPT, TransDepth, DORN, ViP-DeepLab, PWA, BANet and others in tab. 2 to tab. 5.
- Superseded by: not known from content on this wiki.
Source and license
Adapted from “DepthFormer: Exploiting Long-Range Correlation and Local Information for Accurate Monocular Depth Estimation” by Zhenyu Li, Zehui Chen, Xianming Liu, Junjun Jiang (arXiv:2203.14211), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/zhyever/Monocular-Depth-Estimation-Toolbox at commit d8aff50e75c4 (Apache-2.0). Any quoted code is shown under that license.