🚀 蒸餾數據高效圖像變換器(微型模型)
本項目是一個用於圖像分類的模型。該模型在 ImageNet-1k 數據集上進行預訓練和微調,能有效對圖像進行分類,為圖像分類任務提供了高效的解決方案。
🚀 快速開始
蒸餾數據高效圖像變換器(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)呈現給模型,並進行線性嵌入。
📦 安裝指南
文檔未提及安裝步驟,可參考相關依賴庫(如 transformers
)的官方安裝說明進行安裝。
💻 使用示例
基礎用法
以下是如何使用此模型將 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-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
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 處進行中心裁剪,並使用 ImageNet 的均值和標準差在 RGB 通道上進行歸一化。
預訓練
該模型在單個 8-GPU 節點上訓練了 3 天。訓練分辨率為 224。關於所有超參數(如批量大小和學習率),請參考原始論文的表 9。
評估結果
模型 |
ImageNet 前 1 準確率 |
ImageNet 前 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 蒸餾版 |
74.5 |
91.9 |
6M |
https://huggingface.co/facebook/deit-tiny-distilled-patch16-224 |
DeiT-small 蒸餾版 |
81.2 |
95.4 |
22M |
https://huggingface.co/facebook/deit-small-distilled-patch16-224 |
DeiT-base 蒸餾版 |
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 蒸餾版 384(1000 個 epoch) |
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 許可證。