Skip to main content

Python package mnistvit

A PyTorch-only implementation of a vision transformer (ViT) for training on MNIST, achieving 99.65% test accuracy with default parameters and without pre-training. The ViT architecture and learning parameters can be configured easily. Code for hyperparameter optimization is provided as well.

The code is intended to be used for learning about vision transformers. With MNIST as a simple and well understood dataset, the importance of various hyperparameters can be explored.

Requirements

The package requires Python 3.12 or greater and additionally requires the torch and torchvision packages. For hyperparameter optimization, additionally ray[tune] and optuna are required. The ViT itself requires torch only.

Installation

To install the mnistvit package, run the following command in the root directory of the repository:

pip install .

To install the package with hyperparameter optimization support:

pip install ".[tune]"

Usage

To train a model with default parameters:

python -m mnistvit.train

The script will produce a file config.json with the model configuration and file model.pt containing the trained model. Use the -h argument for a list of options.

To evaluate the test set accuracy of the model stored in model.pt with the configuration in config.json:

python -m mnistvit.predict --use-accuracy

To predict the class of the digit stored in the file sample.jpg:

python -m mnistvit.predict --image-file sample.jpg

For hyperparameter optimization with default search parameters:

python -m mnistvit.tune

A trained model is available on Hugging Face.

License

mnistvit is released under the GPLv3 license, as found in the LICENSE file.

Download files

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

Source Distribution

mnistvit-1.5.0.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mnistvit-1.5.0-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file mnistvit-1.5.0.tar.gz.

File metadata

  • Download URL: mnistvit-1.5.0.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for mnistvit-1.5.0.tar.gz
Algorithm Hash digest
SHA256 13699406fbc37af660b7643d8435cd4d8ae5321f8d06fc8b12fac1c397681539
MD5 02ad83c1a3a904393e827025d2c42216
BLAKE2b-256 6597811610bfd33942ccf7a63ac1c5e92c2c3293e3a11e0cf9af1b5ffc1fd0cd

See more details on using hashes here.

File details

Details for the file mnistvit-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: mnistvit-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for mnistvit-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e338c905a0568d9ab5439164f696c4a17fdfdb839a78f667366e932e3b61c871
MD5 55cc7a058764dcc8163507b20a8d90bc
BLAKE2b-256 993ee618e510dc20df0e6fe5edc521d7b7627495f14183c7840d9315bfb342e9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.5.0 This release

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 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