-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Rotation transformation #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you be a bit more clear on what you mean by those three angles? |
When images are being randomly rotated, they should be rotated angle1 or angle2 or angle3 degrees, not from (mix, max) degrees |
If I understand correctly, you are saying that we should propose the rotations to be randomly sampled from a discrete subset, instead of having them being sampled from a continuous interval, is that right? If that's the case, I'd say that having it being sampled from an interval is more generic, and should probably be kept. |
I agree with @fmassa. That being said, @noeagles, you could use the functional transforms and build that functionality yourself. import torchvision.transforms.functional as TF
import random
angle = random.choice([-30, -15, 0, 15, 30])
img = TF.rotate(img, angle) |
How it can be used inside the transforms.Compose([...])? |
Something like this would work: import torchvision.transforms.functional as TF
import random
from typing import Sequence
class MyRotateTransform:
def __init__(self, angles: Sequence[int]):
self.angles = angles
def __call__(self, x):
angle = random.choice(self.angles)
return TF.rotate(x, angle) |
@sotte do you think this snippet could be added somewhere in torchvision? Maybe in the documentation of |
@fmassa Um, if you think it's helpful, sure :) If we add this we should maybe just document the general procedure how you can use I guess I could add it to https://pytorch.org/docs/stable/torchvision/transforms.html#functional-transforms. I can create a PR (let me know if want something specific), but you can also just add the snippet. Both is fine with me. |
I think a note in the documentation of the functional interface, explaining that it gives full flexibility sounds like best thing to do, with an example for a particular case, like the rotation that you proposed just above |
I'll send the PR later today. |
@fmassa I have a use-case which prohibits the use of "generic interval" rotations because it destroys information I need in the corners. In particular, I can only use order-4 symmetry transforms (image attached). Using only reflections (RandomHorizontalFlip and RandomVerticalFlip) I can only get 4 of the 8 possible transforms.
These order-4 symmetry transforms are ubiquitous, for instance, in computer vision for satellite imagery research. I'm surprised that it isn't a built-in. |
@crypdick yes, rotations by 90 degrees as you suggest are definitely make sense for satellite, medical imagery and as data augmentations in torchvision. IMO, the reason why this is not yet built-in in torchvision, probably, due to "photography" type of imagery intended to be processed (like ImageNet) where upside-down rotation does not make much sense... @fmassa I agree that this can be an enhancement for transforms and functional operations. |
I agree that having the D_4 group augmentation as shown by @crypdick is very useful for many application ( biological, chemical and satellite data comes to mind). It is very easy to get it though: from torchvision.transforms import (
Compose,
RandomApply,
RandomHorizontalFlip,
RandomRotation,
RandomVerticalFlip,
)
transform = Compose(
[
RandomHorizontalFlip(p=0.5),
RandomVerticalFlip(p=0.5),
RandomApply([RandomRotation((90, 90))], p=0.5),
]
) But a shorthand and quicker version might be useful. |
* [LLM] Initial commit of the PaxML implementation * [LLM] Update paxml link * [LLM] checkpoint loading script and document * [LLM] SPM generation steps * [LLM] SPM generation step correction * [LLM] Add script to select example from dataset * [LLM PaxML] Sync model with PaxML 00156e6 * [LLM PaxML] update readme * [GPT-3 PaxML] Update model to the latest version. * [LLM] update c4_mllog.py to latest APIs * [LLM] Update README.md
I noticed that RandomRotation range only from (min, max); however it is more realistic to rotate from the set (angle1, angle2, angle3) randomly?
The text was updated successfully, but these errors were encountered: