transform = transforms.Compose([transforms.ToPILImage(), transforms.ToTensor()])
Before applying the transformation
After applying the transformation
Q.1 Why the pixel values are changed?
Q.2 How to correct this?
transform = transforms.Compose([transforms.ToPILImage(), transforms.ToTensor()])
Before applying the transformation
After applying the transformation
Q.1 Why the pixel values are changed?
Q.2 How to correct this?
I was able to solve this problem by normalizing the input data before transforming it.
The problem was that ToPILImage()
was discarding all the values which were greater than 1 hence the bright pixels became dark.
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: use torch.tensor(input_image)
to convert image into a tensor instead.
I was able to solve this problem by normalizing the input data before transforming it.
The problem was that ToPILImage()
was discarding all the values which were greater than 1 hence the bright pixels became dark.
© 2022 - 2024 — McMap. All rights reserved.