模型:
facebook/deit-tiny-distilled-patch16-224
任务:
许可:
Distilled Data-efficient Image Transformer(DeiT)模型在ImageNet-1k(100万张图像,1,000个类别)上进行了预训练和微调,分辨率为224x224。它首先在Touvron等人的 Training data-efficient image transformers & distillation through attention 论文中提出,并在 this repository 中首次发布。然而,权重是由Ross Wightman从 timm repository 转换而来的。
免责声明:发布DeiT的团队没有为这个模型编写模型卡片,所以这个模型卡片是由Hugging Face团队编写的。
这个模型是一个蒸馏的Vision Transformer(ViT)。它使用蒸馏令牌(除了类别令牌)在预训练和微调过程中有效地从教师(CNN)中学习。蒸馏令牌通过自注意力层与类([CLS])和补丁令牌进行交互来进行反向传播学习。
图像以固定大小的补丁序列(分辨率为16x16)的形式呈现给模型,补丁被线性嵌入。
您可以使用原始模型进行图像分类。查看 model hub 以查找您感兴趣的任务的微调版本。
由于这个模型是一个蒸馏的ViT模型,您可以将其插入到DeiTModel、DeiTForImageClassification或DeiTForImageClassificationWithTeacher中。请注意,模型期望使用DeiTFeatureExtractor准备数据。这里我们使用AutoFeatureExtractor,它将自动根据模型名称使用适当的特征提取器。
下面是如何使用这个模型将COCO 2017数据集中的图像分类为1,000个ImageNet类别之一:
from transformers import AutoFeatureExtractor, DeiTForImageClassificationWithTeacher
from PIL import Image
import requests
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
feature_extractor = AutoFeatureExtractor.from_pretrained('facebook/deit-tiny-distilled-patch16-224')
model = DeiTForImageClassificationWithTeacher.from_pretrained('facebook/deit-tiny-distilled-patch16-224')
inputs = feature_extractor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
# model predicts one of the 1000 ImageNet classes
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
目前,特征提取器和模型都支持PyTorch。Tensorflow和JAX/FLAX即将推出。
这个模型是在 ImageNet-1k 上进行了蒸馏预训练和微调的,该数据集包含100万个图像和1,000个类别。
关于训练/验证期间图像的预处理的详细信息可以在 here 中找到。
推理时,图像被调整大小/缩放为相同的分辨率(256x256),居中裁剪为224x224,并使用ImageNet的均值和标准差在RGB通道上进行归一化。
该模型在单个8-GPU节点上进行了3天的训练。训练分辨率为224。关于所有超参数(如批量大小和学习率),我们参考原始论文的表9。
| Model | ImageNet top-1 accuracy | ImageNet top-5 accuracy | # params | URL |
|---|---|---|---|---|
| DeiT-tiny | 72.2 | 91.1 | 5M | 12310321 |
| DeiT-small | 79.9 | 95.0 | 22M | 12311321 |
| DeiT-base | 81.8 | 95.6 | 86M | 12312321 |
| DeiT-tiny distilled | 74.5 | 91.9 | 6M | 12313321 |
| DeiT-small distilled | 81.2 | 95.4 | 22M | 12314321 |
| DeiT-base distilled | 83.4 | 96.5 | 87M | 12315321 |
| DeiT-base 384 | 82.9 | 96.2 | 87M | 12316321 |
| DeiT-base distilled 384 (1000 epochs) | 85.2 | 97.2 | 88M | 12317321 |
请注意,对于微调,使用较高的分辨率(384x384)可以获得最佳结果。当然,增加模型大小将获得更好的性能。
@misc{touvron2021training,
title={Training data-efficient image transformers & distillation through attention},
author={Hugo Touvron and Matthieu Cord and Matthijs Douze and Francisco Massa and Alexandre Sablayrolles and Hervé Jégou},
year={2021},
eprint={2012.12877},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
@misc{wu2020visual,
title={Visual Transformers: Token-based Image Representation and Processing for Computer Vision},
author={Bichen Wu and Chenfeng Xu and Xiaoliang Dai and Alvin Wan and Peizhao Zhang and Zhicheng Yan and Masayoshi Tomizuka and Joseph Gonzalez and Kurt Keutzer and Peter Vajda},
year={2020},
eprint={2006.03677},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
@inproceedings{deng2009imagenet,
title={Imagenet: A large-scale hierarchical image database},
author={Deng, Jia and Dong, Wei and Socher, Richard and Li, Li-Jia and Li, Kai and Fei-Fei, Li},
booktitle={2009 IEEE conference on computer vision and pattern recognition},
pages={248--255},
year={2009},
organization={Ieee}
}