PIL, transforms and png photos give weird result

So I have a brunch of pics and I want to turn all of them to tensors. I am using transforms and PIL library to do so

loader = transforms.Compose([transforms.Resize([IMSIZE, IMSIZE]), transforms.ToTensor()])
image = Image.open(image_name)
image = loader(image).float()

The expected result should be a 3d tensor with size 3*IMSIZE*IMSIZE, however, sometimes when dealing with png figures, it will give me 1*IMSIZE*IMSIZE or 4 *IMSIZE*IMSIZE.

Does someone have an idea what’s going on here?

For example, this figure gives me 1*IMSIZE*IMSIZE tensor.

Does using convert(‘RGB’) help?

image = Image.open(image_name).convert('RGB')