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

Uploaded Source

Built Distribution

mnistvit-1.1.0-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mnistvit-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ee833d0f4b0e6f1fd970de4741fa823d7362e5c3e0fc1cade0afbd96050df654
MD5 b393f0a8703c7f5ef8b3e65362bb4ff1
BLAKE2b-256 c0a3efdf26b8dbd9ae3c51aeb6ff59337c344c1bacfd7c3212eccd9b0c54c280

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mnistvit-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 39.2 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee8a20329e9283c6ebcd84f7fa90e56afaf9667318a5b86bd05f3c3b403ea711
MD5 62aef995fa498dac97ec5a72cfa21803
BLAKE2b-256 f64c54524dc0e3ea3254833987a380cb14f05bed70f5f834967bfab763221bf0

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