numpyvision: Vision datasets as numpy arrays
Project description
numpyvision: Vision datasets as numpy arrays
numpyvision is a drop-in replacement for torchvision.datasets with an easy access to MNIST and other MNIST-like datasets (FashionMNIST, KMNIST, EMNIST) in your numpy code.
numpyvision replicates the functionality of torchvision.datasets.mnist
without the need to download dozens of dependencies - numpyvision 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 numpyvision.datasets import MNIST
>>> mnist = MNIST(train=True)
>>> type(mnist.data)
<class 'numpy.ndarray'>
>>> mnist.data.dtype
dtype('uint8')
>>> mnist.data.min()
0
>>> mnist.data.max()
255
>>> mnist.data.shape
(60000, 28, 28)
>>> mnist.targets.shape
(60000,)
>>> mnist.classes[:3]
['0 - zero', '1 - one', '2 - two']
FashionMNIST example:
from numpyvision.datasets import FashionMNIST
import matplotlib.pyplot as plt
fmnist = FashionMNIST()
img, label = fmnist[0]
plt.imshow(img, cmap='gray')
plt.title(fmnist.classes[label])
plt.axis('off')
plt.show()
EMNIST example
from numpyvision.datasets import EMNIST
import matplotlib.pyplot as plt
letters = EMNIST('letters')
plt.imshow(
letters.data[:256]
.reshape(16, 16, 28, 28)
.swapaxes(1, 2)
.reshape(16 * 28, -1),
cmap='gray')
plt.axis('off')
plt.show()
Installation
Install numpyvision
from PyPi:
pip install numpyvision
or from source:
pip install -U git+https://github.com/pczarnik/numpyvision
The only requirements for numpyvision are numpy>=1.22
and python>=3.9
.
If you want to have progress bars while downloading datasets, install with
pip install numpyvision[tqdm]
Acknowledgments
The main inspirations for numpyvision were mnist
and torchvision.datasets.mnist
.
Project details
Release history Release notifications | RSS feed
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
Hashes for numpyvision-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 491ecc6fcd17445d4eeb5aeb41fea1abfc57b20cfeb54ee570abe8a417b87699 |
|
MD5 | d96ddf7f351ec81b967b56f75a0fa6f3 |
|
BLAKE2b-256 | 44fe9215720c042b858f1e127b7e2305886786bc205619f12829dba66fbbbc67 |