wikillm

Paper · 2023-08-27 · cs.CV

MB-TaylorFormer: Multi-branch Efficient Transformer Expanded by Taylor Formula for Image Dehazing

Transformer for single-image dehazing. Softmax attention becomes a first-order Taylor form that costs linear time in pixel count; a per-head sigmoid gate (MSAR) corrects the error, and patch embedding stacks depthwise deformable convolutions in branches. Author-reported: 40.71 dB PSNR on SOTS-Indoor (base, 2.68M parameters), 42.64 dB (large).

Linear attentionDeformable convolutionDepthwise separable convolutionVision Transformer (ViT) backbonesdehazingimage-restorationvision-transformerlinear-attention

arXivPDFCodeMarkdown14 min read

AI-compiled by claude-haiku-5-5 on 2026-11-05, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Dehazing removes the haze from a photo so the scene looks clear. Transformers handle this well because every pixel can look at the whole image, but the standard attention step compares every pixel with every other one, so its cost grows very fast as the image gets bigger. This paper rewrites that step so the work grows in a straight line with the number of pixels, and adds a small learned correction for the error the rewrite introduces.

The first stage of the network also looks at the image through several paths at once. Each path uses a different window size and a different, flexible sampling shape, so the model gets both coarse and fine views of the same region. The authors report that this design dehazes several benchmarks with strong scores while staying light.

TL;DR

MB-TaylorFormer is a U-Net-shaped Transformer for single-image dehazing. Its attention uses a first-order Taylor expansion of softmax, so cost is linear in the number of pixels, and a per-head gate corrects the error of that expansion. Patch embedding stacks depthwise deformable convolutions in several branches. Author-reported: 40.71 dB PSNR on SOTS-Indoor for the base model and 42.64 dB for the large model tab. 1. The paper alone leaves several details open; the official code fills some of them and adds a learned per-head scale that the equations omit.

Problem

  • Softmax attention costs time quadratic in the number of positions, which limits its use on high-resolution dehazing inputs §1 eq. 5 §3.3.
  • Window-restricted attention lowers cost but shortens the receptive field §1.
  • Fixed-kernel patch embedding produces tokens of one scale only §1 §3.2.
  • Earlier linear-attention methods approximate the softmax kernel with feature maps. This paper instead expands softmax itself, to keep the value approximation close to vanilla attention §2 §1.

Method

The network takes a hazy image and predicts a residual that is added back to the input §3.1. Its parts, in order:

  1. Backbone §3.1 fig. 2. A 3×3 convolution extracts shallow features. A four-level encoder–decoder follows. Each level applies multi-scale patch embedding, then several Transformer branches, then SKFF fusion of the branches §3.1. Downsampling uses pixel-unshuffle and upsampling uses pixel-shuffle §3.1. Skip connections are concatenated and reduced with a 1×1 convolution, except at the first level §3.1. A refinement stage follows the decoder; the paper describes it as a residual block, but the code uses a Transformer stage (see Paper vs code) §3.1. A final 3×3 convolution outputs a residual R, and the restored image is I' = I + R §3.1. Depthwise separable convolutions are used throughout §3.1.
  2. Multi-scale patch embedding §3.2 fig. 3. Each path is a depthwise separable deformable convolution (DSDCN): a depthwise deformable 3×3 layer followed by a pointwise layer. Offsets come from a depthwise 3×3 and a pointwise convolution. Layers are stacked, not placed side by side, so each deeper path adds semantic depth §3.2. Each deformable layer is followed by Hardswish §3.2. The offsets are truncated to [−3, 3], which gives a receptive field from 1×1 up to 9×9 §3.2 fig. 4. Cost and parameter counts of DSDCN versus a standard DCN are given in eq. 1–eq. 4.
  3. Taylor-expanded multi-head self-attention §3.3. The paper expands exp(QᵀK/√D) to first order and writes the attention as 1 + Q̃ᵀK̃ eq. 7–eq. 8. Every query and key vector is scaled to norm 0.5 so that the expansion stays in the range [−0.25, 0.25] where the first-order form is accurate §3.3 fig. 5. Matrix-product associativity then gives a form whose cost is linear in the number of positions eq. 9. Q, K and V come from a 1×1 convolution followed by a depthwise 3×3 convolution §3.3. The number of heads increases from the top level to the bottom §3.3. Cost of standard MSA is eq. 10; cost of T-MSA is eq. 11, and the paper assumes h×w is much larger than D §3.3.
  4. Multi-scale attention refinement (MSAR) §3.4. The remainder of the first-order expansion is not modelled. MSAR corrects it with a gate per head: the spatially concatenated normalised Q and K of each head pass through a grouped convolution whose kernel sizes depend on the head count, then a sigmoid eq. 12. The head output is multiplied by this gate, projected with W^P, and added to the block input eq. 13 §3.4. The gate has one channel per head rather than one per channel, which the authors chose for cost tab. 3.

