🚀 蒸留型データ効率の良い画像トランスフォーマー (ベースサイズのモデル)
このモデルは、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チームによって作成されています。
🚀 クイックスタート
このモデルは、蒸留型のVision Transformer (ViT) です。事前学習と微調整の両方の過程で、クラストークンに加えて蒸留トークンを使用し、教師モデル (CNN) から効果的に学習します。蒸留トークンは、自己注意層を介してクラス ([CLS]) トークンとパッチトークンと相互作用することで、誤差逆伝播によって学習されます。
✨ 主な機能
- 蒸留トークンを使用して、教師モデルから効果的に学習することができます。
- 画像を固定サイズのパッチ (解像度16x16) のシーケンスとしてモデルに入力し、線形埋め込みを行います。
📚 ドキュメント
モデルの説明
このモデルは蒸留型のVision Transformer (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-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])
現在、特徴抽出器とモデルの両方がPyTorchをサポートしています。TensorflowとJAX/FLAXのサポートも近日追加予定です。
学習データ
このモデルは、ImageNet-1k (100万枚の画像と1000クラスから構成されるデータセット) で事前学習および蒸留による微調整が行われています。
学習手順
前処理
学習/検証時の画像の前処理の詳細は、ここ で確認できます。
推論時には、画像は同じ解像度 (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 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ライセンスの下で提供されています。