Hi Danish!



 danishnazir:

Can you tell me how I can convert it to [0,1]? based on some threshold e.g 127.


Thresholding will certainly work.  You could also use torch.where().
If you know that your values will always be exactly 0 or 255, you
could divide by 255 (and convert to float):
>>> import torch
>>> torch.__version__
'1.7.1'
>>> targ = torch.tensor ([0, 255, 0, 0, 255])
>>> targ.dtype
torch.int64
>>> targ = (targ / 255).float()
>>> targ
tensor([0., 1., 0., 0., 1.])
>>> targ.dtype
torch.float32

Best.
K. Frank