Conversion to LongTensor

What happens to the tensor when I change its type from Float to Long

This is supposed to be a segmentation mask of an image, and it gets completely wrecked when I change it to LongTensor.

Hi, If you convert your float tensor to long tensor (I assume you’re storing values between 0.0 and 1.0 in your float tensor) all your values get rounded off (in your example to 0, what’s the reason for the plot being black only). To solve this, you could multiply your original float tensor with a appropriate value before converting it to long.
imshow() also has the vmin and vmax parameters to specify the range, however by default it takes the range of values of the given data, so that should work anyways.


ax[0].imshow(tensor, cmap="gray")
ax[1].imshow((tensor * 255).long(), cmap="gray")