Torchvision.transforms failed to transform a 16-bit grayscale tif

I use PIL to open a 16-bit grayscale tif image, then use torchvision.transforms to transform the image. an error “ValueError: image has wrong mode” comes out from transform operation. But when I open a RGB image of bmp or jpg format, no error comes out. The code is follow:
import os
from PIL import Image
import torchvision.transforms as transforms
rrc_trans = transforms.RandomResizedCrop(size=224, scale=(0.2, 1.0))
rhf_trans = transforms.RandomHorizontalFlip()
to_sensor = transforms.ToTensor()
norm_trans = transforms.Normalize(mean=0.45, std=0.225)
img = Image.open(‘aa.tif’)
img1 = rrc_trans(img)
img2 = rhf_trans(img1)
img3 = to_sensor(img2)
img4 = norm_trans(img3)

Based on this issue the default BILINEAR interpolation doesn’t seem to be supported for uint16 images and NEAREST should work:

x = np.random.randint(0, 65535, (224, 224), dtype=np.uint16)
img = PIL.Image.fromarray(x)

rrc_trans = transforms.RandomResizedCrop(size=224, scale=(0.2, 1.0), interpolation=PIL.Image.Resampling.NEAREST)
img1 = rrc_trans(img)