Views
No views yet
1from transformers import AutoFeatureExtractor, DeiTForImageClassificationWithTeacher
2from PIL import Image
3import requests
4url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
5image = Image.open(requests.get(url, stream=True).raw)
6feature_extractor = AutoFeatureExtractor.from_pretrained('facebook/deit-tiny-distilled-patch16-224')
7model = DeiTForImageClassificationWithTeacher.from_pretrained('facebook/deit-tiny-distilled-patch16-224')
8inputs = feature_extractor(images=image, return_tensors="pt")
9outputs = model(**inputs)
10logits = outputs.logits
11# model predicts one of the 1000 ImageNet classes
12predicted_class_idx = logits.argmax(-1).item()
13print("Predicted class:", model.config.id2label[predicted_class_idx])| Model | ImageNet top-1 accuracy | ImageNet top-5 accuracy | # params | 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 |
1@misc{touvron2021training,
2 title={Training data-efficient image transformers & distillation through attention},
3 author={Hugo Touvron and Matthieu Cord and Matthijs Douze and Francisco Massa and Alexandre Sablayrolles and Hervé Jégou},
4 year={2021},
5 eprint={2012.12877},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV}
8}1@misc{wu2020visual,
2 title={Visual Transformers: Token-based Image Representation and Processing for Computer Vision},
3 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},
4 year={2020},
5 eprint={2006.03677},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV}
8}1@inproceedings{deng2009imagenet,
2 title={Imagenet: A large-scale hierarchical image database},
3 author={Deng, Jia and Dong, Wei and Socher, Richard and Li, Li-Jia and Li, Kai and Fei-Fei, Li},
4 booktitle={2009 IEEE conference on computer vision and pattern recognition},
5 pages={248--255},
6 year={2009},
7 organization={Ieee}
8}