Created
January 13, 2019 15:19
-
-
Save vihar/d5775e3c81d51c254dcc2ff1436b5321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load the libraries | |
import torch | |
import numpy as np | |
from torchvision import datasets | |
import torchvision.transforms as transforms | |
# Set the parameters | |
num_workers = 0 | |
batch_size = 20 | |
# Converting the Images to tensors using Transforms | |
transform = transforms.ToTensor() | |
train_data = datasets.MNIST(root='data', train=True, | |
download=True, transform=transform) | |
test_data = datasets.MNIST(root='data', train=False, | |
download=True, transform=transform) | |
# Loading the Data | |
train_loader = torch.utils.data.DataLoader(train_data, batch_size=batch_size, | |
num_workers=num_workers) | |
test_loader = torch.utils.data.DataLoader(test_data, batch_size=batch_size, | |
num_workers=num_workers) | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
dataiter = iter(train_loader) | |
images, labels = dataiter.next() | |
images = images.numpy() | |
# Peeking into dataset | |
fig = plt.figure(figsize=(25, 4)) | |
for image in np.arange(20): | |
ax = fig.add_subplot(2, 20/2, image+1, xticks=[], yticks=[]) | |
ax.imshow(np.squeeze(images[image]), cmap='gray') | |
ax.set_title(str(labels[image].item())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment