Allow degrees=None in RandomAffine to disable rotation#9444
Allow degrees=None in RandomAffine to disable rotation#9444sunnycho100 wants to merge 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9444
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 2 Unrelated FailuresAs of commit 6b33f6a with merge base b358d66 ( NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @sunnycho100! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@sunnycho100 Thanks a lot for opening this PR! After discussion, we don’t think this is a current priority for TorchVision, so we won’t be merging it at this time. |
Closes #5241
Motivation
Right now
degreesis a required positional arg inRandomAffine, which forces users to passdegrees=0just to disable rotation — even when they only care about translation, scale, or shear. Every other parameter already acceptsNoneto opt out, sodegreesis the odd one out.This has been bugging me while working on an augmentation pipeline where I only needed translate + scale. Having to write
RandomAffine(0, translate=(...), scale=(...))felt like a papercut every time.Changes
Both v1 (
transforms.py) and v2 (v2/_geometry.py):degreesfrom a required positional arg to an optional kwarg defaulting toNonedegrees=None, rotation is disabled internally by settingself.degrees = [0.0, 0.0]degrees=Noneand none oftranslate,scale,shearare set either, aValueErroris raised — a no-opRandomAffine()with zero args does not make senseTests (
test_transforms.py,test_transforms_v2.py):RandomAffine(degrees=None, translate=(...))works and setsdegreesto[0.0, 0.0]RandomAffine(translate=(...))works (positional omission)RandomAffine()andRandomAffine(degrees=None)both raiseValueErrorUsage
Backward-compatible: existing code that passes
degreespositionally still works exactly the same.