How to rotate a bounding box with `transforms.functional.rotate`?

I’m doing an object detection task with FasterRCNN. I want to add data augmentation by rotating the image and the bounding box. I am able to rotate an image (which is just a tensor of size [3, 256, 256]) just fine. However, the bounding box is of format [x, y, x + w, y + h], and I am not able to rotate this with transforms.functional.rotate.

Any ideas how I can do this rotation? It’s important that I use functional rotations instead of just transforms.Compose so that I can use the same random transformation for both the image and the boxes, instead of the image being rotated 90 degrees and the bounding box being rotated 270 degrees, for example.

AFAIK, you have to formulate an appropriate rotation matrix (3x3) and multiply it with the homogeneous coordinates (Nx3).

An easier way would be to use libraries such as albumentations, imgaug.

Cheers, used albumentations and it worked well.