Paper · 2022-04-03 · cs.CV
BinsFormer: Revisiting Adaptive Bins for Monocular Depth Estimation
BinsFormer predicts depth as a per-pixel mix of adaptive bin centres. A Transformer decoder generates the bins from learned queries, one extra query classifies the scene, and features are refined at three scales. Author-reported: on NYU Depth v2 with a Swin-Large backbone (ImageNet-22K), delta1 0.925 and RMS 0.330; on KITTI Eigen, delta1 0.974 and RMS 2.098.
Monocular depth estimationObject queries (learned query slots in transformer decoders)computer-visiondepth-estimationtransformeradaptive-binsmulti-scale
arXivPDFCodeMarkdown17 min read
AI-compiled by claude-haiku-5-5 on 2026-10-18, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Most depth models guess one distance for each pixel directly. BinsFormer first decides, for each photo, a small set of depth ranges ("bins") that suit that scene. Each pixel then gets a probability for every range, and its depth is the weighted average of the range centres. Choosing the ranges per image lets the model spend its resolution where the scene's depths actually are.
The bins come from a Transformer decoder that looks at the whole image and proposes them in one pass. The authors keep this global part apart from the detailed per-pixel features, so the two do not overwrite each other. Two more additions help. One extra query predicts what kind of room or street the photo shows. The bins are also refined at three image resolutions, from coarse to fine.
The model learns from photos with measured depth maps, and it is judged on standard indoor and outdoor depth benchmarks.
TL;DR
BinsFormer estimates depth from one RGB image as a probability-weighted average of bin centres that are generated per image. A Transformer decoder produces the bins from learned queries, and a separate per-pixel branch produces the probabilities §3.2.1 §3.2.2 §3.2.3. An auxiliary scene-classification query and multi-scale refinement are added §3.2.4 §3.2.5. Author-reported, the authors report that it outperforms the compared methods on KITTI, NYU and the SUN RGB-D cross-dataset test §4.3.1 §4.3.2 §4.3.3. The official code differs from the paper in several training details, listed under Paper vs code.
Problem
Per-pixel regression is the most direct formulation, but it converges slowly and gives weaker results §1. Classifying discretised depth gives sharp steps between levels §1. Classification-regression methods avoid both problems by predicting a probability over bins and taking a weighted sum of bin centres §1. Their bins were fixed, uniform or log-spaced, or learned once per dataset §1. AdaBins makes the bins adaptive, but the authors list three limits of it: the bins are predicted from the highest-resolution feature map, which limits global context; bins and per-pixel probabilities share one feature; and its chamfer loss adds an inductive bias §1. The method assumes a per-dataset minimum and maximum valid depth §3.2.3.
Method
The model has a pixel-level module, a Transformer module and a depth-estimation module, plus a scene-classification auxiliary task and multi-scale refinement §3.1 fig. 2. Bin generation is framed as a direct set-to-set prediction problem solved by a Transformer decoder §1 §3.2.2.
- Per-pixel features. A backbone and a decoder give per-pixel features f_p of size H×W×C and S multi-scale features F §3.2.1. Any depth decoder can serve here. The code uses a light FPN §4.2.3 binsformer_head.py.
- Bin and scene queries. N bin queries (64 by default §4.2.4 tab. 6) and one scene query enter the Transformer decoder, which attends to F §3.2.2 binsformer_head.py. Each query output feeds two heads: a bin-length logit and a bin embedding from a 3-layer ReLU MLP §3.2.2. The scene query feeds a 3-layer MLP that classifies the scene §3.2.4 transformer.py.
- Bin lengths and centres. The bin-length logits pass through a softmax over the N bins §3.2.2. Each bin's centre is then computed from the cumulative lengths, with the dataset's minimum and maximum depth as bounds §3.2.3 eq. 1.
- Probabilities. For every pixel, a softmax over the N bins of the dot product between f_p and each bin embedding gives the probability distribution P §3.2.3.
- Depth. The depth at each pixel is the sum of centre times probability over the bins §3.2.3 eq. 2.
- Scene classification. A cross-entropy loss on the scene query's output, with a small weight μ §3.2.4 eq. 4. The paper uses 25 indoor classes, taken from the folder names of NYU §4.2.1. KITTI has no scene loss §4.2.1.
- Multi-scale refinement. The three feature scales are handled one at a time. Each scale has L = 3 decoder layers, nine layers in total §4.2.4. The paper says the queries start at zero and carry learnable positional embeddings §3.2.5 (the code differs; see Paper vs code). In each layer, a cross-attention block to that scale's features is followed by a self-attention block and a feed-forward network §3.2.5. The depth module runs after every layer for auxiliary supervision §3.2.5.
- Losses. The depth loss is a scaled scale-invariant loss with λ = 0.85 and α = 10 §3.2.3 eq. 3. The total loss weights each layer's losses by a per-scale weight w_s §3.2.5 eq. 4.
Equations as numbered in the paper:
c(b_i) = d_{min} + \left(d_{max} - d_{min}\right)\left(\frac{b_i}{2} + \sum_{j=1}^{i-1} b_j\right) eq. 1
\hat d = \sum_{i=1}^{N} c(b_i)\, p_i eq. 2
\mathcal{L}_{reg} = \alpha \sqrt{\frac{1}{T}\sum_i g_i^{2} - \frac{\lambda}{T^2}\Big(\sum_i g_i\Big)^2}, \qquad g_i = \log \tilde d_i - \log d_i eq. 3
\mathcal{L}_{total} = \sum_{s=1}^{S} \Big( w_s \sum_{l=1}^{L} \big( \mathcal{L}_{reg}^{s,l} + \mu\, \mathcal{L}_{cls}^{s,l} \big) \Big) eq. 4
With μ = 1e-3 and w_s = {1/2^s, 1/2^(s-1), ..., 1} as written in the paper §3.2.5 eq. 4. The symbols b_i, c, d_min and d_max are defined in §3.2.3 eq. 1. T is the number of pixels with valid ground truth, and g_i is the log-depth error §3.2.3 eq. 3.
The paper has no algorithm box. The pseudocode below is written from the description above, in the paper's form. Where the official code differs, see Paper vs code.
# BinsFormer depth prediction for one image [§3.2] [eq. 1] [eq. 2]
# Input: features F (multi-scale); per-pixel features f_p (B, C, H, W)
# Output: per-layer depth (B, 1, H, W); per-layer scene logits (B, 25)
def predict_depth(features, per_pixel):
# 1. Learned queries: index 0 is the scene query, 1..N the bin queries
# [§3.2.2] [§4.2.4]
queries = embed_queries(N + 1) # (N+1, C_q)
# 2. Run the decoder layers, one scale per layer [§3.2.5]
# (the scale order is a Paper vs code item)
layer_outputs = transformer_decoder(queries, features, per_pixel)
depths = []
scene_logits = []
for out in layer_outputs:
# 3. Scene logits from the scene query [§3.2.4]
scene_logits.append(mlp_scene(out[0])) # (B, 25)
# 4. Bin lengths: softmax over the N bin outputs [§3.2.2]
bin_lengths = softmax(linear(out[1:]), axis="bins") # (B, N)
# 5. Bin centres from cumulative bin lengths [§3.2.3] [eq. 1]
centres = bin_centres(bin_lengths, d_min, d_max) # (B, N)
# 6. Bin embeddings from a 3-layer ReLU MLP [§3.2.2]
bin_embed = mlp_bins(out[1:]) # (B, N, C)
# 7. Per-pixel probabilities: softmax over bins of a dot product
# [§3.2.3]
logits = einsum("bnc,bchw->bnhw", bin_embed, per_pixel)
probs = softmax(logits, axis="bins") # (B, N, H, W)
# 8. Depth is the probability-weighted sum of centres [§3.2.3] [eq. 2]
depths.append(sum(probs * centres[:, :, None, None], axis="bins"))
return depths, scene_logits# Training loss, summed over every decoder layer [§3.2.5] [eq. 4]
# Input: per-layer depths and scene logits; ground-truth depth and scene label
# Scale weights w_s and layer grouping: see Paper vs code
def total_loss(depths, scene_logits, depth_gt, scene_gt):
total = 0.0
for layer in range(num_layers):
# 1. Scale-invariant loss on pixels with valid ground truth [eq. 3]
# alpha = 10, lambda = 0.85 [§3.2.3]
reg = sigloss(depths[layer], depth_gt)
# 2. Scene cross-entropy, weight mu = 1e-3 [§3.2.4] [eq. 4]
cls = cross_entropy(scene_logits[layer], scene_gt)
# 3. Per-scale weight w_s applied to both terms [§3.2.5] [eq. 4]
total = total + scale_weight(layer) * (reg + mu * cls)
return totalHyperparameters
Values the paper gives are cited to the paper. "Not stated" means the paper does not give the value. Code values come from the Swin-Large NYU config unless another config is named.
| Name | Value | Where | Notes |
|---|---|---|---|
| Backbone | Swin-Large, ImageNet-22K pre-trained (†) | §4.2.2 binsformer_swinl_22k_w7_nyu.py | Paper also names ResNet-18/50 and Swin-Tiny/Base; no ResNet config exists in configs/binsformer/ |
| Swin depths, heads, window | depths [2, 2, 18, 2], embed 192, heads [6, 12, 24, 48], window 7 | binsformer_swinl_22k_w7_nyu.py | Not stated in paper; Swin-Large architecture from §4.2.2 only |
| Pixel decoder | light-weight FPN | §4.2.3 binsformer_head.py | Channel width not stated in paper; code uses 512 binsformer_swinl_22k_w7_nyu.py |
| Multi-scale features | 3 scales (trans_index = [1, 2, 3]) | §3.2.5 binsformer_head.py | Scale count is stated; scale choice per layer, see Paper vs code |
| Deformable encoder | 6 layers, 3 levels, 8 points, dim 512, FFN 1024 | §4.2.4 binsformer_swinl_22k_w7_nyu.py | Paper says "a simple deformable encoder" with no layer count |
| Positional encoding | sine, 256 features, normalised | binsformer_swinl_22k_w7_nyu.py | Not stated in paper |
| Decoder layers | 9 in total, 3 per scale | §4.2.4 binsformer_swinl_22k_w7_nyu.py | Paper says L = 3 per scale and S = 3 |
| Decoder width, heads, FFN | 512, 8 heads, FFN 2048 | binsformer_swinl_22k_w7_nyu.py [#L62-L63] [#L66] | Not stated in paper |
| Bin queries N | 64, plus 1 scene query | §4.2.4 tab. 6 binsformer_head.py | Paper's N = 64 choice from tab. 6 |
| Scale selection per layer | '%' by default: scale = layer index mod 3 | binsformer_swinl_22k_w7_nyu.py transformer.py | Paper describes L consecutive layers per scale; see Paper vs code |
| Depth range, NYU | d_min 1e-3, d_max 10 m | §1 binsformer_swinl_22k_w7_nyu.py | Paper states 0–10 m; d_min not stated in paper |
| Depth range, KITTI | d_min 1e-3, d_max 80 m | §1 binsformer_swinl_22k_w7_kitti.py | 0–80 m is stated in §1 |
| Scene classes | 25 for NYU; none for KITTI | §4.2.1 binsformer_head.py binsformer_swinl_22k_w7_kitti.py | Classes are NYU folder names §4.2.1 |
| Scale-invariant loss | α = 10, λ = 0.85 | §3.2.3 eq. 3 binsformer_swinl_22k_w7_nyu.py | Code fixes the mean term at 0.15 = 1 − λ sigloss.py |
| Scene loss weight μ | 1e-3 | §3.2.5 eq. 4 | Code uses 1e-2 binsformer_swinl_22k_w7_nyu.py; see Paper vs code |
| Auxiliary depth supervision | layers 3 and 6 with weights 1/4 and 1/2; final layer weight 1 | binsformer_swinl_22k_w7_nyu.py | Paper supervises every layer with w_s eq. 4; see Paper vs code |
| Optimizer | AdamW, β = (0.9, 0.999), weight decay 0.01 | §4.2.1 binsformer_swinl_22k_w7_nyu.py | Code excludes norm and position-embedding parameters from decay binsformer_swinl_22k_w7_nyu.py |
| Learning rate | 1e-4 | §4.2.1 binsformer_swinl_22k_w7_nyu.py | Peak rate in the code's OneCycle schedule |
| Batch size | 16 | §4.2.1 binsformer_swinl_22k_w7_nyu.py | Config has 2 per GPU; 8 GPUs implied by the paper's hardware §4.2.1 |
| Iterations | 38.4k (= 1600 × 24) | §4.2.1 binsformer_swinl_22k_w7_nyu.py | |
| Warm-up | linear over the first 30% of iterations | §4.2.1 | Code: 12,800 iterations, which is 33% of 38,400 binsformer_swinl_22k_w7_nyu.py |
| Decay | cosine annealing | §4.2.1 | Code uses OneCycle with div factor 25 and final div factor 100 binsformer_swinl_22k_w7_nyu.py; anneal type is set by mmcv, not checked here |
| Gradient clipping | max norm 35, L2 norm | Not stated in paper | binsformer_swinl_22k_w7_nyu.py |
| Hardware and time | 8 NVIDIA V100 32 GB, about 5 hours | §4.2.1 | Author-reported |
| NYU training crop | 416 × 544 random crop; rotation ±2.5° with p = 0.5; flip p = 0.5; colour jitter p = 0.5 | Not stated in paper | binsformer_swinl_22k_w7_nyu.py |
| NYU test | Eigen centre crop; input 480 × 640; horizontal-flip averaging | §4.1.1 binsformer_swinl_22k_w7_nyu.py | Flip averaging is not in the paper; see Pitfalls |
| KITTI training crop | Garg crop, KB crop, random crop 352 × 704 | §4.1.1 binsformer_swinl_22k_w7_kitti.py [#L133] | Garg crop is named in §4.1.1 |
| Metrics | δ1, δ2, δ3 (threshold accuracy); AbsRel; SqRel; RMSE; RMS log; log10 | §4.1.2 | KITTI online benchmark uses SILog, absErrorRel, sqErrorRel, iRMSE §4.1.2 |
Results
Author-reported. Setup: NYU Depth v2 with the listed backbones, evaluated with the pre-defined Eigen centre crop §4.1.1 tab. 3; KITTI Eigen split and the official online benchmark §4.1.1 tab. 1 tab. 2; SUN RGB-D, 5050 test images, evaluated with NYU-trained models without fine-tuning §4.1.1 tab. 4. In tab. 1 † marks ImageNet-22K pre-training and ‡ marks pre-training on an auxiliary depth dataset. The same markers appear in tab. 3, whose caption does not define them.
Headline numbers. On NYU with Swin-Large†, δ1 is 0.925, REL 0.094 and RMS 0.330 tab. 3, against 0.903, 0.103 and 0.364 for AdaBins tab. 3. On KITTI Eigen with Swin-Large†, δ1 is 0.974, REL 0.052 and RMS 2.098 tab. 1, against 0.964, 0.058 and 2.360 for AdaBins tab. 1. On the KITTI online benchmark, SILog is 10.14 against 10.80 for ViP-DeepLab, which the paper reports as a 6.1% improvement tab. 2 §4.3.1. Cross-dataset, δ1 on SUN RGB-D is 0.805 with Swin-Large† and 0.771 for AdaBins tab. 4.
tab. 1 KITTI, Eigen split, depth range 0–80 m. Higher δ is better; lower error is better.
| Method | Ref | Backbone | δ1 | δ2 | δ3 | REL | Sq-rel | RMS | RMS log |
|---|---|---|---|---|---|---|---|---|---|
| Godard et al. | CVPR 2017 | ResNet-50 | 0.861 | 0.949 | 0.976 | 0.114 | 0.898 | 4.935 | 0.206 |
| Johnston et al. | CVPR 2020 | ResNet-101 | 0.889 | 0.962 | 0.982 | 0.106 | 0.861 | 4.699 | 0.185 |
| Gan et al. | ECCV 2018 | ResNet-101 | 0.890 | 0.964 | 0.985 | 0.098 | 0.666 | 3.933 | 0.173 |
| DORN | CVPR 2018 | ResNet-101 | 0.932 | 0.984 | 0.994 | 0.072 | 0.307 | 2.727 | 0.120 |
| Yin et al. | ICCV 2019 | ResNeXt-101 | 0.938 | 0.990 | 0.998 | 0.072 | -- | 3.258 | 0.117 |
| PGA-Net | TPAMI 2020 | ResNet-50 | 0.952 | 0.992 | 0.998 | 0.063 | 0.267 | 2.634 | 0.101 |
| BTS | arXiv 2019 | DenseNet-161 | 0.956 | 0.993 | 0.998 | 0.059 | 0.245 | 2.756 | 0.096 |
| TransDepth | ICCV 2021 | ResNet-50+ViT-B† | 0.956 | 0.994 | 0.999 | 0.064 | 0.252 | 2.755 | 0.098 |
| DPT | ICCV 2021 | ResNet-50+ViT-B‡ | 0.959 | 0.995 | 0.999 | 0.062 | -- | 2.573 | 0.092 |
| AdaBins | CVPR 2021 | E-B5+mini-ViT | 0.964 | 0.995 | 0.999 | 0.058 | 0.190 | 2.360 | 0.088 |
| BinsFormer (this paper) | -- | ResNet-18 | 0.954 | 0.994 | 0.999 | 0.065 | 0.230 | 2.574 | 0.099 |
| BinsFormer (this paper) | -- | ResNet-50 | 0.962 | 0.994 | 0.999 | 0.061 | 0.208 | 2.426 | 0.093 |
| BinsFormer (this paper) | -- | Swin-Tiny | 0.968 | 0.995 | 0.999 | 0.058 | 0.183 | 2.286 | 0.088 |
| BinsFormer (this paper) | -- | Swin-Base | 0.970 | 0.996 | 0.999 | 0.056 | 0.172 | 2.248 | 0.085 |
| BinsFormer (this paper) | -- | Swin-Base† | 0.974 | 0.997 | 0.999 | 0.053 | 0.156 | 2.141 | 0.080 |
| BinsFormer (this paper) | -- | Swin-Large† | 0.974 | 0.997 | 0.999 | 0.052 | 0.151 | 2.098 | 0.079 |
tab. 2 KITTI online depth benchmark, test set. Lower is better. Numbers are from the benchmark website.
| 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 |
| BinsFormer (this paper) | 10.14 | 1.69 | 8.23 | 10.90 |
The backbone and configuration used for this row are not stated in the caption tab. 2.
tab. 3 NYU Depth v2. Higher δ is better; lower error is better.
| Method | Encoder | δ1 | δ2 | δ3 | REL | RMS | log10 |
|---|---|---|---|---|---|---|---|
| DORN | ResNet-101 | 0.828 | 0.965 | 0.992 | 0.115 | 0.509 | 0.051 |
| Yin et al. | ResNeXt-101 | 0.875 | 0.976 | 0.994 | 0.108 | 0.416 | 0.048 |
| BTS | DenseNet-161 | 0.885 | 0.978 | 0.994 | 0.110 | 0.392 | 0.047 |
| DAV | DRN-D-22 | 0.882 | 0.980 | 0.996 | 0.108 | 0.412 | -- |
| TransDepth | ResNet-50+ViT-B† | 0.900 | 0.983 | 0.996 | 0.106 | 0.365 | 0.045 |
| DPT | ResNet-50+ViT-B‡ | 0.904 | 0.988 | 0.998 | 0.110 | 0.357 | 0.045 |
| AdaBins | E-B5+Mini-ViT | 0.903 | 0.984 | 0.997 | 0.103 | 0.364 | 0.044 |
| BinsFormer (this paper) | ResNet-18 | 0.866 | 0.976 | 0.994 | 0.122 | 0.410 | 0.050 |
| BinsFormer (this paper) | ResNet-50 | 0.882 | 0.978 | 0.995 | 0.111 | 0.390 | 0.047 |
| BinsFormer (this paper) | Swin-Tiny | 0.890 | 0.983 | 0.996 | 0.113 | 0.379 | 0.047 |
| BinsFormer (this paper) | Swin-Base | 0.902 | 0.984 | 0.996 | 0.104 | 0.362 | 0.044 |
| BinsFormer (this paper) | Swin-Base† | 0.917 | 0.988 | 0.997 | 0.098 | 0.340 | 0.041 |
| BinsFormer (this paper) | Swin-Large† | 0.925 | 0.989 | 0.997 | 0.094 | 0.330 | 0.040 |
tab. 4 Cross-dataset: trained on NYU Depth v2, tested on SUN RGB-D without fine-tuning.
| Method | Encoder | δ1 | δ2 | δ3 | REL | RMS | log10 |
|---|---|---|---|---|---|---|---|
| Chen et al. | SENet | 0.757 | 0.943 | 0.984 | 0.166 | 0.494 | 0.071 |
| Yin et al. | ResNeXt-101 | 0.696 | 0.912 | 0.973 | 0.183 | 0.541 | 0.082 |
| BTS | DenseNet-161 | 0.740 | 0.933 | 0.980 | 0.172 | 0.515 | 0.075 |
| AdaBins | E-B5+Mini-ViT | 0.771 | 0.944 | 0.983 | 0.159 | 0.476 | 0.068 |
| BinsFormer (this paper) | ResNet-18 | 0.738 | 0.935 | 0.982 | 0.175 | 0.504 | 0.074 |
| BinsFormer (this paper) | Swin-Tiny | 0.760 | 0.945 | 0.985 | 0.162 | 0.478 | 0.069 |
| BinsFormer (this paper) | Swin-Large† | 0.805 | 0.963 | 0.990 | 0.143 | 0.421 | 0.061 |
tab. 5 NYU ablation of components. δ1 higher is better; REL and RMS lower is better. The backbone is not stated in the caption. Check marks are as in the table.
| Method | Cls.-Reg. | Ada. Bins | Bins Query | Aux. Info. | Multi-S. | δ1 | REL | RMS |
|---|---|---|---|---|---|---|---|---|
| Reg. Baseline | 0.852 | 0.130 | 0.422 | |||||
| Reg. Baseline+ | ✓ | 0.870 | 0.123 | 0.403 | ||||
| Fix UD | ✓ | 0.851 | 0.130 | 0.424 | ||||
| Fix SID | ✓ | 0.825 | 0.145 | 0.453 | ||||
| AdaBins | ✓ | ✓ | ✓ | 0.850 | 0.136 | 0.434 | ||
| BinsFormer | ✓ | ✓ | ✓ | 0.878 | 0.116 | 0.397 | ||
| BinsFormer | ✓ | ✓ | ✓ | ✓ | 0.882 | 0.115 | 0.388 | |
| BinsFormer | ✓ | ✓ | ✓ | ✓ | ✓ | 0.890 | 0.113 | 0.379 |
tab. 6 NYU: number of bins N. δ1 to δ3 higher is better; REL, RMS and log10 lower is better. The text says the gain saturates above N = 64, which the table shows as the default.
| N | δ1 | δ2 | δ3 | REL | RMS | log10 |
|---|---|---|---|---|---|---|
| 1 | Not converge | |||||
| 8 | 0.889 | 0.981 | 0.995 | 0.115 | 0.390 | 0.048 |
| 16 | 0.887 | 0.981 | 0.995 | 0.113 | 0.384 | 0.048 |
| 32 | 0.889 | 0.982 | 0.995 | 0.114 | 0.380 | 0.047 |
| 64 (default) | 0.890 | 0.983 | 0.996 | 0.113 | 0.379 | 0.047 |
| 128 | 0.889 | 0.982 | 0.994 | 0.112 | 0.380 | 0.046 |
| 256 | 0.886 | 0.980 | 0.995 | 0.115 | 0.383 | 0.048 |
| 512 | 0.883 | 0.977 | 0.992 | 0.119 | 0.393 | 0.050 |
tab. 7 NYU: multi-scale refinement. Scales used and total decoder layers.
| Feature scales | Layers | δ1 | δ2 | δ3 | REL | RMS | log10 |
|---|---|---|---|---|---|---|---|
| f4 | 3 | 0.882 | 0.980 | 0.995 | 0.115 | 0.388 | 0.048 |
| f3, f4 | 6 | 0.888 | 0.982 | 0.995 | 0.113 | 0.380 | 0.047 |
| f2, f3, f4 (default) | 9 | 0.890 | 0.983 | 0.996 | 0.113 | 0.379 | 0.047 |
| f1, f2, f3, f4 | 12 | 0.881 | 0.979 | 0.994 | 0.118 | 0.392 | 0.049 |
Figure-based claims in the paper, such as the uncertainty trend and the query visualisations, are described in words in §4.4.1 and fig. 5, and not reproduced here.
Paper vs code
Official code: github.com/zhyever/Monocular-Depth-Estimation-Toolbox, at commit d8aff50e75c4b0c183361c7690959d0269b45a9d. The paper's abstract and its footnote link this repository, so it is taken as the official code. Its LICENSE file is Apache-2.0 and carries an MMSegmentation copyright header, since the toolbox builds on that framework. No code is quoted in this card.
- Scale order. The paper runs the L = 3 layers of each scale one after
another §3.2.5 §4.2.4. The code's default maps layer i to scale i mod 3,
so the scale changes at every layer transformer.py.
The NYU and KITTI Swin-Large configs do not set
operation, so the code uses this default binsformer_swinl_22k_w7_nyu.py. The other option,//, groups the layers by scale as the paper describes transformer.py. Its use in the reported results is not stated. - Query initialisation. The paper zero-initialises the queries and gives them learnable positional embeddings §3.2.5. The code uses learnable query features, which are Xavier-initialised, and learnable query positions binsformer_head.py binsformer_head.py binsformer_head.py.
- Scene loss weight. The paper gives μ = 1e-3 eq. 4. The Swin config sets the scene loss weight to 1e-2 binsformer_swinl_22k_w7_nyu.py. The head's own default is 1e-1 binsformer_head.py.
- Which layers get supervision and how they are weighted. The paper applies both loss terms to every layer, weighted by w_s eq. 4 §3.2.5. The code supervises the depth at the 3rd and 6th layers (0-based indices 2 and 5) with weights 1/4 and 1/2, and the final layer with weight 1 binsformer_swinl_22k_w7_nyu.py binsformer_head.py. The scene loss on the auxiliary layers is added without the aux weight binsformer_head.py. The main-layer scene loss is also unweighted binsformer_head.py.
- Scale weights. The paper writes w_s = {1/2^s, ..., 1} §3.2.5. The code's values 1/4, 1/2, 1 are consistent with the reading 1/2^(S−s) for S = 3. This reading is my inference, since the paper's formula is ambiguous.
- SI loss normalisation. The paper writes the 1/T and λ/T² form of eq. 3 eq. 3. The code computes the unbiased variance of g (torch.var) plus 0.15 times the squared mean sigloss.py. The constant 0.15 is 1 − λ with λ = 0.85. The code's ε = 1e-3 inside the logs is not in the paper sigloss.py sigloss.py.
- Valid-pixel mask. The code's mask is target > 0 only, with no upper depth bound, because the config does not pass
max_depthto the loss sigloss.py binsformer_swinl_22k_w7_nyu.py. The paper says "valid" ground truth §3.2.3 without a definition. - Depth bounds. The paper uses the dataset's minimum and maximum valid depth §3.2.3. The code uses a fixed 1e-3 and 10 m (NYU) or 80 m (KITTI) binsformer_swinl_22k_w7_nyu.py binsformer_swinl_22k_w7_kitti.py.
- Warm-up and schedule. The paper gives 30% linear warm-up and cosine decay §4.2.1. The code's warm-up is 12,800 iterations, which is 33%, under a OneCycle schedule binsformer_swinl_22k_w7_nyu.py.
- Dataset sizes. The paper says about 50K NYU pairs §4.1.1. The repository's NYU training list has 24,230 lines nyu_train.txt. The paper says about 26K KITTI Eigen training images §4.1.1. The repository list has 23,157 lines kitti_eigen_train.txt. The test lists have 653 NYU and 696 KITTI lines nyu_test.txt kitti_eigen_test.txt. The paper gives 697 KITTI test frames.
- Test-time flip. The paper does not mention test-time augmentation. The NYU test pipeline sets flip = True binsformer_swinl_22k_w7_nyu.py. The model's
aug_testaverages the predictions over its augmented inputs encoder_decoder.py. Whether the paper's numbers use this is not stated. - Missing configs. The paper's table rows for ResNet-18/50, Swin-Base and Swin-Base† have no config in configs/binsformer/. Only Swin-Tiny and Swin-Large configs exist there, for NYU, KITTI and NYU-to-SUN. No BinsFormer config is present for the KITTI online benchmark, and none for the ablations .
- Consistent items. The 25 scene classes §4.2.1 are in the code too. Chamfer loss is off in the configs binsformer_swinl_22k_w7_nyu.py, which matches the paper's method description. No discrepancy found there.
Pitfalls
- Layer-to-scale mapping is ambiguous. The paper's description gives consecutive layers per scale, while the released default cycles through scales every layer. Choose one and state it. The code's configs use the cycling default.
- Under the cycling default, all three supervised layers see the finest scale. The supervised layers are the 3rd, 6th and 9th (0-based indices 2, 5 and 8). Under the modulo rule all three map to scale index 2 transformer.py. So the depth losses here act on the finest features only.
- Eq. 3 can go numerically negative. The paper's form subtracts two large terms. The code's variance form cannot yield a negative square-root argument, because the variance is non-negative sigloss.py. Implement the variance form, or clamp the argument.
- ε in the log. The loss takes log(depth + 1e-3), so predictions near zero get a fixed offset in log space sigloss.py.
- Bin normalisation is a no-op in exact arithmetic. The code normalises the softmax bin lengths again so they sum to one binsformer_head.py. Harmless, but it is an extra step not in the paper.
- Scene loss with batch size 1. The cross-entropy calls
input.squeeze(), which removes the batch axis when the batch size is 1 celoss.py. Keep the batch size above 1, or fix the squeeze. - Queries are learned, not zero. Implementers following the paper's zero-initialisation note will diverge from the code's learned queries §3.2.5 binsformer_head.py.
- Scene loss weight differs by a factor of ten. The paper's μ = 1e-3 and the config's 1e-2 give different training objectives. Results in the paper are not stated to use either §3.2.5 binsformer_swinl_22k_w7_nyu.py.
- Uncertainty is only described. The paper says uncertainty is computed by maximum likelihood "following" a cited work §4.4.1. No formula or code path for it is given here.
- Costs. Nine decoder layers over three scales, a six-layer deformable encoder and a Swin-Large backbone, trained at batch 16 for 38.4k iterations on eight V100s, about five hours by the paper's account §4.2.1 binsformer_swinl_22k_w7_nyu.py binsformer_swinl_22k_w7_nyu.py. The paper does not give the cost of the ResNet or Swin-Tiny variants.
- Unstated values to take from the code. Pixel-decoder width, encoder depth and width, positional encoding, decoder width and heads, crop and colour augmentation, gradient clipping and weight-decay exclusions are not in the paper. The code is the only source for them.
- Reported numbers. All tables are author-reported. The KITTI benchmark row's configuration is not stated tab. 2, and the ablation backbone is not stated tab. 5.
Lineage
- Builds on: AdaBins, whose adaptive bins and chamfer loss the paper revisits §1 §3.2.4. The Transformer decoder and set-to-set framing follow DETR §1 §3.2.2. The light FPN and the multi-scale deformable encoder follow MaskFormer, Mask2Former and deformable DETR §4.2.3 §4.2.4. The scale-invariant loss follows Eigen et al. §3.2.3.
- Compared against: per-pixel regression and classification methods, including DORN, BTS, DAV, TransDepth and DPT on NYU and KITTI tab. 1 tab. 3; Godard et al., Johnston et al., Gan et al., Yin et al. and PGA-Net on KITTI tab. 1; BANet, PWA and ViP-DeepLab on the KITTI benchmark tab. 2; and Chen et al. on SUN RGB-D tab. 4.
Source and license
Adapted from “BinsFormer: Revisiting Adaptive Bins for Monocular Depth Estimation” by Zhenyu Li, Xuyang Wang, Xianming Liu, Junjun Jiang (arXiv:2204.00987), 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.