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 collection of PyTorch implementations for Vision Transformers (ViT) and their many variants. It simplifies the process of experimenting with state-of-the-art computer vision architectures that use transformer encoders for image classification and feature processing.

How it works

The library offers modular, ready-to-use implementations of various ViT architectures. Users can import specific models (like ViT, SimpleViT, or NaViT) and configure them via parameters such as image size, patch size, depth, and attention heads. The code handles the underlying tensor transformations, allowing users to pass image tensors directly into the model to receive classification predictions.

Who it’s for

It is designed for researchers and machine learning engineers who want to quickly implement, test, or compare different Vision Transformer architectures without writing the boilerplate code for each model from scratch.

Highlights

  • Includes the original Vision Transformer implementation.
  • Supports advanced variants like NaViT (for variable-resolution images), DeepViT, CaiT, and many others.
  • Provides utilities for model distillation to create efficient student models from larger teachers.
  • Offers flexible configuration for patch sizes, embedding dimensions, and attention mechanisms.
  • Compatible with standard PyTorch workflows for training and inference.

Related

  • Project
  • Project
  • Project
  • Project
  • Project