🚀 蒸餾數據高效圖像Transformer(基礎大小模型)
Distilled Data-efficient Image Transformer(DeiT)模型在分辨率為224x224的情況下進行預訓練,並在ImageNet - 1k(100萬張圖像,1000個類別)上以384x384的分辨率進行微調。該模型由Touvron等人在論文 Training data-efficient image transformers & distillation through attention 中首次提出,並首次在 此倉庫 中發佈。不過,其權重是由Ross Wightman從 timm倉庫 轉換而來。
⚠️ 重要提示
發佈DeiT的團隊並未為此模型編寫模型卡片,此模型卡片由Hugging Face團隊編寫。
✨ 主要特性
- 該模型是一個蒸餾視覺Transformer(ViT),除了類別標記外,還使用蒸餾標記,能在預訓練和微調期間有效地從教師模型(CNN)中學習。
- 蒸餾標記通過反向傳播學習,通過自注意力層與類別([CLS])和補丁標記進行交互。
- 模型將圖像表示為固定大小的補丁序列(分辨率為16x16),並進行線性嵌入。
🚀 快速開始
你可以使用原始模型進行圖像分類。可查看 模型中心 以尋找針對你感興趣的任務進行微調的版本。
📦 安裝指南
文檔未提及安裝步驟,可參考相關依賴庫的官方文檔進行安裝,如transformers
、PIL
、requests
等。
💻 使用示例
基礎用法
以下是如何使用此模型將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-384')
model = DeiTForImageClassificationWithTeacher.from_pretrained('facebook/deit-base-distilled-patch16-384')
inputs = feature_extractor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
💡 使用建議
目前,特徵提取器和模型都支持PyTorch,Tensorflow和JAX/FLAX即將支持。
📚 詳細文檔
模型描述
此模型是一個蒸餾視覺Transformer(ViT)。除了類別標記外,它使用蒸餾標記,以便在預訓練和微調期間有效地從教師模型(CNN)中學習。蒸餾標記通過反向傳播學習,通過自注意力層與類別([CLS])和補丁標記進行交互。圖像以固定大小的補丁序列(分辨率為16x16)的形式呈現給模型,並進行線性嵌入。
預期用途和限制
你可以使用原始模型進行圖像分類。查看 模型中心 以尋找針對你感興趣的任務進行微調的版本。
訓練數據
該模型在 ImageNet - 1k 上進行預訓練和蒸餾微調,這是一個包含100萬張圖像和1000個類別的數據集。
訓練過程
預處理
訓練/驗證期間圖像預處理的確切細節可在 此處 找到。在推理時,圖像會被調整大小/重新縮放至相同的分辨率(438x438),在384x384處進行中心裁剪,並使用ImageNet的均值和標準差在RGB通道上進行歸一化。
預訓練
該模型在單個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許可證。