# XCiT

**Category:** ViT · **Code:**
[`timm/models/xcit.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/xcit.py) ·
**Architectures:** 28 · **Pretrained weights:** 42 (42 with ImageNet-1k results)

Cross-Covariance Image Transformers (XCiT) replace token self-attention with cross-covariance attention across feature
channels, linear in the number of tokens, and add local patch interaction layers.

## Papers

* [XCiT: Cross-Covariance Image Transformers](https://arxiv.org/abs/2106.09681)

## Usage

See the [Quickstart](../quickstart) for loading pretrained weights, image preprocessing and fine-tuning, and [Feature
Extraction](../feature_extraction) for using the models as backbones.

```py
>>> import timm
>>> model = timm.create_model('xcit_small_12_p8_224.fb_dist_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)
```

## Model API support

| Feature | `Xcit` |
|---|---|
| [`features_only=True` feature maps](../model_api#intermediate-features) | ✓ (strides 8, 8, 8) |
| [`forward_intermediates()`](../model_api#intermediate-features) | ✓ |
| [`prune_intermediate_layers()`](../model_api#intermediate-features) | ✓ |
| [Any input size, no changes needed](../model_api#input-size) | ✓ |
| [`set_input_size()`](../model_api#input-size) | – |
| [`dynamic_img_size=True`](../model_api#input-size) | – |
| [`set_grad_checkpointing()`](../model_api#training-hooks) | ✓ |
| [Layer-wise LR decay (`group_matcher()`)](../model_api#training-hooks) | ✓ |
| [`reset_classifier()`](../model_api#classifier) | ✓ |

✓ supported, ✓ (square) works for square sizes only, ✗ not supported, – not needed (the model already accepts any input
size). Checked by running each feature on a randomly initialized model (`Xcit` with `xcit_nano_12_p8_224` at 224), other
architectures of the same class are expected to behave the same. See the [Model API](../model_api) page for details.

## Architectures

| Architecture | Params (M) | GMACs | Input size | Pretrained weights |
|---|---:|---:|---:|---:|
| `xcit_large_24_p8_224` | 188.93 | 141.23 | 224 | 2 |
| `xcit_large_24_p8_384` | 188.93 | 415.00 | 384 | 1 |
| `xcit_large_24_p16_224` | 189.10 | 35.86 | 224 | 2 |
| `xcit_large_24_p16_384` | 189.10 | 105.35 | 384 | 1 |
| `xcit_medium_24_p8_224` | 84.32 | 63.53 | 224 | 2 |
| `xcit_medium_24_p8_384` | 84.32 | 186.67 | 384 | 1 |
| `xcit_medium_24_p16_224` | 84.40 | 16.13 | 224 | 2 |
| `xcit_medium_24_p16_384` | 84.40 | 47.39 | 384 | 1 |
| `xcit_nano_12_p8_224` | 3.05 | 2.16 | 224 | 2 |
| `xcit_nano_12_p8_384` | 3.05 | 6.34 | 384 | 1 |
| `xcit_nano_12_p16_224` | 3.05 | 0.56 | 224 | 2 |
| `xcit_nano_12_p16_384` | 3.05 | 1.64 | 384 | 1 |
| `xcit_small_12_p8_224` | 26.21 | 18.69 | 224 | 2 |
| `xcit_small_12_p8_384` | 26.21 | 54.92 | 384 | 1 |
| `xcit_small_12_p16_224` | 26.25 | 4.82 | 224 | 2 |
| `xcit_small_12_p16_384` | 26.25 | 14.14 | 384 | 1 |
| `xcit_small_24_p8_224` | 47.63 | 35.81 | 224 | 2 |
| `xcit_small_24_p8_384` | 47.63 | 105.24 | 384 | 1 |
| `xcit_small_24_p16_224` | 47.67 | 9.10 | 224 | 2 |
| `xcit_small_24_p16_384` | 47.67 | 26.72 | 384 | 1 |
| `xcit_tiny_12_p8_224` | 6.71 | 4.81 | 224 | 2 |
| `xcit_tiny_12_p8_384` | 6.71 | 14.13 | 384 | 1 |
| `xcit_tiny_12_p16_224` | 6.72 | 1.24 | 224 | 2 |
| `xcit_tiny_12_p16_384` | 6.72 | 3.64 | 384 | 1 |
| `xcit_tiny_24_p8_224` | 12.11 | 9.21 | 224 | 2 |
| `xcit_tiny_24_p8_384` | 12.11 | 27.05 | 384 | 1 |
| `xcit_tiny_24_p16_224` | 12.12 | 2.34 | 224 | 2 |
| `xcit_tiny_24_p16_384` | 12.12 | 6.87 | 384 | 1 |

GMACs and parameter counts are for the default input size and classifier of each architecture, from the [benchmark
results](https://github.com/huggingface/pytorch-image-models/tree/main/results).

## Pretrained weights

Top-1 is ImageNet-1k validation accuracy from
[`results-imagenet.csv`](https://github.com/huggingface/pytorch-image-models/blob/main/results/results-imagenet.csv) at
the listed eval size, - if the weight has no ImageNet-1k result (e.g. pretraining or image-text weights). Classes is the
size of the pretrained classifier, none for weights without one.

| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---:|---:|---:|---:|---|---|
| `xcit_large_24_p8_224.fb_dist_in1k` | 224 | 85.396 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_large_24_p8_224.fb_dist_in1k) |
| `xcit_large_24_p8_224.fb_in1k` | 224 | 84.380 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_large_24_p8_224.fb_in1k) |
| `xcit_large_24_p8_384.fb_dist_in1k` | 384 | 86.024 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_large_24_p8_384.fb_dist_in1k) |
| `xcit_large_24_p16_224.fb_dist_in1k` | 224 | 84.936 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_large_24_p16_224.fb_dist_in1k) |
| `xcit_large_24_p16_224.fb_in1k` | 224 | 82.886 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_large_24_p16_224.fb_in1k) |
| `xcit_large_24_p16_384.fb_dist_in1k` | 384 | 85.778 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_large_24_p16_384.fb_dist_in1k) |
| `xcit_medium_24_p8_224.fb_dist_in1k` | 224 | 85.078 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_medium_24_p8_224.fb_dist_in1k) |
| `xcit_medium_24_p8_224.fb_in1k` | 224 | 83.744 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_medium_24_p8_224.fb_in1k) |
| `xcit_medium_24_p8_384.fb_dist_in1k` | 384 | 85.842 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_medium_24_p8_384.fb_dist_in1k) |
| `xcit_medium_24_p16_224.fb_dist_in1k` | 224 | 84.292 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_medium_24_p16_224.fb_dist_in1k) |
| `xcit_medium_24_p16_224.fb_in1k` | 224 | 82.630 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_medium_24_p16_224.fb_in1k) |
| `xcit_medium_24_p16_384.fb_dist_in1k` | 384 | 85.434 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_medium_24_p16_384.fb_dist_in1k) |
| `xcit_nano_12_p8_224.fb_dist_in1k` | 224 | 76.330 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_nano_12_p8_224.fb_dist_in1k) |
| `xcit_nano_12_p8_224.fb_in1k` | 224 | 73.900 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_nano_12_p8_224.fb_in1k) |
| `xcit_nano_12_p8_384.fb_dist_in1k` | 384 | 77.810 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_nano_12_p8_384.fb_dist_in1k) |
| `xcit_nano_12_p16_224.fb_dist_in1k` | 224 | 72.318 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_nano_12_p16_224.fb_dist_in1k) |
| `xcit_nano_12_p16_224.fb_in1k` | 224 | 69.982 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_nano_12_p16_224.fb_in1k) |
| `xcit_nano_12_p16_384.fb_dist_in1k` | 384 | 75.460 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_nano_12_p16_384.fb_dist_in1k) |
| `xcit_small_12_p8_224.fb_dist_in1k` | 224 | 84.252 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_12_p8_224.fb_dist_in1k) |
| `xcit_small_12_p8_224.fb_in1k` | 224 | 83.354 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_12_p8_224.fb_in1k) |
| `xcit_small_12_p8_384.fb_dist_in1k` | 384 | 85.068 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_12_p8_384.fb_dist_in1k) |
| `xcit_small_12_p16_224.fb_dist_in1k` | 224 | 83.354 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_12_p16_224.fb_dist_in1k) |
| `xcit_small_12_p16_224.fb_in1k` | 224 | 81.982 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_12_p16_224.fb_in1k) |
| `xcit_small_12_p16_384.fb_dist_in1k` | 384 | 84.734 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_12_p16_384.fb_dist_in1k) |
| `xcit_small_24_p8_224.fb_dist_in1k` | 224 | 84.878 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_24_p8_224.fb_dist_in1k) |
| `xcit_small_24_p8_224.fb_in1k` | 224 | 83.854 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_24_p8_224.fb_in1k) |
| `xcit_small_24_p8_384.fb_dist_in1k` | 384 | 85.580 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_24_p8_384.fb_dist_in1k) |
| `xcit_small_24_p16_224.fb_dist_in1k` | 224 | 83.880 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_24_p16_224.fb_dist_in1k) |
| `xcit_small_24_p16_224.fb_in1k` | 224 | 82.588 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_24_p16_224.fb_in1k) |
| `xcit_small_24_p16_384.fb_dist_in1k` | 384 | 85.102 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_small_24_p16_384.fb_dist_in1k) |
| `xcit_tiny_12_p8_224.fb_dist_in1k` | 224 | 81.214 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_12_p8_224.fb_dist_in1k) |
| `xcit_tiny_12_p8_224.fb_in1k` | 224 | 79.710 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_12_p8_224.fb_in1k) |
| `xcit_tiny_12_p8_384.fb_dist_in1k` | 384 | 82.394 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_12_p8_384.fb_dist_in1k) |
| `xcit_tiny_12_p16_224.fb_dist_in1k` | 224 | 78.572 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_12_p16_224.fb_dist_in1k) |
| `xcit_tiny_12_p16_224.fb_in1k` | 224 | 77.122 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_12_p16_224.fb_in1k) |
| `xcit_tiny_12_p16_384.fb_dist_in1k` | 384 | 80.954 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_12_p16_384.fb_dist_in1k) |
| `xcit_tiny_24_p8_224.fb_dist_in1k` | 224 | 82.578 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_24_p8_224.fb_dist_in1k) |
| `xcit_tiny_24_p8_224.fb_in1k` | 224 | 81.888 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_24_p8_224.fb_in1k) |
| `xcit_tiny_24_p8_384.fb_dist_in1k` | 384 | 83.784 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_24_p8_384.fb_dist_in1k) |
| `xcit_tiny_24_p16_224.fb_dist_in1k` | 224 | 80.462 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_24_p16_224.fb_dist_in1k) |
| `xcit_tiny_24_p16_224.fb_in1k` | 224 | 79.474 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_24_p16_224.fb_in1k) |
| `xcit_tiny_24_p16_384.fb_dist_in1k` | 384 | 82.580 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/xcit_tiny_24_p16_384.fb_dist_in1k) |

