lucidrains/vit-pytorch

Implementation of Vision Transformer, a simple way to achieve SOTA in vision classification with only a single transformer encoder, in Pytorch

What it solves

This project provides a comprehensive PyTorch implementation of the Vision Transformer (ViT) and a wide array of its subsequent architectural variants. It allows researchers and developers to easily integrate state-of-the-art vision classification models that use transformer encoders instead of traditional convolutional neural networks.

How it works

The library implements the core ViT architecture—which treats images as sequences of patches for processing by a transformer—and extends this to numerous specialized versions. These variants include optimizations for training speed (Simple ViT), handling variable image resolutions (NaViT), knowledge distillation from convolutional networks (DistillableViT), and hybrid models that mix convolutions with attention (CvT, LeViT).

Who it’s for

It is designed for machine learning engineers and AI researchers working on computer vision tasks, specifically those looking to experiment with different transformer-based image classification architectures without implementing them from scratch.

Highlights

  • Extensive Variant Library: Includes implementations of NaViT, CaiT, CrossViT, PiT, LeViT, CvT, Twins SVT, and more.
  • Flexible Training: Supports advanced techniques like distillation tokens for transferring knowledge from teacher models to students.
  • Variable Resolution Support: NaViT implementation allows training on images of multiple resolutions packed into a single batch.
  • SOTA Architectures: Implements modern improvements such as 2D sinusoidal positional embeddings and global average pooling.

Related

  • Project
  • Project
  • Project
  • Dispatch
  • Project