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 in model.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
Built Distribution
File details
Details for the file mnistvit-1.0.2.tar.gz
.
File metadata
- Download URL: mnistvit-1.0.2.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 865d77f9226fc6f2a920117dfdafed7975a07fcbddb4c4a2faf525f059dd45c6 |
|
MD5 | b9e781e90ba04c4ec4f3543130acbabe |
|
BLAKE2b-256 | e959146b4989869990c46482505673fcfb32635bf25fdb99d2ecd1568bc8ba4b |
File details
Details for the file mnistvit-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: mnistvit-1.0.2-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e7db329cc7b1d76df9fd8190e66b218c1eaa9a45169bef2d9418b9f0538e6b3 |
|
MD5 | eb0e574ab6464f517c5a10dcdb3516c9 |
|
BLAKE2b-256 | 99ed111a2b39e48378add8c4cc031a34032659e8049e48d07de84cb0ab5b7361 |