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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mnistvit-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 db56e447ee28e6d56d353bfd9494a282427adff2222872589c140d0c2675b56a
MD5 f981c99037528001d3b9c24c100b4913
BLAKE2b-256 36ddd40734ffbd7dbe8bb86ac865771e3af47bc48d328fe785cbfe51ed28668a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mnistvit-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57bb379a4eb5181601006be5fbfa635fb039ee128e57774dd166f177a477ab5d
MD5 4beefd803e3330d445d11bfecf1bf4b2
BLAKE2b-256 1e38aa7f2366e63feae4ae56412928f3d50fde023a5a2f898ccf34ba7dd5d7c8

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