My recomendation is using Kornia https://torchgeometry.readthedocs.io/en/latest/geometry.transform.html?highlight=warp_affine#kornia.geometry.transform.warp_affine 157
Example: https://torchgeometry.readthedocs.io/en/latest/warp_affine.html 135