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, torchcodec 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:

pip install mnistvit

To install the package with hyperparameter optimization support:

pip install "mnistvit[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.

Metadata

Release files for mnistvit 1.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mnistvit 1.5.3
File Size Uploaded Provenance Actions
mnistvit-1.5.3.tar.gz 25.8 kB Without provenance Details for mnistvit-1.5.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mnistvit 1.5.3
File Interpreter ABI Platform Actions
mnistvit-1.5.3-py3-none-any.whl Python 3 none any Details for mnistvit-1.5.3-py3-none-any.whl

Total release size: 53.9 kB

Release files / mnistvit-1.5.3.tar.gz

Download URL mnistvit-1.5.3.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b4b25517aed1148d95b3a623ff5b06e69e9751e9143338e266ce51e7f38c19eb
BLAKE2b-256 checksum
How to use checksums
990633c1bc4e31a194e466f4cdb8709a84ad9803c8d5c6d55adfa403b07967b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / mnistvit-1.5.3-py3-none-any.whl

Download URL mnistvit-1.5.3-py3-none-any.whl
Size 28.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6d50173f3a11563b10d9b35c41624326ff30918ca9f0a310e37d4d6ea05a6c8
BLAKE2b-256 checksum
How to use checksums
1562ba44e2c7ce672768fb42129abedf92803a49cfc5569c3e64a6ab8c13e081
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for mnistvit 1.5.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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