InternImage: Exploring Large-Scale Vision Foundation Models with Deformable Convolutions
- Publication
- CVPR 2023Conference
- First submitted to arXiv
- arXiv:2211.05778
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{classiccnnsinternimage2022,
title = {{InternImage: Exploring Large-Scale Vision Foundation Models with Deformable Convolutions}},
author = {Wenhai Wang and Jifeng Dai and Zhe Chen and Zhenhang Huang and Zhiqi Li and Xizhou Zhu and Xiaowei Hu and Tong Lu and Lewei Lu and Hongsheng Li and Xiaogang Wang and Yu Qiao},
year = {2022},
eprint = {2211.05778},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2211.05778}
}
In 2022, vision models with more than a billion parameters were almost all Transformers. ViT-G has 1.8 billion parameters, SwinV2-G reached 3 billion, and BEiT-3 has 1.9 billion. On the convolutional side, the largest models, ConvNeXt-XL and RepLKNet-XL, both stopped at a little over 300 million. ConvNeXt proved that convolutions can still hold their own at ordinary sizes, but at the scale of a billion parameters and hundreds of millions of images, nobody had yet built a convolutional network that could rival ViT.
This paper comes from Shanghai AI Laboratory, SenseTime, Tsinghua University, Nanjing University, and CUHK. On the author list, Jifeng Dai and Xizhou Zhu are the first authors of the first and second versions of deformable convolution, respectively, and this time they bring out their own operator to build a backbone for large models.
Defining the Problem
Where Convolutions Fall Short
The authors first compare ordinary convolution with multi-head self-attention (MHSA) and pin down two differences.
The first is long-range dependence. Stack 3×3 convolutions layer upon layer, and the effective receptive field actually stays small; however deep the network gets, it struggles to see the whole image from the start the way ViT does.
The second is adaptive spatial aggregation. Self-attention weights change with the input, differing for every image and every position. Convolution weights are fixed once training is done, and they carry strong inductive biases such as locality and translation equivariance. Inductive biases let convolutional networks converge fast and get by with less data, but they also limit how well the networks can learn more general patterns from web-scale data.

