Learn practical skills, build real-world projects, and advance your career
import numpy as np
import torch
import torchvision
import torchvision.transforms as transforms
from torchvision.datasets import MNIST
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import matplotlib.pyplot as plt
# Downloading data set in the "data" directory
dataset = MNIST(root='data/', download=True)
0.1%
31.0%IOPub message rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_msg_rate_limit`. Current values: NotebookApp.iopub_msg_rate_limit=1000.0 (msgs/sec) NotebookApp.rate_limit_window=3.0 (secs) 100.0%
Extracting data/MNIST\raw\train-images-idx3-ubyte.gz to data/MNIST\raw
102.8%
Downloading http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz Downloading http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz to data/MNIST\raw\train-labels-idx1-ubyte.gz Extracting data/MNIST\raw\train-labels-idx1-ubyte.gz to data/MNIST\raw Downloading http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz Downloading http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz to data/MNIST\raw\t10k-images-idx3-ubyte.gz
61.2%IOPub message rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_msg_rate_limit`. Current values: NotebookApp.iopub_msg_rate_limit=1000.0 (msgs/sec) NotebookApp.rate_limit_window=3.0 (secs)
#Seeing the number of data in the data set
train_dataset = MNIST(root='data/', train=True)
test_dataset = MNIST(root='data/', train=False)
len(train_dataset),len(test_dataset)
(60000, 10000)
#Visualizing a data

%matplotlib inline

image, label = dataset[1000]
plt.imshow(image, cmap='gray')
print('Label of 1000th data:', label)
Label of 1000th data: 0
Notebook Image
# Converting to Tensor
dataset = MNIST(root='data/', train=True, transform=transforms.ToTensor())