On the same lines, here’s a modified version directly using the transforms class. I lifted it directly from my training code.
transform = transforms.Compose([transforms.Resize((256, 256)), transforms.ToTensor(), 
                               transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
img = Image.open(os.path.join(input_path, file)) #PIL image
img = transform(img) #torch.FloatTensor 

￼
￼