Patches Are All You Need?
- Publication
- Transactions on Machine Learning Research 2023Journal
- First submitted to arXiv
- arXiv:2201.09792
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{visiontransformersconvmixer2022,
title = {{Patches Are All You Need?}},
author = {Asher Trockman and J. Zico Kolter},
year = {2022},
eprint = {2201.09792},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2201.09792}
}
We have seen plenty of titles in the form “XXX is all you need” over the past few years.
Whenever one turns up, we cannot help taking a look: what happened this time?
Problem Definition
Since ViT appeared, everyone has wanted to know why Transformers work so well. Is it self-attention, token mixing, or the design of the whole architecture?
In this paper, the authors ask whether ViT's strength also comes from patchifying the image. They propose ConvMixer to remove self-attention from this kind of design. If performance holds up, that gives us a reason to think patch representation matters at least to some extent; the experiment does not isolate patchification as the only cause.
Solution
Model Architecture
The authors keep ViT's idea of taking patches as input and maintaining the same resolution through the later layers, but build a different architecture with convolutions. There are two main changes. The red marks on this imported figure are the note's annotations, rather than part of the original paper figure.
- Replace self-attention with convolution. The image is first divided into patches using a convolution whose kernel and stride both equal the patch size, while retaining their two-dimensional arrangement. For token mixing, the model uses a depthwise convolution instead of self-attention. Each layer mixes nearby patches within the kernel's reach, and stacking layers expands that reach. This lets us examine a patch-based model without self-attention.
- Replace the MLP with pointwise convolution. A convolution mixes channels at each spatial position, much like a per-token linear layer. It is not equivalent to a complete two-layer MLP. The figure then shows GELU and BatchNorm.
Training Strategy
The authors train from random initialization on ImageNet-1K without extra pretraining or additional data. Their setup includes RandAugment and MixUp, along with AdamW. They did not tune ImageNet hyperparameters and trained for fewer epochs than some comparison models because compute was limited.
Model Design Parameters
Four parameters describe a ConvMixer:
- Width (hidden dimension, ): The dimension of each patch embedding.
- Depth (): The number of repeated ConvMixer layers.
- Patch size (): Sets the model's internal spatial resolution by dividing the input image into patches.
- Kernel size (): Sets the size of the depthwise convolution kernel and the area mixed in one layer.
Models are named for width and depth, such as ConvMixer-/. ConvMixer supports variable input sizes; with an input side length divisible by , its internal side length is . The figure above plots ImageNet accuracy against parameter count, rather than showing these four operations.
Discussion
Performance on ImageNet
ConvMixer-1536/20 reaches 81.37% ImageNet top-1 with 51.6M parameters, ahead of ResNet-152's 79.64% with 60.2M parameters. ConvMixer-768/32 also reaches a similar 80.16% with roughly one-third as many parameters as ResNet-152, though the training epochs differ.
Despite its relatively small parameter count, ConvMixer-1536/20 exceeds ResMLP-B24/8's 81.0% and approaches DeiT-B's 81.8% in this main table. DeiT and ResMLP benefited from more hyperparameter tuning; ConvMixer's main result used an untuned setup. The appendix separately reports 82.20% after changing regularization, so we should keep those training settings distinct.
The cost of patch size, kernel size and tuning
The appendix shows the patch-size trade-off. For ConvMixer-1536/20, changing from 7 to 14 lowers top-1 from 81.37% to 78.92%, while throughput rises from 134 to 538 images/s. The untuned row is also less accurate than the row; the starred 82.20% result uses different regularization. Looking only at accuracy or speed misses the other side.
Conclusion
The authors propose ConvMixer to weaken the role of self-attention and explore what patchification contributes. Performance remains strong without self-attention, leading them to two conclusions:
- The patch-based design matters.
- ConvMixer is simple, performs well, and is worth considering.