Skip to main content

VITAX

PyPI version

VITAX: An open-source platform for training and inference of Vision Transformers (ViT) with the new and elegant Flax NNX API.

This library provides a clean, from-scratch implementation of the Vision Transformer model and makes it easy to leverage powerful pretrained models from the Hugging Face Hub for your own computer vision tasks.

Core Features

  • Modern Flax API: Built entirely using flax.nnx, offering a more intuitive, object-oriented, and explicit way to build neural networks in JAX.
  • Hugging Face Integration: Seamlessly load pretrained ViT weights from google/vit-* models for transfer learning and fine-tuning.
  • Custom Models: Easily create and train Vision Transformer models from scratch with custom configurations.
  • Simple & Efficient Training: Includes a straightforward and JIT-compiled training and evaluation pipeline using optax for optimization.
  • Modular Design: The code is well-structured, separating the model definition, weight loading, and training logic for clarity and extensibility.

Installation

You can install vitax directly from PyPI:

pip install vitax

Model creation with Vitax

In Vitax, you can create vision transformers in different ways

Load a Pretrained Model for Fine-Tuning

This is the most common use case. You can load a model pretrained on ImageNet-21k and adapt its final classification layer for your specific dataset (e.g., CIFAR-100 with 100 classes).

from vitax.models import create_model

# Load a base pretrained ViT model and adapt it for 100 classes
model = create_model(
    'google/vit-base-patch16-224',
    num_classes=100,
    pretrained=True
)

Create a Model from Scratch (Random Weights)

If you want to train a model from the ground up, you can create one with random weights. You can either use a standard configuration or define your own.

Using a standard model configuration:

from vitax.models import create_model

# Create a 'vit-base-patch16-224' architecture with random weights
model = create_model(
    'google/vit-base-patch16-224',
    num_classes=10, # For a 10-class dataset like CIFAR-10
    pretrained=False
)

Using a fully custom architecture:

from vitax.models import create_model

# Define a custom configuration for a smaller model, compatible with HuggingFace ViT config
custom_config = {
    'image_size': 224,
    'patch_size': 16,
    'num_hidden_layers': 6,          # Fewer layers
    'num_attention_heads': 8,           # Fewer attention heads
    'intermediate_size': 500,          # Smaller MLP dimension
    'hidden_size': 128,       # Embedding dimension
}

# Create the custom model with random weights
custom_model = create_model(
    name_or_config=custom_config,
    num_classes=10,
    pretrained=False
)

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for vitax 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vitax 0.0.10
File Size Uploaded
vitax-0.0.10.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vitax 0.0.10
File Interpreter ABI Platform
vitax-0.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / vitax-0.0.10.tar.gz

Download URL vitax-0.0.10.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
67bb6559d230e4ae7f5b1be050b9a956dfa1de7a683c8a37ab5a49bbfbfe6b16
BLAKE2b-256 checksum
How to use checksums
8c2fbcdf9a920e7d6a8608e5b51d320bb3b48e0629a0bdc29dce6c5db2eedf9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / vitax-0.0.10-py3-none-any.whl

Download URL vitax-0.0.10-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5c0d43f291b83d771c0a8eb8a2dccfa4e25321f7eafa50a20a347d69e322b9e
BLAKE2b-256 checksum
How to use checksums
ab7038b6fdc7a7b9f2b9f848e43b533ee5e8bf3197156eb232171ceb10db0762
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page