|
--- |
|
license: apache-2.0 |
|
tags: |
|
- vision |
|
datasets: |
|
- imagenet-21k |
|
inference: false |
|
--- |
|
|
|
# Vision Transformer (large-sized model) |
|
|
|
Vision Transformer (ViT) model pre-trained on ImageNet-21k (14 million images, 21,843 classes) at resolution 512x512. It was introduced in the paper [An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale](https://arxiv.org/abs/2010.11929) by Dosovitskiy et al. and first released in [this repository](https://github.com/google-research/vision_transformer). However, this model is contributed by the Kakao Brain team and the weights were converted from their TensorFlow implementation to PyTorch by Alara Dirik. |
|
|
|
|
|
## Model description |
|
|
|
The Vision Transformer (ViT) is a transformer encoder model (BERT-like) pretrained on a large collection of images in a supervised fashion, namely ImageNet-21k, at a resolution of 512x512 pixels. |
|
|
|
Images are presented to the model as a sequence of fixed-size patches (resolution 16x16), which are linearly embedded. One also adds a [CLS] token to the beginning of a sequence to use it for classification tasks. One also adds absolute position embeddings before feeding the sequence to the layers of the Transformer encoder. |
|
|
|
Note that this model is contributed by Kakao Brain and trained on the downstream image classification task. |
|
|
|
|
|
## Intended uses & limitations |
|
|
|
You can use the raw model for image classification. See the [model hub](https://huggingface.co/models?search=google/vit) to look for |
|
fine-tuned versions on a task that interests you. |
|
|
|
### How to use |
|
|
|
Here is how to use this model in PyTorch: |
|
|
|
```python |
|
from transformers import ViTImageProcessor, ViTForImageClassification |
|
from PIL import Image |
|
import requests |
|
|
|
url = 'http://images.cocodataset.org/val2017/000000039769.jpg' |
|
image = Image.open(requests.get(url, stream=True).raw) |
|
|
|
processor = ViTImageProcessor.from_pretrained('kakaobrain/vit-large-patch16-512') |
|
model = ViTForImageClassification.from_pretrained('kakaobrain/vit-large-patch16-512') |
|
|
|
inputs = processor(images=image, return_tensors="pt") |
|
outputs = model(**inputs) |
|
logits = outputs.logits |
|
``` |
|
|
|
Refer to the [docs](https://huggingface.co/docs/transformers/model_doc/vit) for usage in TensorFlow and JAX/FLAX. |
|
|
|
## Training data |
|
|
|
The ViT model was pretrained on [ImageNet-21k](http://www.image-net.org/), a dataset consisting of 14 million images and 21k classes. |
|
|
|
## Training procedure |
|
|
|
### Preprocessing |
|
|
|
The exact details of preprocessing of images during training/validation can be found [here](https://github.com/google-research/vision_transformer/blob/master/vit_jax/input_pipeline.py). |
|
|
|
Images are resized/rescaled to the same resolution (512x512) and normalized across the RGB channels with mean (0.5, 0.5, 0.5) and standard deviation (0.5, 0.5, 0.5). |
|
|
|
### BibTeX entry and citation info |
|
|
|
```bibtex |
|
@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} |
|
} |
|
``` |
|
|
|
```bibtex |
|
@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} |
|
} |
|
``` |