timm documentation
LeViT
快速入门
教程
模型页面
模型系列结果
卷积网络
视觉 Transformer
混合卷积 / 注意力网络
BYOANet(BoTNet、HaloNet、LambdaNet)CoaTCSATv2FocalNet混合视觉 TransformerLeViTMaxViT 和 CoAtNetMetaFormer(PoolFormer、ConvFormer、CAFormer)Next-ViTTinyViTVisformerViTamin
高效与移动网络
MLP 及其他 token 混合器
多模态模型的视觉编码器
参考
LeViT
类别: 混合 · 代码: timm/models/levit.py · 架构: 20 · 预训练权重: 10(10 个具有 ImageNet-1k 结果)
LeViT 是一种用于快速推理的混合网络,其结构由一个卷积茎部(convolutional stem)和若干注意力阶段组成,这些阶段通过基于注意力的下采样来降低分辨率,并利用注意力偏置来表示位置信息。
论文
用法
请参阅快速入门了解如何加载预训练权重、进行图像预处理和微调,以及查阅特征提取了解如何将模型用作骨干网络。
>>> import timm
>>> model = timm.create_model('levit_256.fb_dist_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)模型 API 支持
| 功能 | Levit | LevitDistilled |
|---|---|---|
features_only=True 特征图 | ✓(步长 16、32、64) | ✓(步长 16、32、64) |
forward_intermediates() | ✓ | ✓ |
prune_intermediate_layers() | ✓ | ✓ |
| 任意输入尺寸,无需更改 | ✗ | ✗ |
set_input_size() | ✗ | ✗ |
dynamic_img_size=True | ✗ | ✗ |
set_grad_checkpointing() | ✓ | ✓ |
逐层学习率衰减(group_matcher()) | ✓ | ✓ |
reset_classifier() | ✓ | ✓ |
✓ 支持,✓ (square) 仅支持方形尺寸,✗ 不支持,– 无需支持(模型本身已接受任意输入
尺寸)。通过在每个功能上运行随机初始化的模型(Levit 使用 levit_256d 在 224 上,LevitDistilled 使用 levit_128s 在 224 上)进行验证,同一类的其他架构预计表现相同。有关详细信息,请参阅
Model API 页面。
架构
| 架构 | 类 | 参数(M) | GMAC | 输入大小 | 预训练权重 |
|---|---|---|---|---|---|
levit_128 | LevitDistilled | 9.19 | 0.41 | 224 | 1 |
levit_128s | LevitDistilled | 7.76 | 0.30 | 224 | 1 |
levit_192 | LevitDistilled | 10.92 | 0.66 | 224 | 1 |
levit_256 | LevitDistilled | 18.86 | 1.13 | 224 | 1 |
levit_256d | Levit | 26.16 | 1.39 | 224 | 0 |
levit_384 | LevitDistilled | 39.07 | 2.35 | 224 | 1 |
levit_384_s8 | LevitDistilled | 39.06 | 9.95 | 224 | 0 |
levit_512 | Levit | 95.08 | 5.62 | 224 | 0 |
levit_512_s8 | Levit | 73.97 | 21.77 | 224 | 0 |
levit_512d | Levit | 92.39 | 5.84 | 224 | 0 |
levit_conv_128 | LevitDistilled | 9.19 | 0.41 | 224 | 1 |
levit_conv_128s | LevitDistilled | 7.76 | 0.30 | 224 | 1 |
levit_conv_192 | LevitDistilled | 10.92 | 0.66 | 224 | 1 |
levit_conv_256 | LevitDistilled | 18.86 | 1.13 | 224 | 1 |
levit_conv_256d | Levit | 26.16 | 1.39 | 224 | 0 |
levit_conv_384 | LevitDistilled | 39.07 | 2.35 | 224 | 1 |
levit_conv_384_s8 | LevitDistilled | 39.06 | 9.95 | 224 | 0 |
levit_conv_512 | Levit | 95.08 | 5.62 | 224 | 0 |
levit_conv_512_s8 | Levit | 73.97 | 21.77 | 224 | 0 |
levit_conv_512d | Levit | 92.39 | 5.84 | 224 | 0 |
GMACs 和参数量对应于每种架构的默认输入大小和分类器,数据来自基准测试结果。
预训练权重
Top-1 是 results-imagenet.csv 中在所列评估规模下的 ImageNet-1k 验证准确率,- 表示该权重没有 ImageNet-1k 结果(例如预训练权重或图文权重)。Classes 是预训练分类器的大小,对于没有分类器的权重则为 none。
| 权重 | 输入大小 | Top-1(%) | 评估大小 | 类 | 许可证 | Hub |
|---|---|---|---|---|---|---|
levit_128.fb_dist_in1k | 224 | 78.486 | 224 | 1000 | apache-2.0 | timm |
levit_128s.fb_dist_in1k | 224 | 76.520 | 224 | 1000 | apache-2.0 | timm |
levit_192.fb_dist_in1k | 224 | 79.858 | 224 | 1000 | apache-2.0 | timm |
levit_256.fb_dist_in1k | 224 | 81.506 | 224 | 1000 | apache-2.0 | timm |
levit_384.fb_dist_in1k | 224 | 82.600 | 224 | 1000 | apache-2.0 | timm |
levit_conv_128.fb_dist_in1k | 224 | 78.488 | 224 | 1000 | apache-2.0 | timm |
levit_conv_128s.fb_dist_in1k | 224 | 76.534 | 224 | 1000 | apache-2.0 | timm |
levit_conv_192.fb_dist_in1k | 224 | 79.860 | 224 | 1000 | apache-2.0 | timm |
levit_conv_256.fb_dist_in1k | 224 | 81.506 | 224 | 1000 | apache-2.0 | timm |
levit_conv_384.fb_dist_in1k | 224 | 82.600 | 224 | 1000 | apache-2.0 | timm |
引用
@article{graham2021levit,
title={LeViT: a Vision Transformer in ConvNet's Clothing for Faster Inference},
author={Benjamin Graham and Alaaeldin El-Nouby and Hugo Touvron and Pierre Stock and Armand Joulin and Herv'e J'egou and Matthijs Douze},
journal={arXiv preprint arXiv:2104.01136},
year={2021}
}