模型概述
模型特點
模型能力
使用案例
🚀 蒸餾數據高效圖像變換器(小型模型)
Distilled data-efficient Image Transformer(DeiT)模型在ImageNet - 1k(100萬張圖像,1000個類別)上以224x224的分辨率進行了預訓練和微調。它最初由Touvron等人在論文Training data-efficient image transformers & distillation through attention中提出,並首次在該倉庫發佈。不過,權重是由Ross Wightman從timm倉庫轉換而來。
免責聲明:發佈DeiT的團隊並未為該模型撰寫模型卡片,此模型卡片由Hugging Face團隊撰寫。
✨ 主要特性
- 該模型是一個蒸餾視覺變換器(ViT),除了類別令牌外,還使用蒸餾令牌,在預訓練和微調過程中能有效地從教師模型(CNN)中學習。
- 蒸餾令牌通過反向傳播學習,通過自注意力層與類別([CLS])和補丁令牌進行交互。
- 圖像以固定大小的補丁序列(分辨率16x16)呈現給模型,並進行線性嵌入。
📦 安裝指南
文檔未提及具體安裝步驟,跳過此章節。
💻 使用示例
基礎用法
由於該模型是蒸餾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-small-distilled-patch16-224')
model = DeiTForImageClassificationWithTeacher.from_pretrained('facebook/deit-small-distilled-patch16-224')
inputs = feature_extractor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
# 模型預測1000個ImageNet類別之一
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
目前,特徵提取器和模型都支持PyTorch。Tensorflow和JAX/FLAX即將支持。
📚 詳細文檔
預期用途和限制
你可以使用原始模型進行圖像分類。請查看模型中心,以查找針對你感興趣的任務進行微調的版本。
訓練數據
該模型在ImageNet - 1k上進行了預訓練和蒸餾微調,這是一個包含100萬張圖像和1000個類別的數據集。
訓練過程
預處理
訓練/驗證期間圖像預處理的確切細節可以在此處找到。
推理時,圖像會被調整/重新縮放至相同的分辨率(256x256),中心裁剪為224x224,並在RGB通道上使用ImageNet的均值和標準差進行歸一化。
預訓練
該模型在單個8 - GPU節點上訓練了3天。訓練分辨率為224。對於所有超參數(如批量大小和學習率),請參考原論文的表9。
評估結果
模型 | ImageNet top - 1準確率 | ImageNet top - 5準確率 | 參數數量 | URL |
---|---|---|---|---|
DeiT - tiny | 72.2 | 91.1 | 5M | https://huggingface.co/facebook/deit - tiny - patch16 - 224 |
DeiT - small | 79.9 | 95.0 | 22M | https://huggingface.co/facebook/deit - small - patch16 - 224 |
DeiT - base | 81.8 | 95.6 | 86M | https://huggingface.co/facebook/deit - base - patch16 - 224 |
DeiT - tiny distilled | 74.5 | 91.9 | 6M | https://huggingface.co/facebook/deit - tiny - distilled - patch16 - 224 |
DeiT - small distilled | 81.2 | 95.4 | 22M | https://huggingface.co/facebook/deit - small - distilled - patch16 - 224 |
DeiT - base distilled | 83.4 | 96.5 | 87M | https://huggingface.co/facebook/deit - base - distilled - patch16 - 224 |
DeiT - base 384 | 82.9 | 96.2 | 87M | https://huggingface.co/facebook/deit - base - patch16 - 384 |
DeiT - base distilled 384 (1000 epochs) | 85.2 | 97.2 | 88M | https://huggingface.co/facebook/deit - base - distilled - patch16 - 384 |
請注意,對於微調,使用更高的分辨率(384x384)可獲得最佳結果。當然,增加模型大小會帶來更好的性能。
BibTeX引用和引用信息
@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}
}
📄 許可證
本項目採用Apache - 2.0許可證。









