Rotate a tensor at a given degree

Hi there,

I have an tensor, and I want to rotate it at a given degree, i.e. 0.05.
How can I do it efficiently? I saw the torchvision.transforms.RandomRotation but this is used for data augmentation.

Any advice?

Thank you

1 Like

You can do it in multiple ways.

Use can pil Library directly for rotation as pytorch uses pil for this kind of image operations.

Another simple way I can think of is use random rotation class itself. But give the min and max with the same value.

If you want to write.a proper class, copy the random rotation class source code and change the way you need it to be like getting the rotation angle alone.

Thank you for suggestion,

The problem is this is the tensor as an intermediate layer in a network. Using PIL lib would requires to convert it back to numpy which is significantly slow.

Secondly, as I haven’t yet figure out how to use use random rotation class caused it only allow to use in the augmentation process.

Thirdly, making a custom class as modified of random rotation sounds reasonable. But I haven’t try yet. Just wonder why pyTorch does not support this function.

Thank you for your suggestions

1 Like