Learn practical skills, build real-world projects, and advance your career
import torch
import torchvision
from torchvision.datasets import MNIST
import matplotlib.pyplot as plt
%matplotlib inline
dataset= MNIST(root='data/', download=True)
C:\Users\akifr\anaconda3\lib\site-packages\torchvision\datasets\mnist.py:498: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at ..\torch\csrc\utils\tensor_numpy.cpp:180.) return torch.from_numpy(parsed.astype(m[2], copy=False)).view(*s)
test_dataset= MNIST(root='data/', train=False)
dataset[0]
(<PIL.Image.Image image mode=L size=28x28 at 0x1DCC1170E80>, 5)
image, label = dataset[0]
plt.imshow(image, cmap='gray')
print('Label:', label)
Label: 5
Notebook Image