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.2

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

Built distribution (wheel)

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

Total release size: 54.0 kB

Release files / mnistvit-1.5.2.tar.gz

Download URL mnistvit-1.5.2.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
14d26291e3f79dc15a60c9347e952a7ba3806fbdd68a8a274abb5d6b4a4d829c
BLAKE2b-256 checksum
How to use checksums
6b3ddbea2d753504ebd0b80c1aa63faee90c2d863ba9e6e25068558bca85f499
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.2-py3-none-any.whl

Download URL mnistvit-1.5.2-py3-none-any.whl
Size 28.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b76f92c72f30a5e9782ced889139ceb800f70e43752d5aac243a87eb25655bf
BLAKE2b-256 checksum
How to use checksums
e8a609dc04f433f63e694c8b5fd7e867e7b7b3bd88592dc921d52665bdfdec4e
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.2

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