That’s strange, as this code seems to work:
image = transforms.ToPILImage(mode='L')(torch.randn(1, 96, 96))

However, you could just simply slice your image and pass it to your transformation:
transform(image[0])