Skip to main content

A vision transformer for training on MNIST

Project description

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.

Requirements

The package requires Python 3.10 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 parent directory of the repository:

pip install mnistvit

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

License

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

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

mnistvit-1.2.0.tar.gz (24.7 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.2.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mnistvit-1.2.0.tar.gz
Algorithm Hash digest
SHA256 3b577241b6868e92cc4c85f602ba43c940993ba48b917f9c03b32dce942006ea
MD5 da0daf817563404c4206c11a4a27c517
BLAKE2b-256 7e525d19b3980205d733190e887930b1ee18f11e59c0fb998943a9cbe763242f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mnistvit-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1300ec45324df116e0e95c3c39a727e08febd2aa770c525fcf7593a7b5b2f581
MD5 85a323342503d4273a26c1b719f44b9d
BLAKE2b-256 7a18966ae69dcc8c85ea7b1aa6d018f8f64de9035d14ecf00d7b56a2dc7b2828

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