模型:
facebook/deit-base-distilled-patch16-224
任务:
许可:
Distilled data-efficient Image Transformer (DeiT)模型在ImageNet-1k(100万张图片,1000个类别)数据集上进行了预训练和微调,分辨率为224x224。它最早由Touvron等人在论文 Training data-efficient image transformers & distillation through attention 中提出,并在 this repository 中首次发布。然而,权重是由Ross Wightman从 timm repository 进行转换的。
免责声明:发布DeiT的团队没有为该模型编写模型卡片,因此本模型卡片由Hugging Face团队编写。
该模型是一种蒸馏的视觉Transformer(ViT)。它使用了一个蒸馏令牌,除了类别令牌之外,通过自注意层与教师(CNN)进行有效的学习,既在预训练过程中,也在微调过程中。蒸馏令牌通过与类别([CLS])和图块令牌之间的自注意层进行反向传播学习。
图像被呈现给模型时,作为固定尺寸图块的序列(分辨率16x16),这些图块被线性嵌入。
您可以使用原始模型进行图像分类。查看 model hub 以查找您感兴趣的任务的微调版本。
由于该模型是一个蒸馏的ViT模型,您可以将其插入到DeiTModel、DeiTForImageClassification或DeiTForImageClassificationWithTeacher中。请注意,模型期望使用DeiTFeatureExtractor准备数据。在这里,我们使用AutoFeatureExtractor,它会根据模型名称自动选择适当的特征提取器。
下面是如何使用该模型将COCO 2017数据集的图像分类为1000个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-base-distilled-patch16-224')
model = DeiTForImageClassificationWithTeacher.from_pretrained('facebook/deit-base-distilled-patch16-224')
inputs = feature_extractor(images=image, return_tensors="pt")
# forward pass
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万张图片和1k个类别。
有关训练/验证期间图像预处理的详细信息可以在 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}
}