Skip to main content

Keras (TensorFlow v2) reimplementation of ViT models.

Project description

tfvit

Keras (TensorFlow v2) reimplementation of Vision Transformer model.

Installation

pip install tfvit

Examples

Default usage (without preprocessing):

from tfvit import ViTBase32384  # + 11 other variants and input preprocessing

model = ViTBase32384()  # by default will download imagenet[21k]-pretrained weights
model.compile(...)
model.fit(...)

Custom classification (with preprocessing):

from keras import layers, models
from tfvit import ViTBase32224

inputs = layers.Input(shape=(224, 224, 3), dtype='uint8')
outputs = ViTBase32224(include_top=False)(inputs)
outputs = layers.Dense(100, activation='softmax')(outputs)

model = models.Model(inputs=inputs, outputs=outputs)
model.compile(...)
model.fit(...)

Differences

Code simplification:

  • Pretrain input height and width are always equal
  • Patch height and width are always equal

Citation

@article{dosovitskiy2020vit,
  title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
  author={Dosovitskiy, Alexey and Beyer, Lucas and Kolesnikov, Alexander and Weissenborn, Dirk and Zhai, Xiaohua and Unterthiner, Thomas and  Dehghani, Mostafa and Minderer, Matthias and Heigold, Georg and Gelly, Sylvain and Uszkoreit, Jakob and Houlsby, Neil},
  journal={ICLR},
  year={2021}
}

@misc{darcet2023vitneedreg,
  title={Vision Transformers Need Registers},
  author={Darcet, Timothée and Oquab, Maxime and Mairal, Julien and Bojanowski, Piotr},
  journal={arXiv:2309.16588},
  year={2023}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfvit-1.1.2.tar.gz (10.6 kB view details)

Uploaded Source

File details

Details for the file tfvit-1.1.2.tar.gz.

File metadata

  • Download URL: tfvit-1.1.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for tfvit-1.1.2.tar.gz
Algorithm Hash digest
SHA256 718a8cd3c4d01a47fbd65bac53f6ffa2de7dca3e9de66d7ed70275f125dc62ce
MD5 17dc61c9301fa251f1a240a12582bf3c
BLAKE2b-256 572642223d0081e54aeb1f5bcfd98b001c7dfb36f4deed4b3e84abbb83e26f75

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page