🚀 蒸留型データ効率の高い画像トランスフォーマー(小型モデル)
蒸留型データ効率の高い画像トランスフォーマー(DeiT)モデルは、解像度224x224のImageNet - 1k(100万枚の画像、1,000クラス)で事前学習および微調整されています。このモデルは、Touvronらによる論文 Training data-efficient image transformers & distillation through attention で初めて紹介され、このリポジトリ で最初に公開されました。ただし、重みはRoss Wightmanによる timmリポジトリ から変換されたものです。
免責事項: DeiTを公開したチームはこのモデルのモデルカードを作成していないため、このモデルカードはHugging Faceチームによって作成されました。
🚀 クイックスタート
このモデルは、蒸留型のVision Transformer(ViT)です。事前学習と微調整の両方の段階で、教師モデル(CNN)から効果的に学習するために、クラストークンに加えて蒸留トークンを使用します。蒸留トークンは、自己注意層を通じてクラス([CLS])とパッチトークンと相互作用することで、誤差逆伝播により学習されます。
✨ 主な機能
- 蒸留トークンを使用して、教師モデル(CNN)から効果的に学習します。
- 画像を固定サイズのパッチ(解像度16x16)のシーケンスとしてモデルに入力し、線形埋め込みを行います。
📚 ドキュメント
モデルの説明
このモデルは蒸留型のVision Transformer(ViT)です。クラストークンに加えて蒸留トークンを使用し、事前学習と微調整の両方の段階で教師モデル(CNN)から効果的に学習します。蒸留トークンは、自己注意層を通じてクラス([CLS])とパッチトークンと相互作用することで、誤差逆伝播により学習されます。
画像は固定サイズのパッチ(解像度16x16)のシーケンスとしてモデルに入力され、線形埋め込みが行われます。
想定される用途と制限
生のモデルを画像分類に使用することができます。関心のあるタスクで微調整されたバージョンを探すには、モデルハブ を参照してください。
使い方
このモデルは蒸留型のViTモデルなので、DeiTModel、DeiTForImageClassification、またはDeiTForImageClassificationWithTeacherに組み込むことができます。ただし、モデルはDeiTFeatureExtractorを使用してデータが準備されることを期待しています。ここではAutoFeatureExtractorを使用しており、モデル名に応じて適切な特徴抽出器を自動的に使用します。
以下は、このモデルを使用してCOCO 2017データセットの画像を1,000の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
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
現在、特徴抽出器とモデルの両方がPyTorchをサポートしています。TensorflowとJAX/FLAXは近日対応予定です。
学習データ
このモデルは、ImageNet - 1k(100万枚の画像と1,000クラスからなるデータセット)で事前学習および蒸留による微調整が行われました。
学習手順
前処理
学習/検証時の画像の前処理の正確な詳細は、ここ で確認できます。
推論時には、画像は同じ解像度(256x256)にリサイズ/リスケールされ、224x224で中央切り抜きされ、ImageNetの平均と標準偏差を使用してRGBチャネル全体で正規化されます。
事前学習
モデルは、単一の8GPUノードで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 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エポック) |
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ライセンスの下で提供されています。