Hello everyone, I am new in Pytorch.
Recently i would like to try with Pytorch, but when I run the tutorial woth CIFAR10 dataset.
http://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#sphx-glr-beginner-blitz-cifar10-tutorial-py 33
I could not plot anything. what is the wrong ?
here is the piece of code that I implemented from the tutorial:
import torch
import torchvision
import torchvision.transforms as transforms
########################################################################
The output of torchvision datasets are PILImage images of range [0, 1].
We transform them to Tensors of normalized range [-1, 1].
transform = transforms.Compose(
[transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
trainset = torchvision.datasets.CIFAR10(root=’./data’, train=True,
download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=4,
shuffle=True, num_workers=2)
testset = torchvision.datasets.CIFAR10(root=’./data’, train=False,
download=True, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=4,
shuffle=False, num_workers=2)
classes = (‘plane’, ‘car’, ‘bird’, ‘cat’,
‘deer’, ‘dog’, ‘frog’, ‘horse’, ‘ship’, ‘truck’)
########################################################################
Let us show some of the training images, for fun.
import matplotlib.pyplot as plt
import numpy as np
functions to show an image
def imshow(img):
img = img / 2 + 0.5     # unnormalize
npimg = img.numpy()
plt.imshow(np.transpose(npimg, (1, 2, 0)))
however, I can plot the categories with name. but no image displayed. The Matplotlib example can be successfully plotted. So annoying and wired. please help .thanks