# PiT

**类别：** ViT · **代码：** [`timm/models/pit.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/pit.py) · **架构：** 8 · **预训练权重：** 8（8 个具有 ImageNet-1k 结果）

基于池化的视觉 Transformer（PiT）在阶段之间使用深度卷积池化层来减小 token 的空间尺寸并增加通道数，这与 CNN 的做法相同。

## 论文

* [重新思考视觉 Transformer 的空间维度](https://arxiv.org/abs/2103.16302)

## 用法

请参阅[快速入门](../quickstart)了解如何加载预训练权重、进行图像预处理和微调，以及参阅[特征提取](../feature_extraction)了解如何将这些模型用作骨干网络。

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

## 模型 API 支持

| 功能 | `PoolingVisionTransformer` |
|---|---|
| [`features_only=True` 特征图](../model_api#intermediate-features) | ✓（步长 8、16、32） |
| [`forward_intermediates()`](../model_api#intermediate-features) | ✓ |
| [`prune_intermediate_layers()`](../model_api#intermediate-features) | ✓ |
| [任意输入尺寸，无需更改](../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) | ✗ |
| [逐层学习率衰减（`group_matcher()`）](../model_api#training-hooks) | ✗ |
| [`reset_classifier()`](../model_api#classifier) | ✓ |

✓ 支持，✓ (square) 仅支持方形尺寸，✗ 不支持，– 无需支持（模型本身已接受任意输入尺寸）。通过在每个功能上运行随机初始化的模型（`PoolingVisionTransformer` 使用 `pit_ti_224`，尺寸为 224）进行验证，预期同一类的其他架构表现相同。详情请参阅 [Model API](../model_api) 页面。

## 架构

| 架构 | 参数（M） | GMAC | 输入大小 | 预训练权重 |
|---|---:|---:|---:|---:|
| `pit_b_224` | 73.76 | 12.42 | 224 | 1 |
| `pit_b_distilled_224` | 74.79 | 12.50 | 224 | 1 |
| `pit_s_224` | 23.46 | 2.88 | 224 | 1 |
| `pit_s_distilled_224` | 24.04 | 2.90 | 224 | 1 |
| `pit_ti_224` | 4.85 | 0.70 | 224 | 1 |
| `pit_ti_distilled_224` | 5.10 | 0.71 | 224 | 1 |
| `pit_xs_224` | 10.62 | 1.40 | 224 | 1 |
| `pit_xs_distilled_224` | 11.00 | 1.41 | 224 | 1 |

GMACs 和参数量对应于每种架构的默认输入大小和分类器，数据来自[基准测试结果](https://github.com/huggingface/pytorch-image-models/tree/main/results)。

## 预训练权重

Top-1 是在所列评估规模下，来自 [`results-imagenet.csv`](https://github.com/huggingface/pytorch-image-models/blob/main/results/results-imagenet.csv) 的 ImageNet-1k 验证准确率，- 表示该权重没有 ImageNet-1k 结果（例如预训练权重或图文权重）。Classes 是预训练分类器的大小，对于没有分类器的权重则为无。

| 权重 | 输入大小 | Top-1（%） | 评估大小 | 类 | 许可证 | Hub |
|---|---:|---:|---:|---:|---|---|
| `pit_b_224.in1k` | 224 | 82.458 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/pit_b_224.in1k) |
| `pit_b_distilled_224.in1k` | 224 | 83.774 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/pit_b_distilled_224.in1k) |
| `pit_s_224.in1k` | 224 | 81.114 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/pit_s_224.in1k) |
| `pit_s_distilled_224.in1k` | 224 | 81.826 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/pit_s_distilled_224.in1k) |
| `pit_ti_224.in1k` | 224 | 72.926 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/pit_ti_224.in1k) |
| `pit_ti_distilled_224.in1k` | 224 | 74.276 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/pit_ti_distilled_224.in1k) |
| `pit_xs_224.in1k` | 224 | 78.196 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/pit_xs_224.in1k) |
| `pit_xs_distilled_224.in1k` | 224 | 79.172 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/pit_xs_distilled_224.in1k) |

