python - 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))
解决方案
推荐阅读
- linker - ELFIO 正在创建全零 ELF 部分,无论设置数据如何。如何将数据放入 .text 部分?
- perl - 知道 2 个数组是否不同的最简单方法?
- report - COGNOS:将列与交叉表中的前一列与动态生成列进行比较
- python - 如何通过继承在两个不同的类中拆分函数?初学者
- excel - 从数据库恢复数据非常慢 - VBA
- javascript - 函数调用中的延迟加载要求语句?
- c++ - cpp中z3的编译和执行命令?
- docker - FeathersJS 和 Docker 应用程序存在套接字和连接问题
- xml - 如何将 xml 文件“复制”到 PostgreSQL?
- sql-server - 恢复时备份 SQL Server Developer 大喊它启用了数据压缩,仅在企业版上可用