Skip to main content

MNISTs: All MNIST-like datasets in one package

Project description

MNISTs: All MNIST-like datasets in one package

MNISTs provides an easy way to use MNIST and other MNIST-like datasets (FashionMNIST, KMNIST, EMNIST) in your numpy code.

MNISTs replicates the functionality of torchvision.datasets.mnist without the need to download dozens of dependencies. MNISTs has only one dependency - numpy.

Usage

Each dataset stores train/test images as numpy arrays of shape (n_samples, img_height, img_width) and train/test labels as numpy arrays of shape (n_samples,).

MNIST example:

>>> from mnists import MNIST
>>> mnist = MNIST()
>>> type(mnist.train_images())
<class 'numpy.ndarray'>
>>> mnist.train_images().dtype
dtype('uint8')
>>> mnist.train_images().min()
0
>>> mnist.train_images().max()
255
>>> mnist.train_images().shape
(60000, 28, 28)
>>> mnist.train_labels().shape
(60000,)
>>> mnist.test_images().shape
(10000, 28, 28)
>>> mnist.test_labels().shape
(10000,)
>>> mnist.classes[:3]
['0 - zero', '1 - one', '2 - two']

FashionMNIST example:

from mnists import FashionMNIST
import matplotlib.pyplot as plt

fmnist = FashionMNIST()
plt.imshow(fmnist.train_images()[0], cmap='gray')
plt.title(fmnist.classes[fmnist.train_labels()[0]])
plt.axis('off')
plt.show()

FashionMNIST example

EMNIST example

from mnists import EMNIST
import matplotlib.pyplot as plt

emnist = EMNIST()
letters = emnist.Letters()
plt.imshow(
    letters.train_images()[:256]
        .reshape(16, 16, 28, 28)
        .swapaxes(1, 2)
        .reshape(16 * 28, -1),
    cmap='gray')
plt.axis('off')
plt.show()

EMNIST example

Installation

Install mnists from PyPi:

pip install mnists

or from source:

pip install -U git+https://github.com/pczarnik/mnists

The only requirements for MNISTs are numpy>=1.22 and python>=3.9.

If you want to have progress bars while downloading datasets, install with

pip install mnists[tqdm]

Acknowledgments

The main inspirations for MNISTs were mnist and torchvision.datasets.mnist.

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

mnists-0.4.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

mnists-0.4.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file mnists-0.4.1.tar.gz.

File metadata

  • Download URL: mnists-0.4.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for mnists-0.4.1.tar.gz
Algorithm Hash digest
SHA256 a0398c8409409f4cc3a13b95fcfea89bb1ec761eacb44e668b5c4f4358f082fb
MD5 48966883b425512e0a2c63db994a3de2
BLAKE2b-256 165776118791bba51bae23d7baec423c158b58af4bff22b53bb49fbb2f3a30fc

See more details on using hashes here.

File details

Details for the file mnists-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: mnists-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for mnists-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d23557814da8349f0a022050d7c6cb77d236a942a269580de353c51a105e475a
MD5 c8630b8249c6ae5581e007b35edb4579
BLAKE2b-256 a09f8d4f954d104a7810ef0a43614124a0daa95d7ed9e817e480cd9d2334c1ea

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