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
File details
Details for the file numpyvision-0.5.0.tar.gz
.
File metadata
- Download URL: numpyvision-0.5.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6f85420377780459afaf5ceba3044ca094cabdb670035ee77bcb1211aa7c98b |
|
MD5 | c8d612f958434a38012dc6151c1d41f9 |
|
BLAKE2b-256 | 8607a8357abdd9ef08159d9a13a3cc1652af141fa4f591b8b967eb8c2338cce0 |
File details
Details for the file numpyvision-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: numpyvision-0.5.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 491ecc6fcd17445d4eeb5aeb41fea1abfc57b20cfeb54ee570abe8a417b87699 |
|
MD5 | d96ddf7f351ec81b967b56f75a0fa6f3 |
|
BLAKE2b-256 | 44fe9215720c042b858f1e127b7e2305886786bc205619f12829dba66fbbbc67 |