Pseudocode for the attention with the MSAR gate, written from the equations and checked against the official code. The per-head scale on the last steps is in the code but not in the paper.

Pseudocode
# Taylor-expanded attention with MSAR gate  [eq. 9] [eq. 12] [eq. 13]
# Input:  x (B, N, D), N = H * W, D = heads * d
# Output: y (B, N, D)

def taylor_msar_attention(x, heads, d):
    # Q, K, V: 1x1 conv, then depthwise 3x3 conv  [§3.3]
    # [code: basicsr/models/archs/MB_TaylorFormer.py#L208]
    queries, keys, values = project_qkv(x)  # each (B, heads, N, d)

    # Scale every query and key vector to norm 0.5  [§3.3] [eq. 8]
    # [code: basicsr/models/archs/MB_TaylorFormer.py#L215-L219]
    queries = 0.5 * queries / norm(queries, over=d)
    keys = 0.5 * keys / norm(keys, over=d)

    # MSAR gate: per-head grouped conv over [queries, keys], then sigmoid
    # [eq. 12] [code: basicsr/models/archs/MB_TaylorFormer.py#L222-L224]
    gate = sigmoid(grouped_conv(concat(queries, keys)))  # (B, heads, N, 1)

    # Sums shared by all queries; no N x N matrix is formed  [eq. 9]
    # [code: basicsr/models/archs/MB_TaylorFormer.py#L225-L231]
    value_sum = sum(values, over=N)                 # (B, heads, 1, d)
    key_value = transpose(keys) @ values            # (B, heads, d, d)
    key_sum = sum(keys, over=N)                     # (B, heads, 1, d)

    # First-order Taylor form: numerator over denominator  [eq. 9]
    numerator = value_sum + queries @ key_value     # (B, heads, N, d)
    denominator = N + queries @ transpose(key_sum)  # (B, heads, N, 1)
    attended = numerator / (denominator + 1e-6)

    # Learned per-head scale, initialised to 1; not in the equations
    # [code: basicsr/models/archs/MB_TaylorFormer.py#L176] [#L234]
    attended = attended * temperature

    # Apply the gate, merge heads, project  [eq. 13]
    # [code: basicsr/models/archs/MB_TaylorFormer.py#L235-L238]
    attended = attended * gate
    return project_out(merge_heads(attended))

The block adds this output to its input, then applies a feed-forward network with a residual connection §3.3 MB_TaylorFormer.py. The paper does not describe the feed-forward network. The code uses a GELU-gated design MB_TaylorFormer.py.

Pseudocode
# One encoder or decoder stage  [§3.1]
# Input:  x (B, C, H, W)
# Output: y (B, C, H, W)

def stage(x, num_blocks):
    # Stacked DSDCN layers; each branch takes one layer's output  [§3.2]
    # [code: basicsr/models/archs/MB_TaylorFormer.py#L644-L651]
    branch_inputs = multi_scale_patch_embed(x)  # list of (B, C, H, W)

    # Each branch runs its own stack of Transformer blocks  [§3.1]
    # [code: basicsr/models/archs/MB_TaylorFormer.py#L287-L298]
    branch_outputs = []
    for tokens in branch_inputs:
        for block_index in range(num_blocks):
            tokens = tokens + attention(norm(tokens))  # see above
            tokens = tokens + feed_forward(norm(tokens))
        branch_outputs.append(tokens)

    # Fuse branches with selective-kernel attention (SKFF)  [§3.1]
    # [code: basicsr/models/archs/MB_TaylorFormer.py#L467-L502]
    fused = skff(branch_outputs)

    # Stage residual  [code: basicsr/models/archs/MB_TaylorFormer.py#L828]
    return fused + x

Hyperparameters

Paper values come first; code values are from the two shipped configs (Dehazing/Options/MB-TaylorFormer-B.yml and -L.yml), which are identical where not noted.

