🚀 蒸留型データ効率の良い画像トランスフォーマー (小型モデル)
蒸留型データ効率の良い画像トランスフォーマー(DeiT)モデルは、解像度224x224のImageNet-1k(100万枚の画像、1,000クラス)で事前学習および微調整されています。このモデルは、Touvronらによる論文 Training data-efficient image transformers & distillation through attention で初めて紹介され、このリポジトリ で最初に公開されました。ただし、重みはRoss Wightmanによる timmリポジトリ から変換されています。
免責事項:DeiTを公開したチームはこのモデルのモデルカードを作成していないため、このモデルカードはHugging Faceチームによって作成されています。
🚀 クイックスタート
このモデルは、画像分類に使用できます。関心のあるタスクで微調整されたバージョンを探すには、モデルハブ を参照してください。
✨ 主な機能
- ImageNet-1kで事前学習および微調整された蒸留型Vision Transformer(ViT)モデル。
- 蒸留トークンを使用して、教師モデル(CNN)から効果的に学習します。
- 画像を固定サイズのパッチ列としてモデルに入力し、線形埋め込みを行います。
📦 インストール
このモデルを使用するには、transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install transformers
💻 使用例
基本的な使用法
このモデルを使用して、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-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])
📚 ドキュメント
モデルの説明
このモデルは蒸留型のVision Transformer(ViT)です。クラストークンに加えて、蒸留トークンを使用して、事前学習と微調整の両方の過程で教師モデル(CNN)から効果的に学習します。蒸留トークンは、自己注意層を介してクラス([CLS])トークンとパッチトークンと相互作用することで、誤差逆伝播によって学習されます。
画像は固定サイズのパッチ列(解像度16x16)としてモデルに入力され、線形埋め込みが行われます。
想定される用途と制限
このモデルは、画像分類に使用できます。関心のあるタスクで微調整されたバージョンを探すには、モデルハブ を参照してください。
使い方
このモデルは蒸留型ViTモデルであるため、DeiTModel、DeiTForImageClassification、またはDeiTForImageClassificationWithTeacherに組み込むことができます。ただし、モデルはDeiTFeatureExtractorを使用してデータを準備することを想定しています。ここでは、AutoFeatureExtractorを使用します。これは、モデル名に基づいて適切な特徴抽出器を自動的に使用します。
学習データ
このモデルは、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 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ライセンスの下で公開されています。