I found that torchvision.transform only works for PIL image type of objects. However, I want to apply random rotations on torch tensor and I want to get the gradient of the input images, so I can’t convert it to PIL first and then apply the transform.