NameValueWhereNotes
Model variantsB and L§4.1Parameter and MAC counts in tab. 1
Channels per level[24, 48, 72, 96]MB-TaylorFormer-B.ymlNot stated in the paper text
Transformer blocks per levelB: [2, 3, 3, 4]; L: [4, 6, 6, 8]MB-TaylorFormer-B.yml MB-TaylorFormer-L.ymlNot stated in the paper text
Refinement blocksB: 2; L: 4MB-TaylorFormer-B.yml MB-TaylorFormer-L.ymlNot stated in the paper text
Heads per level[1, 2, 4, 8]MB-TaylorFormer-B.ymlHead count sets the MSAR kernel sizes (see Pitfalls)
Branches per levelB: [2, 2, 2, 2]; L: [2, 3, 3, 3]MB-TaylorFormer-B.yml MB-TaylorFormer-L.ymlPaper describes three branches §3.2
Feed-forward expansion2.66MB-TaylorFormer-B.ymlNot stated in the paper text
Bias in convolutionsFalseMB-TaylorFormer-B.ymlNot stated in the paper text
Q/K norm after scaling0.5§3.3 MB-TaylorFormer-B.ymlPaper: "normalizing the norm to 0.5"
Offset truncation[−3, 3]§3.2 MB-TaylorFormer-B.yml
Training patch size256 × 256§4.4 MB-TaylorFormer-B.ymlPaper states it for the ablations; code uses it for both variants
Batch size1 per GPU, 8 GPUsMB-TaylorFormer-B.yml MB-TaylorFormer-B.ymlPaper does not state a batch size
Training length500,000 iterationsMB-TaylorFormer-B.ymlPaper: "epoch is set as 500" for ablations §4.4; main-run length not stated
OptimizerAdamW, β = (0.9, 0.999)MB-TaylorFormer-B.ymlNot stated in the paper text
Weight decay1e-4MB-TaylorFormer-B.ymlNot stated in the paper text
Initial learning rate2e-4§4.1 MB-TaylorFormer-B.yml
LR schedule200k iters at 2e-4; then 300k iters, cosine to 1e-5§4.1 MB-TaylorFormer-B.ymlPaper: cosine to 1e-6 §4.1; code differs (see Paper vs code)
Gradient clippingclip_grad_norm 0.01image_restoration_model.pyNot stated in the paper text
LossL1, weight 1§4.1 MB-TaylorFormer-B.yml
Augmentationrandom crop and flipping§4.1Code also uses 90° rotations (see Paper vs code)
Pretrained init (B config)author-local pathMB-TaylorFormer-B.ymlNot usable outside the authors' machine
Test paddingreflect-pad to a multiple of 8, then croptest.pyNot stated in the paper text
Test metricsPSNR and SSIM on output clamped to [0, 1]§4.2 test.py

Datasets §4.1: synthetic RESIDE subsets (ITS, OTS; evaluated on SOTS) and the real O-HAZE and Dense-Haze sets. The real sets have 45 and 55 pairs; the paper uses the last 5 of each as test images and the rest for training §4.1.

Results

Author-reported. Setup: the caption of fig. 1 says all models are trained on SOTS-Indoor. The shipped configs train on the ITS training split and validate on ITS/SOTS MB-TaylorFormer-B.yml MB-TaylorFormer-B.yml. The paper does not state the training set for each row of tab. 1. Baselines are the methods in tab. 1; MACs are reported without an input resolution.

Table 1 tab. 1, full, as in the source (best per column in bold and second best underlined in the paper; the formatting is dropped here):

MethodSOTS-Indoor PSNRSSIMSOTS-Outdoor PSNRSSIMO-HAZE PSNRSSIMDense-Haze PSNRSSIM#ParamMACs
DCP16.620.81819.130.81516.780.65312.720.442-0.6G
DehazeNet19.820.82124.750.92717.570.77013.840.4300.01M0.6G
GFN22.300.88021.550.84418.160.671--0.50M14.9G
GDN32.160.98430.860.98218.920.67214.960.5360.96M21.5G
PFDN32.680.976------11.27M51.5G
MSBDN33.670.98533.480.98224.360.74915.130.55531.35M41.54G
FFA-Net36.390.98933.570.98422.120.77015.700.5494.46M287.8G
AECR-Net37.170.990----15.800.4662.61M52.2G
MAXIM-2S38.110.99134.190.985----14.10M216.0G
SGID-PFF38.520.99130.200.97520.960.74112.490.51713.87M156.4G
Restormer38.880.991--23.580.76815.780.54826.10M141.0G
Dehamer36.630.98835.180.98625.110.77716.620.560132.50M60.3G
MB-TaylorFormer-B (Ours)40.710.99237.420.98925.050.78816.660.5602.68M38.5G
MB-TaylorFormer-L (Ours)42.640.99438.090.99125.310.78216.440.5667.43M88.1G

Headline results, from the text §4.2 §4.3:

  • SOTS-Indoor: B gains 2.19 dB over SGID-PFF; L gains 4.12 dB tab. 1.
  • SOTS-Outdoor: L is 2.91 dB above Dehamer tab. 1.
  • O-HAZE: best PSNR is 0.20 dB above Dehamer; Dense-Haze, 0.04 dB above it tab. 1.

