In the tutorials,why we use "torchvision.utils.make_grid(images)" to show image?

This is a tutorial code:

def imshow(img):
img = img / 2 + 0.5 # unnormalize
npimg = img.numpy()
plt.imshow(np.transpose(npimg, (1, 2, 0)))

get some random training images

dataiter = iter(trainloader)
images, labels =

show images


print labels

print(’ ‘.join(’%5s’ % classes[labels[j]] for j in range(4)))

What is function of ‘torchvision.utils.make_grid’ ?why don’t show image using functions 'imshow (images) directly?

1 Like

torchvision.utils.make_grid creates a single image containing all passed image tensors as a grid, which might be more convenient in case you want to display a few images.

1 Like

Thanks for your help.

Still concerning this topic:

In the tutorial, the img_grid is sent to tensorboard without normalization:
writer.add_image('four_fashion_mnist_images', img_grid)

while the function matplotlib_imshow unnormalizes the images.

As the images are sent to tensorboard to be visualized, shouldn’t tensorboard also receive unnormalized images?