Large kernels like RepLKNet and SLaK made up for the first item, but the second is still missing, since their weights are just as fixed after training. Deformable convolution has both. Each sampling point's offset lets it look near or far, and both the offsets and the modulation weights are computed from the input.
Why DCNv2 Can't Be Used As-Is
DCNv2's output at position can be written as
where is the number of sampling points, with for 3×3. is a grid position of ordinary convolution, is the learned offset, is the modulation weight after a sigmoid, and is the projection weight of the -th sampling point, of size .
The catch is that DCNv2 is usually used as an add-on, loading weights pretrained with ordinary convolution and then switching to deformable convolution for fine-tuning. For training a billion-parameter backbone from scratch, it has two flaws. Every sampling point has its own set of weights, so parameter count and memory both grow with . And the sigmoid puts each between 0 and 1, so the nine of them can add up to anything from 0 to 9; once the model is big and the data plentiful, gradients become unstable.
Solving the Problem
DCNv3's Three Changes
First, sampling points share weights. Borrowing the idea of separable convolution, is split in two. The position-dependent part is handed to the modulation weight , which plays the role of depthwise; the position-independent projection is shared by all sampling points, which plays the role of pointwise. Nine sets of weights shrink to one.
Second, grouping. Following multi-head attention, the channels are split into groups, each with its own offsets and modulation weights, so different groups in the same layer can look at different places.
Third, softmax for the modulation weights. A sigmoid is computed for each point on its own; switching to one softmax over all nine points fixes their sum at 1.
Put together, this is DCNv3:
where is the -th group of channels, each group having channels, and goes through a softmax along .
The offsets are fractional, so sampling positions usually land between pixels, and the values have to be fetched with bilinear interpolation. Let's write the simplest version with PyTorch's grid_sample, leaving out the final shared projection for now:
import torch
import torch.nn.functional as F
def dcnv3_core(x, offset, logits, G):
# x: (C, H, W); offset: (G, 9, 2, H, W), in pixels; logits: (G, 9, H, W)
C, H, W = x.shape
m = logits.softmax(dim=1) # each group's 9 sampling-point weights sum to 1
ys, xs = torch.meshgrid(torch.arange(H), torch.arange(W), indexing="ij")
grid = [(dy, dx) for dy in (-1, 0, 1) for dx in (-1, 0, 1)] # the 3×3 base positions p_k
out = torch.zeros_like(x)
for g, xg in enumerate(x.split(C // G)): # each group has its own offsets and weights
for k, (dy, dx) in enumerate(grid):
py = ys + dy + offset[g, k, 0] # p0 + p_k + Δp
px = xs + dx + offset[g, k, 1]
pos = torch.stack([px / (W - 1) * 2 - 1, py / (H - 1) * 2 - 1], -1)
v = F.grid_sample(xg[None], pos[None], align_corners=True)[0] # fetch values by bilinear interpolation
out[g * (C // G):(g + 1) * (C // G)] += m[g, k] * v
return out # followed by a linear projection shared by all sampling points
torch.manual_seed(0)
C, H, W, G = 8, 16, 16, 2
x = torch.randn(C, H, W)
# All offsets 0 and all weights equal: reduces to a 3×3 average
zero_off, flat = torch.zeros(G, 9, 2, H, W), torch.zeros(G, 9, H, W)
out = dcnv3_core(x, zero_off, flat, G)
print("With offsets at 0, max difference from 3×3 average pooling:", f"{(out - F.avg_pool2d(x, 3, 1, 1)).abs().max():.1e}")
# Move all 9 points of group 0 down by 5 cells: the 3×3 kernel sees 5 cells away
off = zero_off.clone()
off[0, :, 0] = 5.0
out = dcnv3_core(x, off, flat, G)
ref = F.avg_pool2d(x, 3, 1, 1)
print("After moving group 0 down 5 cells, max difference from the average 5 cells below:", f"{(out[:4, :-5] - ref[:4, 5:]).abs().max():.1e}")
print("Group 1 unaffected, max difference:", f"{(out[4:] - ref[4:]).abs().max():.1e}")
With offsets at 0, max difference from 3×3 average pooling: 2.4e-07
After moving group 0 down 5 cells, max difference from the average 5 cells below: 1.8e-07
Group 1 unaffected, max difference: 2.4e-07
When the offsets are 0 and the softmax weights are uniform, DCNv3 is just a 3×3 average. Once the offsets move, the same nine sampling points can reach 5 cells away, and only that group moves along. In the actual model, both the offsets and the modulation weights are computed from the input by a 3×3 depthwise convolution followed by a linear layer, so they differ at every position. The official code also includes a pure PyTorch version, whose comments state it's meant only for debugging and testing; training uses the CUDA operator.
The softmax term looks like a minor tweak. Sigmoid weights are independent of one another, so the sum over the nine sampling points can differ by more than twentyfold from one position to another, which amounts to multiplying each position's output by a different factor. The softmax sum is always 1. The ablation later on will show how much this one change matters.
Stacking It into a Network
With the operator in hand, the next question is how to build a network out of it.

The basic block looks a lot like a Transformer's. DCNv3 takes the place of self-attention, followed by an FFN with GELU, and the outputs of both branches go through LN before being added to the residual. The stem and downsampling layers stay with the convolutional-network style; the stem is two stride-2 3×3 convolutions, and downsampling is a single stride-2 3×3 convolution.
Each of the four stages has a channel count , a group count , and a block count , which makes 12 hyperparameters in total, too many to tune. The authors use four rules to bring them down to 4:
- , so the channel count doubles at each stage.
- , so the number of channels per group, , is fixed.
- .
- , so the third stage is the deepest.
The last two give the “AABA” stacking of ConvNeXt and Swin. That leaves four numbers, , , , and . The authors searched 30 combinations around 30 million parameters and picked as InternImage-T.
To scale up further, the authors follow EfficientNet's compound scaling, multiplying depth by and width by under the constraint , and find experimentally that and work best. The result is six sizes:
| Model | Blocks per stage | Parameters | ||
|---|---|---|---|---|
| InternImage-T | 64 | 16 | 4, 4, 18, 4 | 30M |
| InternImage-S | 80 | 16 | 4, 4, 21, 4 | 50M |
| InternImage-B | 112 | 16 | 4, 4, 21, 4 | 97M |
| InternImage-L | 160 | 16 | 5, 5, 22, 5 | 223M |
| InternImage-XL | 192 | 16 | 5, 5, 24, 5 | 335M |
| InternImage-H | 320 | 32 | 6, 6, 32, 6 | 1.08B |
T through XL are sized to match ConvNeXt for easy comparison; H was built separately to reach a billion parameters.
Discussion
ImageNet
First, the ordinary sizes. T, S, and B are trained on ImageNet-1K alone for 300 epochs, with 224×224 input:
| Size | Swin | ConvNeXt | SLaK | HorNet | InternImage |
|---|---|---|---|---|---|
| T (about 30M) | 81.3% | 82.1% | 82.5% | 83.0% | 83.5% |
| S (about 50M) | 83.0% | 83.1% | 83.8% | 84.0% | 84.2% |
| B (about 90M) | 83.5% | 83.8% | 84.0% | 84.3% | 84.9% |
At the same size, InternImage is highest in every row. T is 1.4 percentage points above ConvNeXt-T, and B is 1.1 higher.
Now the large models. XL is first pretrained on ImageNet-22K and reaches 88.0%. H is trained with M3I pretraining on 427 million public images from LAION-400M, YFCC-15M, and CC12M, and reaches 89.6% in the end with 640×640 input. The strongest ViTs and hybrid architectures sit at about 90.5% to 90.9%, using non-public data such as JFT, a gap of about 1 percentage point.
Detection and Segmentation
The gaps on downstream tasks are bigger than on classification. On COCO with Mask R-CNN trained for 12 epochs, InternImage-T reaches 47.2 box AP, against 42.7 for Swin-T and 44.2 for ConvNeXt-T, ahead by 4.5 and 3.0 respectively. With Cascade Mask R-CNN and 36 epochs of multi-scale training, XL gets 56.2 and ConvNeXt-XL 55.2. For ADE20K semantic segmentation with UperNet, InternImage-B gets 50.8 mIoU, against 49.1 for ConvNeXt-B, 49.9 for RepLKNet-31B, and 50.2 for SLaK-B.
The paper's most quoted number is 65.4 box AP on COCO test-dev, 1.2 above the previous best, FD-SwinV2-G, with 27% fewer parameters. A lot is stacked behind that number. The backbone is InternImage-H, first pretrained on 427 million images. A composite-backbone technique then doubles its parameters to 2.18 billion. The detector is DINO, trained first on Objects365 for 26 epochs and then on COCO for 12. The 62.9 mIoU on ADE20K is likewise H paired with Mask2Former, plus multi-scale testing. Every trick that could be stacked was stacked, so these numbers read more like a demonstration that this backbone can handle large-scale training.
Ablation: The Softmax Change
Removing DCNv3's three changes one at a time, compared on InternImage-T:
| Setting | ImageNet top-1 | COCO box AP | COCO mask AP |
|---|---|---|---|
| Full DCNv3 | 83.5% | 47.2 | 42.5 |
| No weight sharing | 83.6% | 47.4 | 42.6 |
| No grouping | 82.3% | 43.8 | 40.0 |
| Sigmoid instead of softmax | 65.7% | 38.7 | 35.6 |
Sharing weights barely affects accuracy, but the version without it has 66.1% more parameters. Scaled up to H, weight sharing saves 42.0% of the parameters and 84.2% of GPU memory; this change is there so the model can be made big.
Removing grouping drops ImageNet by 1.2 and COCO by 3.4, so detection takes the bigger hit.
Switching softmax back to sigmoid sends ImageNet straight down to 65.7%, a loss of nearly 18 percentage points. Here is where the varying sums discussed earlier show their effect.
The authors also tried larger sampling grids than 3×3. 5×5 gets 83.6%, with parameters rising from 30M to 37M; 7×7 actually drops to 82.8%, with 48M parameters. The sampling points move on their own, so 3×3 is enough.

The distribution of sampling points has layers to it too. In the first two stages they crowd near the query point, looking locally; by the third and fourth stages they spread across the whole image. That's very different from ViT, which is global from the first layer.
The Cost
The biggest cost is speed. In the appendix, the authors measured throughput on a single A100, with batch size 256 for 224×224 and batch size 2 for 800×800:
| Model | ImageNet top-1 | 224×224 (images/s) | 800×800 (images/s) |
|---|---|---|---|
| ConvNeXt-B | 83.8% | 881 | 58 |
| RepLKNet-B | 83.5% | 884 | 21 |
| DAT-B | 84.0% | 661 | 24 |
| InternImage-B (DCNv2) | — | 311 | 16 |
| InternImage-B | 84.9% | 775 | 54 |
With DCNv3, throughput is 2.5 to 3.4 times that of the DCNv2 version. It's still a bit slower than ConvNeXt-B, 12% lower at 224 and 7% lower at 800. At high resolution, though, it's 2.5 times RepLKNet-B, since large kernels struggle on big images. In their conclusion, the authors also acknowledge that the latency of DCN-style operators remains a problem for downstream tasks that demand speed.
Another experiment varies the amount of data. The authors uniformly sampled 1%, 10%, and all of ImageNet-1K, and trained on each for 300 epochs:
| Model | 1% | 10% | 100% |
|---|---|---|---|
| ResNet-50 | 12.2% | 57.5% | 80.4% |
| ConvNeXt-T | 8.4% | 52.6% | 82.1% |
| Swin-T | Failed | 12.1% | 81.3% |
| InternImage-T | 5.9% | 56.0% | 83.5% |
The authors say InternImage-T is robust on both 1% and 10% of the data. In the 1% column, however, it loses to ResNet-50 and ConvNeXt-T and beats only Swin-T, which failed to train at all; at 10% it still loses to ResNet-50. It does cope with small amounts of data better than Swin-T. When the data shrinks to just 1%, though, ResNet-50 and ConvNeXt-T, with their stronger inductive biases, still come out ahead.
Conclusion
Those record-breaking numbers really were won by brute force. It took 427 million images, a composite backbone with doubled parameters, Objects365 pretraining, and DINO on top to get COCO's 65.4.
But bring the size back down to ordinary scales, with parameters and FLOPs matched to ConvNeXt, and InternImage is still more than 1 percentage point ahead on ImageNet and 1.8 to 3.0 ahead in COCO box AP. Here there's no brute force to lean on; the credit goes to DCNv3 itself.
If you want to run it yourself, you'll first have to get on good terms with that custom CUDA operator. At every checkpoint, whether compiling, deploying, or exporting to TensorRT, it's the first thing you have to get past.
One last little aside. In this paper's ablation, switching softmax back to sigmoid makes accuracy crash from 83.5% to 65.7%. A little over a year later, much the same group released DCNv4, and one of its two main changes was dropping the softmax entirely, which even made it converge faster.
The shelf life of a paper's key design is sometimes just a year.