python - How do I rotate a PyTorch image tensor around it's ...
stackoverflow.com › questions › 64197754Oct 04, 2020 · There is a pytorch function for that: x = torch.tensor ( [ [0, 1], [2, 3]]) x = torch.rot90 (x, 1, [0, 1]) >> tensor ( [ [1, 3], [0, 2]]) Here are the docs: https://pytorch.org/docs/stable/generated/torch.rot90.html. Share.
Rotate a Tensor in PyTorch - GitHub
gist.github.com › kevinzakka › 0b807675453c7d8cf94bbRotate a Tensor in PyTorch Raw rot.py import numpy as np import torch import torch. nn. functional as F def rotz ( theta ): return np. array ( [ [ np. cos ( theta ), -np. sin ( theta ), 0 ], [ np. sin ( theta ), np. cos ( theta ), 0 ], [ 0, 0, 1 ], ], dtype="float64") device = torch. device ( "cuda") x = torch. rand ( 5, 3, 200, 200 ). to ( device)
rotate — Torchvision main documentation - pytorch.org
pytorch.org › vision › mainRotate the image by angle. If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions. Parameters. img (PIL Image or Tensor) – image to be rotated. angle (number) – rotation angle value in degrees, counter-clockwise. interpolation (InterpolationMode) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Default is InterpolationMode.NEAREST. If input is Tensor, only InterpolationMode ...