Skip to content

Instantly share code, notes, and snippets.

@ugo-nama-kun
Created November 11, 2022 08:22
Show Gist options
  • Save ugo-nama-kun/19a32eb6f91316761ccc8595e654a951 to your computer and use it in GitHub Desktop.
Save ugo-nama-kun/19a32eb6f91316761ccc8595e654a951 to your computer and use it in GitHub Desktop.
Using MNIST in pytorch
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
from torch.utils.data import DataLoader
from torchvision.datasets import MNIST
mnist_data = MNIST('./mnist', train=True, download=True, transform=transforms.ToTensor())
data_loader = DataLoader(mnist_data, batch_size=4, shuffle=False)
data_iter = iter(data_loader)
images, labels = data_iter.next()
npimg = images[0].numpy().reshape((28, 28))
plt.imshow(npimg, cmap='gray')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment