Hi,
I am experiencing a surprising behavior when converting a binary PIL image to BoolTensor through numpy.
import numpy as np
import torch
from PIL import Image, ImageDraw
mask = Image.new(mode='1', size=(6, 6), color=False)
draw = ImageDraw.Draw(mask)
draw.polygon([(2, 2), (4, 2), (4, 4), (2, 4)], fill=True)
np_mask = np.array(mask)
print(np_mask.dtype, np.unique(np_mask))
tensor_mask = torch.from_numpy(np_mask)
print(tensor_mask.dtype, torch.unique(tensor_mask))
float_mask = tensor_mask.float()
print(float_mask.dtype, torch.unique(float_mask))
I would expect this code to print 0 and 1 as unique values of the float_mask
. However, the unique values found are 0 and 255.
Where does this behavior come from? It does not happen for numpy as the code shows.