Hi I’m an newbie in pytorch
I’m studying torch on this tutoral
https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#sphx-glr-beginner-blitz-cifar10-tutorial-py 1




import torch
import torchvision
import torchvision.transforms as transforms
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’)




import matplotlib.pyplot as plt
import numpy as np
functions to show an image
def imshow(img):
img = img * 0.5 + 0.5     # unnormalize  std = 0.5, mean = 0.5
npimg = img.numpy()
plt.imshow(np.transpose(npimg, (1, 2, 0)))
plt.show()
get some random training images
dataiter = iter(trainloader)
images, labels = dataiter.next()
show images
imshow(torchvision.utils.make_grid(images))
print labels
print(’ ‘.join(’%5s’ % classes[labels[j]] for j in range(4)))


and here’s my question.
I don’t understand this line.


images, labels = dataiter.next()


What I thought was dataiter.next() goes to images and labels each which is an same data,
but when I printed out the images and labels right after that line just like below.


print(images, labels)


The output wasn’t same.
images got img file in array and labels got label numbers
and I don’t know why.
How did the image get the image data in arrays and labels get label numbers respectively??
Thank you for your answers
regards.