Add Vision Transformer + ViTFeatureExtractor
Author: NielsRogge
Pull request: yes

# What does this PR do?

This PR includes 2 things:

* it adds the [Vision Transformer (ViT)](https://arxiv.org/abs/2010.11929) by Google Brain. ViT is a Transformer encoder trained on ImageNet. It is capable of classifying images, by placing a linear classification head on top of the final hidden state of the [CLS] token. I converted the weights from the [timm](https://github.com/rwightman/pytorch-image-models) repository, which already took care of converting the weights of the original implementation (which is written in JAX) into PyTorch. Once this model is added, we can also add [DeIT](https://ai.facebook.com/blog/data-efficient-image-transformers-a-promising-new-technique-for-image-classification/) (Data-efficient Image Transformers) by Facebook AI, which improve upon ViT. 

* it provides a design for the `ViTFeatureExtractor` class, which can be used to prepare images for the model. It inherits from `FeatureExtractionMixin` and defines a `__call__` method. It currently accepts 3 types of inputs: PIL images, Numpy arrays and PyTorch tensors. It defines 2 transformations using `torchvision`: resizing + normalization. It then returns a `BatchFeature` object with 1 key, namely `pixel_values`. 

Demo notebook of combination of `ViTForImageClassification` + `ViTFeatureExtractor`: https://colab.research.google.com/drive/16TCM-tJ1Mfhs00Qas063kWZmAtVJcOeP?usp=sharing

Compared to NLP models (which accept `input_ids`, `attention_mask` and `token_type_ids`), this model only accepts `pixel_values`. The model itself then converts these pixel values into patches (in case of ViT) in the `ViTEmbeddings` class. 

## Help needed

Would be great if you can help me with the following tasks:

- [x] Add and improve tests. Currently I have defined the following tests: `test_modeling_vit.py`, `test_feature_extraction_vit.py`. However, for the former, since ViT does not use `input_ids`/`input_embeds`, some tests are failing, so I wonder whether it should use all tests defined in `test_modeling_common.py`. For the latter, I also need some help in creating random inputs to test the feature extractor on. 
- [x] Add support for `head_mask` in the forward of `ViTModel`. Possibly remove `attention_mask`?
- [x] Run `make fix-copies` (doesn't work right now for me on Windows)
- [x] Remove the `is_decoder` logic from `modeling_vit.py` (since the model was created using the CookieCutter template). I assume that things such as `past_key_values` are not required for an encoder-only model. 

## Who can review?

@patrickvonplaten @LysandreJik @sgugger 





Comments:
Hey @NielsRogge 


> Add and improve tests. Currently I have defined the following tests: test_modeling_vit.py, test_feature_extraction_vit.py. However, for the former, since ViT does not use input_ids/input_embeds, some tests are failing, so I wonder whether it should use all tests defined in test_modeling_common.py. For the latter, I also need some help in creating random inputs to test the feature extractor on.


Some common modeling test depend on the specific parameter names, (`input_ids`, `input_embeds`). You could just override such tests in your test class and use the correct parameter names. For example  the `test_forward_signature` test
expects `inputs_ids`, so it should be overridden in your class to expect `input_values`.  

Also, the tests for `input_embeds` (for example `test_inputs_embeds`) can be skipped since `ViT` does not use those.  Agin just overrides the test and use `pass` in the method body.

You could use the modeling tests of `Wav2Vec2` and `Speech2Text` for reference since those models also use different parameter names.

I like the overall design `ViTFeatureExtractor`. Regrading the import `ViTFeatureExtractor`
I think it should be always imported in the __init__ files, and instead, `ViTFeatureExtractor`  could check for `torchvision` and raise if it’s not installed. Otherwise, the TF tests on CI will fail because they won’t be able to import `ViTFeatureExtractor`  as we don’t install `torchvision` in TF tests.

We should also add the `torchvision` and `PIL`  dependency in the setup.py file as `extras["vision"]` and also add it in `config.yaml` for CI

Thanks for the reviews, addressed most of the comments. To do:

- [x] rename `self.self` to `self.attention` and update conversion script accordingly
- [x] convert more models, place them under the google namespace
- [x] add model cards
- [x] add 1,000 ImageNet class names to config

I've addressed all comments. Most important updates:

* moved the ImageNet id to classes dict to a new file under transformers.utils named `imagenet_classes`.py.
* added a warning to the `__call__` method of `ViTFeatureExtractor` to indicate that NumPy arrays and PyTorch tensors are converted to PIL images when resizing, so it's most efficient to pass in PIL images.  

The remaining comments which are still open have to do with styling. I seem to have some issues with `make style`. The max_length is set to 119, so not sure what's causing this.