A few of my files are grayscale, but most are jpeg RGB.
Why does the following not work?

im = PIL.Image.open(img_path)
im.convert(“RGB”)
im_torch = torchvision.transforms.ToTensor()(im)

Just like the suggestion above, I need to add

if im_torch.shape[0]==1:
print(f"im_torch.shape={im_torch.shape}") # im_torch.shape=torch.Size([1, 4077, 4819])
im_torch = im_torch.expand(3,-1,-1)
print(f"im_torch.shape={im_torch.shape}") # im_torch.shape=torch.Size([3, 4077, 4819])

notice the output of the first print statement is

im_torch.shape=torch.Size([1, 4077, 4819])

So does im.convert(“RGB”) not convert the file?