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 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 inmodel.pt:

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.0.1.tar.gz (48.7 kB view details)

Uploaded Source

Built Distribution

mnistvit-1.0.1-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mnistvit-1.0.1.tar.gz
  • Upload date:
  • Size: 48.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for mnistvit-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6a427fa31db0d8197310ff041f883d18b7aab5789b8b1ae4c99b31edac6ffd0c
MD5 445c1fd56dc260e4e2f0cc20a3ad7a85
BLAKE2b-256 430a301113d3dc402e0c4b649890a9cb1e0af974893494f816115d77ac15b2a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mnistvit-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for mnistvit-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8f8c23a6b4e25575247d92c2b9a44d199342bf1c37f5bca2a27357e416630eb
MD5 3dcee1fd514dbfac4d8e60ca37fdd87f
BLAKE2b-256 3f6757944f46be7c1716f85a759f7b5c72caac935b7c7610f79c945b4b493b51

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page