Python - 显示图像数组中的一张图像

Python - Show one image from an image array

我正在阅读有关 pytorch 的教程。 https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html 而且我已经能够在我生成的假图像旁边显示真实图像。

# Grab a batch of real images from the dataloader
real_batch = next(iter(dataloader))

# Plot the real images
plt.figure(figsize=(15,15))
plt.subplot(1,2,1)
plt.axis("off")
plt.title("Real Images")
plt.imshow(np.transpose(vutils.make_grid(real_batch[0].to(device)[:64], padding=5, normalize=True).cpu(),(1,2,0)))

# Plot the fake images from the last epoch
plt.subplot(1,2,2)
plt.axis("off")
plt.title("Fake Images")
plt.imshow(np.transpose(img_list[-1],(1,2,0)))
plt.show()

我的数据集中的结果是:

我想知道如何从生成的假图像中显示一张图像。如果可能的话,我还想将其显示为 512 X 512 图像。

编辑: img_list[-1].shape 是 torch.Size([3, 530, 530]).

编辑 2:

这部分训练显示 img_list 是一个图像列表,每个图像都是一组子图像(无法将它们分开)。有没有一种方法可以编辑它,使 img_list 生成每个假图像的图像?

这是我想要的:

noise = torch.randn(1, nz, 1, 1, device=device)
with torch.no_grad():
    newfake = netG(noise).detach().cpu()

plt.axis("off")
plt.imshow(np.transpose(newfake[0],(1,2,0)))
plt.show()

因为它生成了一个新的图像,带有新的噪音。 img_list 将生成的图像组合成一个图像。 但是,这段代码仍然只能生成 64 x 64 像素的图像。