首页 > 解决方案 > Convert Tensor List for Image to PIL Format

问题描述

tensor(48., device='cuda:0') tensor(165., device='cuda:0') tensor(239., device='cuda:0') tensor(185., device='cuda:0')

I'm getting this whenever I try to just print out the image list in question. I need to convert this list of tensors to a PILImage. I have attempted to use transforms.ToPILImage() but it always says

 raise TypeError('pic should be Tensor or ndarray. Got {}.'.format(type(pic))) TypeError: pic should be Tensor or ndarray. Got <class 'list'>.

Is their another way to convert his list of Tensors to a PIL image that I'm missing? I need to convert it so I can crop it using this code.

img = im.crop(area)
basewidth = 200
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
cropped_image = img.resize((basewidth,hsize), Image.ANTIALIAS)
global i
cropped_image.save("r" + str(i) + ".jpg", "JPEG",dpi=(300,300))

标签: pythontensorflowpython-imaging-library

解决方案


推荐阅读