{"notes":[{"id":"reparameterization/replknet","category":"reparameterization","legacyPath":"reparameterization/2203-replknet","legacySlug":"2203-replknet","legacyPaths":[],"title":"RepLKNet","subtitle":"Giant Convolutional Kernels","author":"Z. Yuan","paperDate":"2022-03-13","publishedOn":"2024-07-21","paperTitle":"Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs","paperUrl":"https://arxiv.org/abs/2203.06717","bibliography":{"title":"Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs","authors":["Xiaohan Ding","Xiangyu Zhang","Yizhuang Zhou","Jungong Han","Guiguang Ding","Jian Sun"],"url":"https://arxiv.org/abs/2203.06717","pdfUrl":"https://arxiv.org/pdf/2203.06717","codeUrl":null,"preprint":{"id":"2203.06717","submittedOn":"2022-03-13","url":"https://arxiv.org/abs/2203.06717"},"publication":{"venue":"CVPR","year":2022,"kind":"conference","url":"https://arxiv.org/abs/2203.06717"},"citation":"@misc{reparameterizationreplknet2022,\n  title = {{Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs}},\n  author = {Xiaohan Ding and Xiangyu Zhang and Yizhuang Zhou and Jungong Han and Guiguang Ding and Jian Sun},\n  year = {2022},\n  eprint = {2203.06717},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2203.06717}\n}\n","citationPath":"/content/papers/citations/reparameterization/replknet.c7cc2407aa19.bib"},"thumbnail":{"src":"/content/papers/assets/b85fa678b6e815b9d112b67d68443295a98c80478664ec8053c2e832d89574ca.jpg","width":1140,"height":972},"locale":"en","path":"/content/papers/en/reparameterization/replknet.271ac18a9d7c.md","headings":[{"id":"problem-definition","text":"Problem Definition","depth":2},{"id":"a-guide-to-using-large-kernels-in-convolution","text":"A Guide to Using Large Kernels in Convolution","depth":2},{"id":"deep-large-kernels-remain-efficient","text":"Deep Large Kernels Remain Efficient","depth":3},{"id":"large-kernels-heavily-rely-on-residual-connections","text":"Large Kernels Heavily Rely on Residual Connections","depth":3},{"id":"large-kernels-require-reparameterization","text":"Large Kernels Require Reparameterization","depth":3},{"id":"large-kernels-significantly-enhance-downstream-task-performance","text":"Large Kernels Significantly Enhance Downstream Task Performance","depth":3},{"id":"large-kernels-are-effective-even-with-small-feature-maps","text":"Large Kernels Are Effective Even with Small Feature Maps","depth":3},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"network-architecture","text":"Network Architecture","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"evaluation-of-large-kernels","text":"Evaluation of Large Kernels","depth":3},{"id":"performance-on-imagenet","text":"Performance on ImageNet","depth":3},{"id":"large-kernel-cnns-have-larger-erf-than-deep-small-kernel-models","text":"Large Kernel CNNs Have Larger ERF Than Deep Small Kernel Models","depth":3},{"id":"shape-bias","text":"Shape Bias","depth":3},{"id":"limitations","text":"Limitations","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"classic-cnns/convnext","relation":"comparison","topic":"Large kernels and simpler convolutional backbones"}]},{"id":"classic-cnns/convnext","category":"classic-cnns","legacyPath":"classic-cnns/2201-convnext","legacySlug":"2201-convnext","legacyPaths":[],"title":"ConvNeXt","subtitle":"Making Convolutions Great Again","author":"Z. Yuan","paperDate":"2022-01-10","publishedOn":"2024-06-30","paperTitle":"A ConvNet for the 2020s","paperUrl":"https://arxiv.org/abs/2201.03545","bibliography":{"title":"A ConvNet for the 2020s","authors":["Zhuang Liu","Hanzi Mao","Chao-Yuan Wu","Christoph Feichtenhofer","Trevor Darrell","Saining Xie"],"url":"https://arxiv.org/abs/2201.03545","pdfUrl":"https://arxiv.org/pdf/2201.03545","codeUrl":"https://github.com/facebookresearch/ConvNeXt","preprint":{"id":"2201.03545","submittedOn":"2022-01-10","url":"https://arxiv.org/abs/2201.03545"},"publication":{"venue":"CVPR","year":2022,"kind":"conference","url":"https://arxiv.org/abs/2201.03545"},"citation":"@misc{classiccnnsconvnext2022,\n  title = {{A ConvNet for the 2020s}},\n  author = {Zhuang Liu and Hanzi Mao and Chao-Yuan Wu and Christoph Feichtenhofer and Trevor Darrell and Saining Xie},\n  year = {2022},\n  eprint = {2201.03545},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2201.03545}\n}\n","citationPath":"/content/papers/citations/classic-cnns/convnext.801b4060b807.bib"},"thumbnail":{"src":"/content/papers/assets/37882616c5c72df33699003256d14bf7c58c8ea5d1e9e4fb5b1c33268c9a6923.jpg","width":1224,"height":432},"locale":"en","path":"/content/papers/en/classic-cnns/convnext.1a8312c7b164.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"redesigning-network-architecture","text":"Redesigning Network Architecture","depth":3},{"id":"introducing-modern-training-techniques","text":"Introducing Modern Training Techniques","depth":3},{"id":"macro-design","text":"Macro Design","depth":3},{"id":"resnext-ify","text":"ResNeXt-ify","depth":3},{"id":"inverted-bottleneck","text":"Inverted Bottleneck","depth":3},{"id":"large-kernel-convolution","text":"Large Kernel Convolution","depth":3},{"id":"micro-design","text":"Micro Design","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"summary-of-model-configurations","text":"Summary of Model Configurations","depth":3},{"id":"performance-on-imagenet","text":"Performance on ImageNet","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"vision-transformers/convmixer","relation":"comparison","topic":"Convolution for mixing visual patches"},{"id":"vision-transformers/caformer","relation":"comparison","topic":"Convolution for mixing visual patches"},{"id":"reparameterization/replknet","relation":"comparison","topic":"Large kernels and simpler convolutional backbones"}]}],"text":"In recent years, CNN architectures have faced challenges from ViT, causing their dominance to waver.\n\nSome argue that ViT's strength lies in its multi-head attention mechanism, which offers greater flexibility, reduced inductive bias, and robustness to distortions.\n\nHowever, another perspective attributes ViT's performance to its architecture, even when the multi-head attention is removed, resulting in similar performance.\n\nThis paper differs by focusing on a single aspect: the design of large convolutional kernels.\n\n## Problem Definition\n\nLarge kernel models have not been popular since VGG, except for some older models like Inceptions.\n\nVGG demonstrated that stacking small kernels can achieve the same receptive field, leading to a decline in interest in large kernel designs.\n\nRecent studies on large kernels have not addressed a key question:\n\n- **Why do traditional CNNs underperform compared to ViTs? Is achieving a large receptive field crucial for closing the performance gap between CNNs and ViTs?**\n\n## A Guide to Using Large Kernels in Convolution\n\nTo answer this question, the authors systematically explored the design of large kernels in CNNs and summarized five guidelines.\n\n### Deep Large Kernels Remain Efficient\n\nLarge kernels are often considered computationally expensive due to increased FLOPs.\n\nHowever, using depthwise convolutions can significantly mitigate this issue.\n\nOn the other hand, modern GPUs and parallel computing devices have limited support for depthwise convolutions, increasing memory access costs.\n\nExisting deep learning tools also lack adequate support for depthwise convolutions, resulting in high inference latency with PyTorch implementations, as shown below.\n\n![img1](/content/papers/assets/a8c40430b36af3afa0e9d234e4ea465a885049ef0a928055c9e099a085c9fa83.jpg)\n\nTo address this, the authors released an efficient PyTorch implementation, reducing the depthwise layers’ share of total model inference latency from 49.5% to 12.3%, roughly proportional to FLOPs:\n\n- [**RepLKNet-pytorch**](https://github.com/DingXiaoH/RepLKNet-pytorch)\n\n### Large Kernels Heavily Rely on Residual Connections\n\n![img2](/content/papers/assets/3ab56ed1c7d9b2ce2728860bf28357cb2ec765cde8ad7059037bc981ab966f04.jpg)\n\nUsing MobileNet-V2 for benchmarking, the authors replaced all DW 3×3 layers with 13×13 layers.\n\nThe table shows that large kernels improve the accuracy of MobileNet-V2 with shortcuts by 0.77 percentage points under the same 100-epoch training setup. Without shortcuts, large kernels reduce accuracy to only 53.98%.\n\n\n> [!TIP]\n> \n> As seen in previous studies, shortcuts create implicit ensembles of models with different receptive fields, benefiting from a larger maximum receptive field without losing the ability to capture small-scale patterns.\n\n\n### Large Kernels Require Reparameterization\n\n![img3](/content/papers/assets/7082c8345268979addca1855712d371f2bfaf186ba919b84cffc2096659070f7.jpg)\n\nThe table shows that directly increasing kernel size from 9 to 13 reduces accuracy, but adding a parallel small-kernel branch during training helps. Before inference, the branch and BN parameters are fused into the large kernel with fixed BN statistics; training-mode BN is not a fixed linear operation.\n\nIt is known that ViT faces optimization problems with small datasets. A common solution is to introduce convolutional priors, such as adding a DW 3×3 convolution to each self-attention block, similar to this study. These strategies introduce additional translation equivariance and locality, making optimization easier on small datasets without losing generality.\n\nSimilarly, the authors found that reparameterization can be omitted without performance degradation when the pre-training dataset is increased to 73 million images.\n\n### Large Kernels Significantly Enhance Downstream Task Performance\n\n![img4](/content/papers/assets/9fc685a0b3469d1861abd6f2a10d755aeb1e3409f09cb19a3653b19733b004e2.jpg)\n\nThe table shows that increasing the kernel size from 3×3 to 9×9 in MobileNet V2 improves ImageNet accuracy by 1.33 percentage points and Cityscapes mIoU by 3.99 points.\n\n![img5](/content/papers/assets/0ff51f15fd9167ddf4800d943efb6b6bf2b4482592a06c3d73ca19ee86cd118a.jpg)\n\nAnother experiment shows a similar trend: as kernel size increases from [3, 3, 3, 3] to [31, 29, 27, 13], ImageNet accuracy improves by only 0.96 percentage points, while ADE20K mIoU increases by 3.12 points. This indicates that models with similar ImageNet scores can have very different capabilities in downstream tasks.\n\nThe authors offer two possible explanations:\n\n1. Large kernels significantly increase the effective receptive field (ERF). Numerous studies have shown that \"context\" information (large ERF) is crucial for many downstream tasks, such as object detection and semantic segmentation.\n2. Large kernels introduce more shape bias to the network. ImageNet images can be correctly classified based on texture or shape, but humans primarily rely on shape cues to recognize objects. Thus, models with stronger shape bias may perform better in downstream tasks.\n\nRecent studies also indicate that ViT has a strong shape bias, partly explaining why ViT excels in transfer tasks. In contrast, traditional CNNs trained on ImageNet tend to have a texture bias.\n\n- [**[21.05] Are convolutional neural networks or transformers more like human vision?**](https://arxiv.org/abs/2105.07197)\n\n### Large Kernels Are Effective Even with Small Feature Maps\n\n![img6](/content/papers/assets/a16069319accde0f08e9abe4edc57db5b8c63f19f1ccd7f3bf1a7ec6b65fd892.jpg)\n\nThe authors enlarged the DW convolution in the final stage of MobileNet V2 to 7×7 or 13×13, making the kernel size equal to or larger than the feature map size (default 7×7). The table shows that using a 13×13 kernel in the final stage raises ImageNet accuracy slightly, from 71.76% to 71.97%, while Cityscapes mIoU rises from 72.31% to 74.62%.\n\nThe authors suggest that padding at the boundaries of a finite feature map matters more as kernel size grows relative to the map. Translation equivariance then no longer holds strictly. Adjacent spatial positions' outputs share only part of the kernel weights, transforming through different mappings, as illustrated below. This mechanism might explain the effectiveness of large kernels on small feature maps.\n\n![img7](/content/papers/assets/2bb517f2507998da2e025f121558a7c3c7663662e626670dfd8f401b466d593d.jpg)\n\n## Solving the Problem\n\n### Network Architecture\n\n![img8](/content/papers/assets/b85fa678b6e815b9d112b67d68443295a98c80478664ec8053c2e832d89574ca.jpg)\n\nBased on the above insights, the authors proposed a new network architecture, RepLKNet.\n\nFirstly, RepLKNet's design focuses on capturing more details in the initial stages through multiple convolution layers. After the initial 3×3 convolution and downsampling, a 3×3 depthwise convolution (DW) layer captures low-level patterns, followed by a 1×1 convolution layer and another DW 3×3 layer for downsampling. This stem processes low-level patterns and downsamples the input by a total factor of four.\n\nSecondly, each stage (1-4) of RepLKNet contains multiple RepLK blocks. These blocks leverage shortcuts and DW large kernels to enhance performance. During training, each large DW layer has a parallel 5×5 branch. With fixed BN statistics, both branches can be merged into one large kernel.\n\n\n> [!TIP]\n> \n> Although not shown in the diagram above, this part is crucial for performance improvement. These blocks enable efficient feature extraction and processing at different stages.\n\n\nAdditionally, to enhance nonlinearity and cross-channel communication, RepLKNet introduces ConvFFN blocks. These blocks consist of shortcuts, Batch Normalization (BN), two 1×1 convolution layers, and GELU activation, similar to feedforward networks (FFN) in Transformers and MLPs.\n\nCompared to the classic FFN using Layer Normalization, BN integrates better with convolution operations, improving inference efficiency. This design is inspired by Transformers and MLP networks and has been successfully applied in CNNs.\n\nBetween different stages, RepLKNet uses Transition Blocks to adjust channel dimensions and perform downsampling. These blocks first increase channel dimensions with a 1×1 convolution, then downsample using a DW 3×3 convolution, ensuring comprehensive feature extraction and transformation. Each transition halves the spatial resolution.\n\n## Discussion\n\n### Evaluation of Large Kernels\n\n![img9](/content/papers/assets/e62eaf2cca43ce5507624a33c8e2422404de551e096f023508460bd394537393.jpg)\n\nTo evaluate the impact of large kernels on RepLKNet, the authors changed kernel sizes while keeping some hyperparameters fixed, observing their performance on classification and semantic segmentation tasks.\n\nWith depth and channels fixed in this ablation, ImageNet top-1 accuracy rises from **82.11%** at 3×3 to **83.02%** at 13×13, then only **83.07%** with stage kernels [31, 29, 27, 13]. ADE20K mIoU rises from **48.35% to 49.17%** over the comparison. The further ImageNet gain is small, while the downstream score still improves.\n\nThis indicates that while large kernels have limited benefits for certain tasks, they are valuable in specific applications.\n\n### Performance on ImageNet\n\n![img10](/content/papers/assets/80ff18c3ef5f9f3bb14de7cf3c8b11cd99b258c48efc1fda9b5b1170082028a8.jpg)\n\nGiven the similarities in architecture between RepLKNet and Swin, the authors conducted a detailed comparison.\n\nOn ImageNet-1K, the authors extended the training schedule of RepLKNet-31B to 300 epochs to ensure a fair comparison. Then, they fine-tuned for 30 epochs with 384×384 input resolution, at a training cost significantly lower than training Swin-B from scratch with 384×384 resolution.\n\nAdditionally, the authors pre-trained RepLKNet-B and RepLKNet-L on ImageNet-22K and fine-tuned them on ImageNet-1K. RepLKNet-XL was pre-trained on the authors' private semi-supervised dataset MegData73M.\n\nThe authors also tested the models' throughput on the same 2080Ti GPU in FP32 with a batch size of 64.\n\n---\n\nThe results show that very large kernels add relatively little to ImageNet classification beyond the earlier increase, while RepLKNet remains accurate and efficient in the listed settings. For instance, RepLKNet-31B trained only on ImageNet-1K reaches **84.8%** at 384×384, **0.3 percentage points** above Swin-B. On the same 2080Ti at batch size 64, throughput is **97.0 versus 67.9 images/s**, about **43%** higher. RepLKNet-XL and Swin-L differ in listed input size and pretraining data, so their rows cannot isolate a speed benefit from the large-kernel design.\n\n### Large Kernel CNNs Have Larger ERF Than Deep Small Kernel Models\n\nThe authors demonstrated that large kernel designs significantly improve CNN performance.\n\nThree stride-1 3×3 convolutions have a 7×7 theoretical receptive field. Representing an arbitrary 7×7 linear convolution exactly also requires enough intermediate channels; an arbitrary nonlinear stack is not the same operation. This raises a question:\n\n- **Why do traditional CNNs with numerous small convolution layers (e.g., ResNets) still underperform compared to large kernel networks?**\n\nThe authors argue that a single large kernel is more effective in achieving a large receptive field (ERF) than many small kernels. Under the simplified ERF theory cited in the paper, its spatial extent grows approximately as $O(K\\sqrt{L})$, where K is the kernel size, and L is the depth (number of layers).\n\nIn other words, **Under those assumptions, ERF grows approximately linearly with kernel size and with the square root of depth**; this is not an exact law for every trained network.\n\n---\n\nMoreover, increasing depth brings optimization challenges.\n\nAlthough ResNets are thought to overcome this issue, they do not entirely. Studies show that ResNets behave like ensembles of shallow networks, with ERF remaining limited despite increased depth.\n\nTo support this, the authors conducted an experiment:\n\n![img11](/content/papers/assets/f1d170dd8687376b5b85a3009e7bfedfed885d07ac40760856fe77e5c4ec7977.jpg)\n\nTo visualize ERF, the authors used a simple yet effective method.\n\nThey resized **50 ImageNet validation images** to **1024×1024** and aggregated a contribution score matrix $A$, measuring how input pixels contribute to the center point of the final feature map.\n\nIn simpler terms: **Which pixels in the input image contribute to the center point of the feature map?**\n\nThe results show that in ResNet, ERF is very limited, even with increased depth. In contrast, RepLKNet exhibits more uniformly distributed high-contribution pixels, resulting in a larger ERF.\n\n### Shape Bias\n\n![img12](/content/papers/assets/5451b2c55d76b1199be64a0095676fea5ff5e65ebaf755e64236cae69f52f3ca.jpg)\n\nThe authors note that large kernel designs introduce a stronger shape bias, crucial for downstream tasks.\n\nThey measured the shape bias of RepLKNet-31B and Swin-B, trained on ImageNet-1K or 22K, and two small kernel baselines, RepLKNet-3 and ResNet-152.\n\nIn this figure's **16-class cue-conflict images**, RepLKNet-31B has a higher average shape bias than Swin-B and the small-kernel CNNs. The authors suggest that shape bias is closely related to ERF and cannot be inferred from self-attention alone. They offer the following interpretation, rather than a proof of unique causation:\n\n1. ViT's high shape bias due to global attention\n2. Swin Transformer's low shape bias due to local window attention\n\n### Limitations\n\nWhile large kernel designs significantly enhance CNN performance on ImageNet and downstream tasks, RepLKNet begins to lag behind Swin Transformers as the data and model scale increase.\n\nThe authors are unsure whether this gap is due to suboptimal hyperparameter tuning or fundamental flaws in CNNs with larger data and model scales.\n\nThis remains an open area for future research.\n\n## Conclusion\n\nIn this study, the authors revisited the long-neglected design of large convolutional kernels in CNN architecture.\n\nThrough experiments, they demonstrated that using a few large kernels instead of many small ones can more effectively achieve a larger effective receptive field, significantly improving CNN performance. This finding helps narrow the performance gap between CNNs and ViTs.\n\nFor the CNN community, the results suggest that special attention should be given to ERF, which may be key to achieving high performance. For the ViT community, the study shows that large convolutional kernels can replace multi-head self-attention mechanisms with similar behavior, potentially aiding in understanding the intrinsic mechanisms of self-attention.\n\nThe authors hope this work fosters mutual understanding and progress between the two communities and inspires further research to explore and optimize deep learning model architecture design.\n","imageSizes":{"/content/papers/assets/a8c40430b36af3afa0e9d234e4ea465a885049ef0a928055c9e099a085c9fa83.jpg":{"width":1460,"height":322},"/content/papers/assets/3ab56ed1c7d9b2ce2728860bf28357cb2ec765cde8ad7059037bc981ab966f04.jpg":{"width":1200,"height":344},"/content/papers/assets/7082c8345268979addca1855712d371f2bfaf186ba919b84cffc2096659070f7.jpg":{"width":1788,"height":282},"/content/papers/assets/9fc685a0b3469d1861abd6f2a10d755aeb1e3409f09cb19a3653b19733b004e2.jpg":{"width":1116,"height":426},"/content/papers/assets/0ff51f15fd9167ddf4800d943efb6b6bf2b4482592a06c3d73ca19ee86cd118a.jpg":{"width":1536,"height":528},"/content/papers/assets/a16069319accde0f08e9abe4edc57db5b8c63f19f1ccd7f3bf1a7ec6b65fd892.jpg":{"width":1548,"height":366},"/content/papers/assets/2bb517f2507998da2e025f121558a7c3c7663662e626670dfd8f401b466d593d.jpg":{"width":1318,"height":428},"/content/papers/assets/b85fa678b6e815b9d112b67d68443295a98c80478664ec8053c2e832d89574ca.jpg":{"width":1140,"height":972},"/content/papers/assets/e62eaf2cca43ce5507624a33c8e2422404de551e096f023508460bd394537393.jpg":{"width":1326,"height":442},"/content/papers/assets/80ff18c3ef5f9f3bb14de7cf3c8b11cd99b258c48efc1fda9b5b1170082028a8.jpg":{"width":1392,"height":870},"/content/papers/assets/f1d170dd8687376b5b85a3009e7bfedfed885d07ac40760856fe77e5c4ec7977.jpg":{"width":1544,"height":494},"/content/papers/assets/5451b2c55d76b1199be64a0095676fea5ff5e65ebaf755e64236cae69f52f3ca.jpg":{"width":996,"height":1028}}}
