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 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 root directory of the repository:

pip install .

To install the package with hyperparameter optimization support:

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

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.1
File Size Uploaded Provenance Actions
mnistvit-1.5.1.tar.gz 25.9 kB Without provenance Details for mnistvit-1.5.1.tar.gz

Built distribution (wheel)

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

Total release size: 54.0 kB

Release files / mnistvit-1.5.1.tar.gz

Download URL mnistvit-1.5.1.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1e82ffb85af5d52bf029b1fba5f05be62ed25e44479b810af19b1785d791837a
BLAKE2b-256 checksum
How to use checksums
744dcb7066840afa729ad5a42fe524a74ff7c5f355199306dedb98dea8f74159
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

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

Download URL mnistvit-1.5.1-py3-none-any.whl
Size 28.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8b5159a815f61ef4b8fde69d5b31278117d887b842c615ec85a69cd543b6b33
BLAKE2b-256 checksum
How to use checksums
f735a4945578bc51e12eb053f7f4f1f79bda23a709412ec948b08b6ae4eec686
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Security for mnistvit 1.5.1

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