Skip to content

Latest commit

 

History

History

xcit

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

XCiT

XCiT: Cross-Covariance Image Transformers

Abstract

Following their success in natural language processing, transformers have recently shown much promise for computer vision. The self-attention operation underlying transformers yields global interactions between all tokens ,i.e. words or image patches, and enables flexible modelling of image data beyond the local interactions of convolutions. This flexibility, however, comes with a quadratic complexity in time and memory, hindering application to long sequences and high-resolution images. We propose a "transposed" version of self-attention that operates across feature channels rather than tokens, where the interactions are based on the cross-covariance matrix between keys and queries. The resulting cross-covariance attention (XCA) has linear complexity in the number of tokens, and allows efficient processing of high-resolution images. Our cross-covariance image transformer (XCiT) is built upon XCA. It combines the accuracy of conventional transformers with the scalability of convolutional architectures. We validate the effectiveness and generality of XCiT by reporting excellent results on multiple vision benchmarks, including image classification and self-supervised feature learning on ImageNet-1k, object detection and instance segmentation on COCO, and semantic segmentation on ADE20k.

How to use it?

Use the model

import torch
from mmpretrain import get_model

model = get_model('xcit-nano-12-p16_3rdparty_in1k', pretrained=True)
inputs = torch.rand(1, 3, 224, 224)
out = model(inputs)
print(type(out))
# To extract features.
feats = model.extract_feat(inputs)
print(type(feats))

Test Command

Prepare your dataset according to the docs.

Test:

python tools/test.py configs/xcit/xcit-nano-12-p16_8xb128_in1k.py https://download.openmmlab.com/mmclassification/v0/xcit/xcit-nano-12-p16_3rdparty_in1k_20230213-ed776c38.pth

Models and results

Pretrained models

Model Params (M) Flops (G) Config Download
xcit-nano-12-p16_3rdparty_in1k* 3.05 0.56 config model
xcit-nano-12-p16_3rdparty-dist_in1k* 3.05 0.56 config model
xcit-tiny-12-p16_3rdparty_in1k* 6.72 1.24 config model
xcit-tiny-12-p16_3rdparty-dist_in1k* 6.72 1.24 config model
xcit-nano-12-p16_3rdparty-dist_in1k-384px* 3.05 1.64 config model
xcit-nano-12-p8_3rdparty_in1k* 3.05 2.16 config model
xcit-nano-12-p8_3rdparty-dist_in1k* 3.05 2.16 config model
xcit-tiny-24-p16_3rdparty_in1k* 12.12 2.34 config model
xcit-tiny-24-p16_3rdparty-dist_in1k* 12.12 2.34 config model
xcit-tiny-12-p16_3rdparty-dist_in1k-384px* 6.72 3.64 config model
xcit-tiny-12-p8_3rdparty_in1k* 6.71 4.81 config model
xcit-tiny-12-p8_3rdparty-dist_in1k* 6.71 4.81 config model
xcit-small-12-p16_3rdparty_in1k* 26.25 4.81 config model
xcit-small-12-p16_3rdparty-dist_in1k* 26.25 4.81 config model
xcit-nano-12-p8_3rdparty-dist_in1k-384px* 3.05 6.34 config model
xcit-tiny-24-p16_3rdparty-dist_in1k-384px* 12.12 6.87 config model
xcit-small-24-p16_3rdparty_in1k* 47.67 9.10 config model
xcit-small-24-p16_3rdparty-dist_in1k* 47.67 9.10 config model
xcit-tiny-24-p8_3rdparty_in1k* 12.11 9.21 config model
xcit-tiny-24-p8_3rdparty-dist_in1k* 12.11 9.21 config model
xcit-tiny-12-p8_3rdparty-dist_in1k-384px* 6.71 14.13 config model
xcit-small-12-p16_3rdparty-dist_in1k-384px* 26.25 14.14 config model
xcit-medium-24-p16_3rdparty_in1k* 84.40 16.13 config model
xcit-medium-24-p16_3rdparty-dist_in1k* 84.40 16.13 config model
xcit-small-12-p8_3rdparty_in1k* 26.21 18.69 config model
xcit-small-12-p8_3rdparty-dist_in1k* 26.21 18.69 config model
xcit-small-24-p16_3rdparty-dist_in1k-384px* 47.67 26.72 config model
xcit-tiny-24-p8_3rdparty-dist_in1k-384px* 12.11 27.05 config model
xcit-small-24-p8_3rdparty_in1k* 47.63 35.81 config model
xcit-small-24-p8_3rdparty-dist_in1k* 47.63 35.81 config model
xcit-large-24-p16_3rdparty_in1k* 189.10 35.86 config model
xcit-large-24-p16_3rdparty-dist_in1k* 189.10 35.86 config model
xcit-medium-24-p16_3rdparty-dist_in1k-384px* 84.40 47.39 config model
xcit-small-12-p8_3rdparty-dist_in1k-384px* 26.21 54.92 config model
xcit-medium-24-p8_3rdparty_in1k* 84.32 63.52 config model
xcit-medium-24-p8_3rdparty-dist_in1k* 84.32 63.52 config model
xcit-small-24-p8_3rdparty-dist_in1k-384px* 47.63 105.24 config model
xcit-large-24-p16_3rdparty-dist_in1k-384px* 189.10 105.35 config model
xcit-large-24-p8_3rdparty_in1k* 188.93 141.23 config model
xcit-large-24-p8_3rdparty-dist_in1k* 188.93 141.23 config model
xcit-medium-24-p8_3rdparty-dist_in1k-384px* 84.32 186.67 config model
xcit-large-24-p8_3rdparty-dist_in1k-384px* 188.93 415.00 config model

Models with * are converted from the official repo. The config files of these models are only for inference. We haven't reproduce the training results.

Citation

@article{el2021xcit,
  title={XCiT: Cross-Covariance Image Transformers},
  author={El-Nouby, Alaaeldin and Touvron, Hugo and Caron, Mathilde and Bojanowski, Piotr and Douze, Matthijs and Joulin, Armand and Laptev, Ivan and Neverova, Natalia and Synnaeve, Gabriel and Verbeek, Jakob and others},
  journal={arXiv preprint arXiv:2106.09681},
  year={2021}
}