Vision Transformer Pytorch
This project is modified from lukemelas/EfficientNet-PyTorch and asyml/vision-transformer-pytorch to provide out-of-box API for you to utilize VisionTransformer as easy as EfficientNet.
Quickstart
Install with pip install vision_transformer_pytorch and load a pretrained VisionTransformer with:
from vision_transformer_pytorch import VisionTransformer
model = VisionTransformer.from_pretrained('ViT-B_16')
About Vision Transformer PyTorch
Vision Transformer Pytorch is a PyTorch re-implementation of Vision Transformer based on one of the best practice of commonly utilized deep learning libraries, EfficientNet-PyTorch, and an elegant implement of VisionTransformer, vision-transformer-pytorch. In this project, we aim to make our PyTorch implementation as simple, flexible, and extensible as possible.
If you have any feature requests or questions, feel free to leave them as GitHub issues!
Installation
Install via pip:
pip install vision_transformer_pytorch
Or install from source:
git clone https://github.com/tczhangzhi/VisionTransformer-Pytorch
cd VisionTransformer-Pytorch
pip install -e .
Usage
Loading pretrained models
Load an EfficientNet:
from vision_transformer_pytorch import VisionTransformer
model = VisionTransformer.from_name('ViT-B_16')
Load a pretrained EfficientNet:
from vision_transformer_pytorch import VisionTransformer
model = VisionTransformer.from_pretrained('ViT-B_16')
# inputs = torch.randn(1, 3, *model.image_size)
# model(inputs)
# model.extract_features(inputs)
Default hyper parameters:
| Param\Model | ViT-B_16 | ViT-B_32 | ViT-L_16 | ViT-L_32 | R50+ViT-B_16 |
|---|---|---|---|---|---|
| image_size | 384 | 384 | 384 | 384 | 384 |
| patch_size | 16 | 32 | 16 | 32 | 1 |
| emb_dim | 768 | 768 | 1024 | 1024 | 768 |
| mlp_dim | 3072 | 3072 | 4096 | 4096 | 3072 |
| num_heads | 12 | 12 | 16 | 16 | 12 |
| num_layers | 12 | 12 | 24 | 24 | 12 |
| num_classes | 1000 | 1000 | 1000 | 1000 | 1000 |
| attn_dropout_rate | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| dropout_rate | 0.1 | 0.1 | 0.1 | 0.1 | 0.1 |
If you need to modify these hyper parameters, please use:
from vision_transformer_pytorch import VisionTransformer
model = VisionTransformer.from_name('ViT-B_16', image_size=256, patch_size=64, ...)
ImageNet
See examples/imagenet for details about evaluating on ImageNet.
Contributing
If you find a bug, create a GitHub issue, or even better, submit a pull request. Similarly, if you have questions, simply post them as GitHub issues.
I look forward to seeing what the community does with these models!
Release files for vision-transformer-pytorch 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| vision_transformer_pytorch-1.0.3.tar.gz | 10.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vision_transformer_pytorch-1.0.3-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 23.9 kB
Release files / vision_transformer_pytorch-1.0.3.tar.gz
| Download URL | vision_transformer_pytorch-1.0.3.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
820597ecc56f02362c82e74f0a9e4434052c2166383bac8535b78162c485bf55
|
|
BLAKE2b-256 checksum How to use checksums |
f77a6a66b49cfca9b767cbef24c13dcd1bd2236b181e040b5e45ceb7afb1f17e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
|
Release files / vision_transformer_pytorch-1.0.3-py2.py3-none-any.whl
| Download URL | vision_transformer_pytorch-1.0.3-py2.py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0652e15527e87d4ce34d5e07153adf596f7570ccf05b45ec274c4968f3311fee
|
|
BLAKE2b-256 checksum How to use checksums |
af28b781e01992e2ad2271f0a89c5a813a7e5bd758af0a45105a06c5ecf0bdb0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
|