Python 将张量反展开为图像
我正在研究GANs,我想把形成的图像形象化 为了这个,我一直在努力Python 将张量反展开为图像,python,pytorch,tensor,Python,Pytorch,Tensor,我正在研究GANs,我想把形成的图像形象化 为了这个,我一直在努力 def show_images(image_tensor, num_images=9, size=(1, 28, 28)): image_unflat = image_tensor.detach().cpu.view(-1, *size) image_grid = make_grid(image_unflat[:num_images], nrow=3) plt.imshow(image_grid.perm
def show_images(image_tensor, num_images=9, size=(1, 28, 28)):
image_unflat = image_tensor.detach().cpu.view(-1, *size)
image_grid = make_grid(image_unflat[:num_images], nrow=3)
plt.imshow(image_grid.permute(1, 2, 0).squeeze())
plt.show()
但是当我试图显示图像(一些张量)
时,我得到一个错误
image_unflat = image_tensor.detach().cpu.view(-1, *size)
AttributeError: 'builtin_function_or_method' object has no attribute 'view'
在这里,一些张量的大小是nx784。您需要在使用视图进行广播之前调用
image_unflat = image_tensor.detach().cpu().view(-1, *size)