Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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 ';ToPILImage';对象没有属性';显示';_Python_Python Imaging Library_Pytorch - Fatal编程技术网

Python ';ToPILImage';对象没有属性';显示';

Python ';ToPILImage';对象没有属性';显示';,python,python-imaging-library,pytorch,Python,Python Imaging Library,Pytorch,我正在做一个图像处理任务,我想在两个网站的图片。对于concatting,我首先将图像转换为张量,然后将张量转换为PIL图像以显示它,但报告不正确。有人可以帮助我吗? 这是我的密码: import skimage.io as io import torch from torchvision import models, transforms from PIL import Image import matplotlib.pyplot as plt from torchvision.transf

我正在做一个图像处理任务,我想在两个网站的图片。对于concatting,我首先将图像转换为张量,然后将张量转换为PIL图像以显示它,但报告不正确。有人可以帮助我吗? 这是我的密码:

import skimage.io as io
import torch
from torchvision import  models, transforms
from PIL import Image
import matplotlib.pyplot as plt
from torchvision.transforms import ToPILImage
import numpy as np
from skimage import data_dir,io,color

coll1 = io.ImageCollection('F:\\code1/*.jpg')
coll2 = io.ImageCollection('F:\\code2/*.jpg')
a = torch.tensor(coll1)
print(a)
print(a.shape)
b = torch.tensor(coll2)
print(b)
print(b.shape)
c=torch.cat((a,b),1)
print(c.shape)
print(c)
img= transforms.ToPILImage()
img.show()
下面是错误代码:

回溯(最近一次调用):文件“F:/filelist.py”,第39行, 在里面 img.show()AttributeError:'ToPILImage'对象没有属性'show'


ToPILImage
方法接受张量或数据数组作为输入

您需要将单个图像张量投射到
ToPILImage
方法。从你的帖子中,我怀疑你传递的是成批的图像张量,而不是一个,因此出现了错误

假设如果要从张量
c
可视化图像

img = transforms.ToPILImage()(c)
img.show()

谢谢你的帮助。我尝试了你的方法,但再次出现错误。错误代码是:TypeError:pic应该是张量或ndarray。明白了。是的,我试过你的新答案,它说:打字错误:图片应该是张量或ndarray。明白了。谢谢你的帮助,但我仍然不知道如何解决这个问题。你能打印出张量的形状吗。我怀疑您试图转换图像批而不是图像。是的,您是对的。我想将总共36 224*224个图像缝合到两个文件夹中,然后将它们作为深入学习数据集输入。但我不清楚如何操作。a是torch.Size([18,224,224,3]),b是torch.Size([18,224,224,3]),c是torch.Size([18,448,224,3])。您需要的是一个自定义数据集类。您可以定义自己的数据集类,并在
\uuuu getitem\uuuu
方法中,让单图像张量通过转换方法。您可以了解更多信息。如果有用,请接受我的答案:)