🚀 蒸餾數據高效圖像轉換器(基礎大小模型)
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)形式呈現給模型,並進行線性嵌入。
📦 安裝指南
文檔未提及安裝步驟,故跳過此章節。
💻 使用示例
基礎用法
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")
outputs = model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
高級用法
文檔未提及高級用法相關代碼示例,故跳過此部分。
📚 詳細文檔
模型描述
該模型是一個蒸餾視覺變換器(ViT)。除了類別標記外,它使用一個蒸餾標記,在預訓練和微調過程中都能有效地從教師模型(CNN)中學習。蒸餾標記通過反向傳播學習,通過自注意力層與類別([CLS])和補丁標記進行交互。
圖像以固定大小的補丁序列(分辨率16x16)形式呈現給模型,並進行線性嵌入。
預期用途和限制
你可以使用原始模型進行圖像分類。訪問模型中心,查找針對你感興趣的任務進行微調的版本。
訓練數據
該模型在ImageNet - 1k上進行了預訓練和微調,這是一個包含100萬張圖像和1000個類別的數據集。
訓練過程
預處理
訓練/驗證期間圖像預處理的確切細節可在此處找到。
在推理時,圖像會被調整大小/重新縮放至相同的分辨率(256x256),中心裁剪為224x224,並使用ImageNet的均值和標準差在RGB通道上進行歸一化。
預訓練
該模型在單個8 - GPU節點上訓練了3天。訓練分辨率為224。有關所有超參數(如批量大小和學習率),請參考原論文的表9。
評估結果
屬性 |
詳情 |
模型類型 |
蒸餾數據高效圖像轉換器(DeiT) |
訓練數據 |
ImageNet - 1k(100萬張圖像,1000個類別) |
模型 |
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許可證。