Learn practical skills, build real-world projects, and advance your career
import torch
import torchvision
from torchvision.datasets import MNIST

dataset = MNIST(root='data/', download = True)
len(dataset)
60000
test_dataset = MNIST(root='data/', train = False)
len(test_dataset)
10000
import matplotlib.pyplot as plt
%matplotlib inline

image, label = dataset[10]
plt.imshow(image)
print('Label: ',label)
Label: 3
Notebook Image
import torchvision.transforms as transforms
dataset = MNIST(root='data/', train = True, transform = transforms.ToTensor())
img_tensor, label = dataset[0]
print(img_tensor.shape,label)
torch.Size([1, 28, 28]) 5