Ablations, all on SOTS-Indoor with the B model §4.4:

Table 2 (multi-scale patch embedding, tab. 2):

PathsOperator used in patch embeddingPSNRSSIM#ParamsMACs
1plain convolution38.270.9912.655M33.63G
2two plain convolutions, side by side38.420.9912.652M37.89G
2two dilated convolutions, side by side38.770.9912.652M37.89G
2two plain convolutions, stacked39.040.9922.652M37.89G
2DSDCN layers, stacked40.710.9922.677M38.51G

Table 3 (MSAR, tab. 4):

MethodsPSNRSSIM#ParamsMACs
MB-TaylorFormer-B40.710.9922.677M38.51G
W/o MSAR38.740.9902.582M37.60G
Gate per channel, G ∈ R^(h×C×H×W)40.880.9934.288M68.43G

Table 4 (replacing T-MSA with other linear attention, tab. 5):

MethodsPSNRSSIM#ParamsMACs
MB-TaylorFormer-B40.710.9922.677M38.51G
W/o MSAR38.740.9902.582M37.60G
T-MSA → MDTA38.570.9912.582M35.20G
T-MSA → Swin36.590.9882.517M36.38G
T-MSA → TAR36.740.9872.517M34.00G
T-MSA → PVTv238.100.99010.89M38.60G
T-MSA → Cswin38.190.9873.30M40.10G
T-MSA → LinFormer36.120.98348.70M371.68G

Table 5 (approximation order, tab. 7):

MethodsPSNRSSIM#ParamsMACs
Swin36.590.9882.517M36.38G
Swin + T-MSA-2nd36.500.9882.517M36.38G
Swin + T-MSA-1st36.370.9872.517M36.38G

Generalisation §4.5, trained and tested as in the cited works:

Table 6, snow removal on CSD tab. 6:

MethodPSNRSSIM#ParamMACs
DesnowNet20.130.8126.15M1.7KG
CycleGAN20.980.807.84M42.4G
All in One26.310.8744.00M12.3G
HDCW-Net29.060.916.99M9.8G
TKL33.890.9631.35M41.6G
SMGARN31.930.956.86M450.3G
Uformer33.800.969.03M19.8G
Restormer35.430.9726.10M141.0G
MB-TaylorFormer-B (Ours)37.100.982.68M38.5G

Table 7, rain removal on RainCityscapes tab. 7:

MethodRESCANDAFNetPCNetEPRRNetUformerRestormerOurs (B)
PSNR28.9730.0624.4931.1132.2634.3736.55
SSIM0.8850.9530.9460.9740.9810.9880.990
#Params0.15M-0.63M137.10M9.03M26.10M2.68M
MACs9.7G-2.4G182.2G19.8G141.0G38.5G

Qualitative results are in fig. 6 (synthetic) and fig. 7 (real). The feature-map comparison of single-scale and multi-scale tokens is fig. 8.

Paper vs code

