Back to paper library
arXiv 2022TMLR 2023Vision TransformersPaper notes

ConvMixer

Convolutional Mixer

Original paper

Patches Are All You Need?

Paper authors

Asher Trockman · J. Zico Kolter

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}
}
On this page

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

Imported original Figure 2 with earlier note annotations; Trockman and Kolter, arXiv:2201.09792v1

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.

  1. 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.
  2. Replace the MLP with pointwise convolution. A 1×11\times1 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

Trockman and Kolter, Figure 1, arXiv:2201.09792v1

Four parameters describe a ConvMixer:

  1. Width (hidden dimension, hh): The dimension of each patch embedding.
  2. Depth (dd): The number of repeated ConvMixer layers.
  3. Patch size (pp): Sets the model's internal spatial resolution by dividing the input image into patches.
  4. Kernel size (kk): 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-hh/dd. ConvMixer supports variable input sizes; with an input side length nn divisible by pp, its internal side length is n/pn/p. The figure above plots ImageNet accuracy against parameter count, rather than showing these four operations.

Discussion

Performance on ImageNet

Trockman and Kolter, Table 1, arXiv:2201.09792v1

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

Trockman and Kolter, Appendix A Table 2, arXiv:2201.09792v1

The appendix shows the patch-size trade-off. For ConvMixer-1536/20, changing pp from 7 to 14 lowers top-1 from 81.37% to 78.92%, while throughput rises from 134 to 538 images/s. The untuned k=3k=3 row is also less accurate than the k=9k=9 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:

  1. The patch-based design matters.
  2. ConvMixer is simple, performs well, and is worth considering.