在将PIL图像转换为张量时,为什么像素在变化? [英] While converting a PIL image into a tensor why the pixels are changing?
本文介绍了在将PIL图像转换为张量时,为什么像素在变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
transform = transforms.Compose([transforms.ToPILImage(), transforms.ToTensor()])
应用转换之前
应用转换后
Q.1为什么更改像素值?
Q.2如何更正此问题?
Q.1 Why the pixel values are changed?
Q.2 How to correct this?
推荐答案
Q1:torchvision的transforms.ToTensor()可以归一化您的输入图像,即将其置于[0,1]范围内,因为这是非常常见的预处理步骤
Q1: transforms.ToTensor() of torchvision normalizes your input image, i.e. puts it in the range [0,1] as it is a very common preprocessing step.
Q2:使用 torch.tensor(input_image)
将图像转换为张量.
Q2: use torch.tensor(input_image)
to convert image into a tensor instead.
这篇关于在将PIL图像转换为张量时,为什么像素在变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文