Vision Transformers (ViTs) are built on the assumption of treating image patches as ``visual tokens" and learn patch-to-patch attention. The patch embedding based tokenizer has a semantic gap with respect to its counterpart, the textual tokenizer. The patch-to-patch attention suffers from the quadratic complexity issue, and also makes it non-trivial to explain learned ViTs. To address these issues in ViT, this paper proposes to learn Patch-to-Cluster attention (PaCa) in ViT. Queries in our PaCa-ViT starts with patches, while keys and values are directly based on clustering (with a predefined small number of clusters). The clusters are learned end-to-end, leading to better tokenizers and inducing joint clustering-for-attention and attention-for-clustering for better and interpretable models. The quadratic complexity is relaxed to linear complexity. The proposed PaCa module is used in designing efficient and interpretable ViT backbones and semantic segmentation head networks. In experiments, the proposed methods are tested on ImageNet-1k image classification, MS-COCO object detection and instance segmentation and MIT-ADE20k semantic segmentation. Compared with the prior art, it obtains better performance in all the three benchmarks than the SWin and the PVTs by significant margins in ImageNet-1k and MIT-ADE20k. It is also significantly more efficient than PVT models in MS-COCO and MIT-ADE20k due to the linear complexity. The learned clusters are semantically meaningful. Code and model checkpoints are available at https://github.com/iVMCL/PaCaViT.
翻译:视觉变换器(ViT)基于将图像补丁视为“视觉标记”并学习补丁到补丁的关注点这一假设进行构建。补丁嵌入式记号生成器与其文本式记号生成器对应物存在语义上的差距。补丁到补丁的关注点存在二次复杂度问题,并且使得解释ViT的学习变得困难。 为了解决这些ViT中的问题,本文提出在ViT中学习补丁到集群关注点(PaCa)。我们PaCa-ViT中的查询从补丁开始,而键和值基于聚类直接进行(具有预定义的少量的聚类)。这些聚类是端到端学习的,从而导致更好的标记生成器和诱导联合聚类-关注和关注-聚类以得到更好和可解释的模型。二次复杂性被放松到线性复杂性。在设计高效且可解释的ViT主干和语义分割头部网络时,使用了所提出的PaCa模块。在实验中,所提出的方法在ImageNet-1k图像分类,MS-COCO对象检测和实例分割以及MIT-ADE20k语义分割中进行测试。与SWin和PVT相比,它在ImageNet-1k和MIT-ADE20k中的所有三个基准测试中表现更好。由于是线性复杂度,因此在MS-COCO和MIT-ADE20k中比PVT模型更有效率。学习到的聚类在语义上具有含义。 代码和模型检查点可在https://github.com/iVMCL/PaCaViT获取。