Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Let the kernel bend
An ordinary 3 × 3 kernel always samples a rigid square grid. Objects are not square: a bird’s wing, a tilted car, a curved road. A deformable convolution lets each of the nine sampling points shift by a small learned amount, decided separately at each position from the image itself, so the kernel can stretch along an object or rotate with it. Positions between pixels are read by blending the four nearest pixels.
Deformable convolutions improve detection and segmentation of objects in unusual poses and shapes, common in aerial imagery, driving scenes and robotic grasping. Deformable attention (E9-13) carries the idea into transformer detectors.
- 1. A deformable convolution learns…
- 2. Points between pixels are read by…
- 3. Offsets are predicted…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Output: y(p) = Σₙ w_n·x(p + gₙ + Δpₙ), where gₙ runs over the 3 × 3 grid and Δpₙ are learned offsets.
- Bilinear sampling: for the 2 × 2 image [[0, 1], [2, 3]], the value at (0.5, 0.5) is 1.5; at (0, 0.25) it is 0.25.
- Special cases:
- zero offsets give a standard convolution;
- offsets (d − 1)·gₙ give a dilation-d convolution;
- rotating the grid by θ gives a rotated filter.
- Offset prediction: a standard convolution outputs 2·k² channels: 18 offsets for 3 × 3, or 72 with 4 offset groups.
- DCNv2 (modulated): each tap is also multiplied by a learned mask mₙ ∈ [0, 1]; weights (2, 3) with masks (0.5, 0) contribute (1, 0).
- 1. Bilinear value at (0.5, 0.5) of [[0, 1], [2, 3]]:
- 2. Offset channels for a 3 × 3 deformable conv:
- 3. Offsets (d − 1)·grid give…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Deformable convolution in code
Exercise 1.
- With zero offsets the deformable convolution matched a standard 3 × 3 convolution at every interior position.
- With offsets equal to the grid it matched a dilation-2 convolution.
- An offset of (0.5, 0.5) averaged four pixels, as bilinear interpolation should.
Practice.
torchvision.ops.deform_conv2d(input, offset, weight, mask=None); predictoffset(andmask) with a small convolution initialised to zero, so training starts from a standard convolution.- Use deformable layers in the later stages of a backbone or in detection heads (DCNv2 replaced the 3 × 3 convolutions in the last three ResNet stages).
- Offsets usually get a lower learning rate for stability.
offset = self.offset_conv(x) # 2*k*k channels, initialised to zero
y = torchvision.ops.deform_conv2d(x, offset, self.weight, padding=1)- 1. The offset branch is initialised to…
- 2. DCNv2 replaced 3 × 3 convs in…
- 3. torchvision's function is…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Differentiability. Bilinear interpolation is piecewise linear in the sampling position, so gradients flow to the offsets: ∂x(p)/∂p is a combination of neighbouring pixel differences. The offsets are trained by ordinary backpropagation, with no extra supervision.
Adaptive receptive fields. Standard convolutions sample a fixed grid, so their receptive field is fixed. Deformable convolutions make it input-dependent: Dai et al. (2017) showed the sampling locations spread over large objects and concentrate on small ones.
Relation to spatial transformers and attention. Spatial transformer networks (Jaderberg et al., 2015) learn one global warp per image; deformable convolution learns local, per-position warps. Deformable attention (Zhu et al., 2021) samples a few learned points per query, combining the idea with attention weights.
Limits. Learned offsets only adapt where training data push them; geometric invariances not present in training are not acquired (exercise 2: the learned detector did not need to give up horizontal lines). Offsets also add compute and irregular memory access.
- 1. Offsets receive gradients because bilinear sampling is…
- 2. Spatial transformers learn…
- 3. Deformable attention samples…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Learning where to look
History.
- M. Jaderberg et al. (2015) introduced spatial transformer networks.
- J. Dai et al. (2017) introduced deformable convolutional networks; X. Zhu et al. (2019) DCNv2.
- X. Zhu et al. (2021) introduced deformable attention (Deformable DETR); W. Wang et al. (2023) scaled deformable convolution (InternImage).
Exercise 2. A fixed horizontal-line detector [[−1, −1, −1], [2, 2, 2], [−1, −1, −1]]/6 with sampling offsets shared by all positions. Offsets are learned by gradient ascent on its maximum response over 6 noisy images of 45° lines. Mean maximum response on 30 new images of each kind:
| offsets | 45° lines | horizontal lines |
|---|---|---|
| none (standard) | 0.252 | 1.046 |
| grid rotated by 45° (exact) | 0.718 | 0.184 |
| learned from 45° lines | 0.583 | 0.959 |
- The standard detector barely responded to diagonals.
- Rotating the sampling grid made it a diagonal detector, at the cost of horizontal lines.
- Learned offsets more than doubled the diagonal response and kept most of the horizontal response, since nothing in training asked them to give it up. Deformable sampling adapts geometry to what the training data reward.
Deformable convolution in AI, robotics and aerospace
- Aerial and satellite detection of rotated objects (vehicles, ships, aircraft) benefits from adaptive sampling.
- Driving scenes: deformable layers in detection and lane models handle perspective and curved lanes.
- Grasp detection for robot arms, where object poses vary widely.
References
- J. Dai et al. (2017). “Deformable convolutional networks.” Proc. ICCV.
- X. Zhu, H. Hu, S. Lin, J. Dai (2019). “Deformable ConvNets v2: more deformable, better results.” Proc. CVPR.
- M. Jaderberg, K. Simonyan, A. Zisserman, K. Kavukcuoglu (2015). “Spatial transformer networks.” Advances in NeurIPS.
- X. Zhu et al. (2021). “Deformable DETR: deformable transformers for end-to-end object detection.” Proc. ICLR.