I find that if my data type is uint8, after the transform.ToTensor(), the range is changed to [0,1]
while if my data type is int32, the range doesn’t change.
someone could explain me why? thank you.
a = torch.randint(0,255,(500,500), dtype=torch.uint8)
print(a.size())
print(torch.max(a))
a = torch.unsqueeze(a, dim =0)
print(a.size())
compose = transforms.Compose([transforms.ToPILImage(),transforms.ToTensor()])
a_trans = compose(a)
print(a_trans.size())
print(torch.max(a_trans))

Result:
torch.Size([500, 500])
tensor(254, dtype=torch.uint8)
torch.Size([1, 500, 500])
torch.Size([1, 500, 500])
tensor(0.9961)

IF:
a = torch.randint(0,255,(500,500), dtype=torch.int32)
print(a.size())
print(torch.max(a))
a = torch.unsqueeze(a, dim =0)
print(a.size())
compose = transforms.Compose([transforms.ToPILImage(),transforms.ToTensor()])
a_trans = compose(a)
print(a_trans.size())
print(torch.max(a_trans))

Result:
torch.Size([500, 500])
tensor(254, dtype=torch.int32)
torch.Size([1, 500, 500])
torch.Size([1, 500, 500])
tensor(254, dtype=torch.int32)