Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将张量反展开为图像_Python_Pytorch_Tensor - Fatal编程技术网

Python 将张量反展开为图像

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

我正在研究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.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)