Official code: FVL2020/ICCV-2023-MB-TaylorFormer, commit c504250a45a91cefb20c9ee706df0a834e62beb0. The paper's abstract links it. The owner is a user account, not an organisation; the README lists the six authors and their university contact addresses. The repository has no LICENSE file, so its code is cited by path and line only, with no quoted snippets. The README points to a later V2 (arXiv:2501.04486); that paper is not covered here.

  • Learning-rate schedule. Paper: start 2e-4, cosine to 1e-6 §4.1. Config values: 2e-4 held for 200k iterations, then cosine from 2e-4 to 1e-5 over 300k iterations MB-TaylorFormer-B.yml. The comments in the same file say 3e-4 with a 92k/208k split and a final value of 1e-6 MB-TaylorFormer-B.yml; the numbers do not match the comments.
  • Training length. Paper: "epoch is set as 500" for ablations §4.4. Config: 500,000 iterations MB-TaylorFormer-B.yml.
  • Branch count. Paper: three branches, with receptive-field ranges ordered x ≤ y ≤ z §3.2. B config uses two per level; L uses three at levels 2–4 and two at level 1 MB-TaylorFormer-B.yml MB-TaylorFormer-L.yml. The code has no x ≤ y ≤ z constraint; it only clamps the offsets MB_TaylorFormer.py.
  • Per-head temperature. Not in equations 9 or 13. The code multiplies each head's output by a learned scalar initialised to 1 MB_TaylorFormer.py MB_TaylorFormer.py.
  • Refinement stage. Paper: "a residual block" after the encoder–decoder §3.1. Code: a Transformer refinement stage with its own patch embedding MB_TaylorFormer.py MB_TaylorFormer.py. A ResBlock class exists but is not used by the model MB_TaylorFormer.py (its only other reference is commented out, #L394).
  • Normalisation type. Config sets LayerNorm_type: WithBias MB-TaylorFormer-B.yml. The model passes 'BiasFree' to every stage, so the config value is ignored MB_TaylorFormer.py (same pattern at other levels).
  • Augmentation. Paper: random cropping and flipping §4.1. Code: one of eight flip/rotation variants, applied to both images transforms.py paired_image_dataset.py.
  • Gradient clipping. Not in the paper. Code clips the global norm at 0.01 image_restoration_model.py.
  • Feed-forward network. Not described in the paper. Code: GELU-gated channel-expansion design MB_TaylorFormer.py.
  • Training data. The paper evaluates on OTS, O-HAZE and Dense-Haze §4.1. The repository ships only the two ITS configs ; it has no config or weights for the other datasets as far as the tree shows.
  • Pretrained model. B config initialises from an author-local path MB-TaylorFormer-B.yml; L config sets none MB-TaylorFormer-L.yml. Whether B trains from scratch depends on that file existing; not checked.
  • Supplementary. The paper defers the T-MSA pseudo-code and the MSAR details to supplementary material §3.3 §3.4, which is not in the LaTeX source and was not fetched.

Pitfalls

  • Only heads 1, 2, 4 and 8 work. The MSAR kernel sizes are a fixed table keyed on head count MB_TaylorFormer.py. Any other count leaves the variable undefined, so the model fails at build time. The paper does not mention this.
  • Denominators stay positive. After scaling, each Q̃ᵀK̃ lies in [−0.25, 0.25] (from the paper's stated range), so each term 1 + Q̃ᵀK̃ is at least 0.75 and the denominator is at least 0.75N. The code adds 1e-6 as a guard MB_TaylorFormer.py.
  • Scaling is per token. Queries are normalised across channels per token; keys are normalised across channels per token too. Normalising keys over the token axis instead would change the attention MB_TaylorFormer.py.
  • Gradient through clamp. Offsets are clamped with torch.clamp MB_TaylorFormer.py. Clamped offsets receive zero gradient, so a branch stuck at the limit stops learning its offset.
  • Level-1 skip concatenation. Level 1 concatenates an upsampled 24-channel map with the encoder's 24-channel map to feed a 48-channel patch embedding. This works only because the second level's channel count is twice the first level's MB_TaylorFormer.py MB_TaylorFormer.py. The code comments that no 1×1 reduction is used there.
  • Text versus table. The text says the B model reaches 0.994 SSIM on SOTS-Indoor §4.2; tab. 1 gives 0.992 for B and 0.994 for L.
  • Efficiency claim. The text says B uses "merely 10%" of SGID-PFF's parameters and "14%" of its computational cost §4.2. The table gives 2.68M against 13.87M (about 19%) and 38.5G against 156.4G (about 25%). These ratios are computed from tab. 1; the paper does not state them.
  • Approximation order. tab. 5 ranks the first-order variant lowest of the three, while the paper keeps it for cost §4.4. The table's "Swin" row has no softmax-attention reference, so the ordering does not show how far the first-order form is from softmax.
  • MACs have no stated input size. tab. 1 and the ablations report MACs without an input resolution, so cost comparisons are only as good as the common input the authors used, which is not stated.
  • Restart schedule. The second cosine phase starts from 2e-4 again with a lower floor. Use the config values, not the paper's 1e-6 floor, if you aim to reproduce the released runs.
  • Generalisation §4.5 uses CSD and RainCityscapes; the table shows the model only, not the training recipe for those tasks.

Lineage

  • Builds on: Restormer (arXiv:2111.09881), whose U-shaped layout the paper adopts §3 and whose channel-wise attention (MDTA) it compares against §2 tab. 4. Deformable convolution §3.2 and SKFF §3.1 are used as cited.
  • Compared against: the methods in tab. 1, including linear-attention variants MDTA, Swin, TAR, PVTv2, Cswin and LinFormer tab. 4, and kernel-based linear attention §2.

Source and license

Adapted from “MB-TaylorFormer: Multi-branch Efficient Transformer Expanded by Taylor Formula for Image Dehazing” by Yuwei Qiu, Kaihao Zhang, Chenxi Wang, Wenhan Luo, Hongdong Li, Zhi Jin (arXiv:2308.14036), 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/FVL2020/ICCV-2023-MB-TaylorFormer at commit c504250a45a9 (none (no LICENSE file in repository)). Any quoted code is shown under that license.