-
Notifications
You must be signed in to change notification settings - Fork 7k
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
RandomRotation and fill #3303
RandomRotation and fill #3303
Conversation
Hi @tonystratum! 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 [email protected]. Thanks! |
In summary of #3309, please not convert fill, but:
|
65d7a85
to
b8f6edf
Compare
ef04f79
to
a05259c
Compare
@tonystratum Thanks a lot for the PR! The changes seem reasonable to me but I'll let @vfdev-5 to approve because of your discussion at #3309. @voldemortX Thanks for all your help on reviews and for providing good input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @tonystratum !
I left few comments. Sorry, I think, it would be better to set fill=0 if it was passed as None...
torchvision/transforms/transforms.py
Outdated
@@ -692,6 +692,10 @@ def __init__(self, distortion_scale=0.5, p=0.5, interpolation=InterpolationMode. | |||
|
|||
self.interpolation = interpolation | |||
self.distortion_scale = distortion_scale | |||
|
|||
if not isinstance(fill, (Sequence, numbers.Number)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, we can keep BC by doing:
if fill is None:
fill = 0
Sorry, I'm a bit hesitating about introducing new behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Maybe throw a warning with it or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some sense it was already done by PIL in _parse_fill*
method, so let's just reassign it without a warning.
Codecov Report
@@ Coverage Diff @@
## master #3303 +/- ##
==========================================
+ Coverage 73.93% 73.97% +0.04%
==========================================
Files 104 104
Lines 9594 9606 +12
Branches 1531 1537 +6
==========================================
+ Hits 7093 7106 +13
+ Misses 2024 2023 -1
Partials 477 477
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tonystratum thanks for the update ! Could you please also include a test here: https://github.com/pytorch/vision/blob/master/test/test_transforms.py#L1527
Something like initialize a transform and verfiy then that its attribute is correctly set.
Also, for affine and perspective ops. Thanks a lot!
unit test reports============================================== test session starts ===============================================
platform linux -- Python 3.8.5, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /home/stratum/PycharmProjects/venvs/tv-test2/bin/python
cachedir: .pytest_cache
rootdir: /home/stratum/build/myvision/vision
collected 70 items / 69 deselected / 1 selected
test/test_transforms.py::Tester::test_random_rotation PASSED [100%]
================================================ warnings summary ================================================
torchvision/__init__.py:26
/home/stratum/build/myvision/vision/torchvision/__init__.py:26: UserWarning: You are importing torchvision within its own root folder (/home/stratum/build/myvision/vision). This is not expected to work and may give errors. Please exit the torchvision project source and relaunch your python interpreter.
warnings.warn(message.format(os.getcwd()))
-- Docs: https://docs.pytest.org/en/stable/warnings.html
================================== 1 passed, 69 deselected, 1 warning in 0.30s =================================== ============================================== test session starts ===============================================
platform linux -- Python 3.8.5, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /home/stratum/PycharmProjects/venvs/tv-test2/bin/python
cachedir: .pytest_cache
rootdir: /home/stratum/build/myvision/vision
collected 70 items / 69 deselected / 1 selected
test/test_transforms.py::Tester::test_random_affine PASSED [100%]
================================================ warnings summary ================================================
torchvision/__init__.py:26
/home/stratum/build/myvision/vision/torchvision/__init__.py:26: UserWarning: You are importing torchvision within its own root folder (/home/stratum/build/myvision/vision). This is not expected to work and may give errors. Please exit the torchvision project source and relaunch your python interpreter.
warnings.warn(message.format(os.getcwd()))
-- Docs: https://docs.pytest.org/en/stable/warnings.html
================================== 1 passed, 69 deselected, 1 warning in 0.31s =================================== ============================================== test session starts ===============================================
platform linux -- Python 3.8.5, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /home/stratum/PycharmProjects/venvs/tv-test2/bin/python
cachedir: .pytest_cache
rootdir: /home/stratum/build/myvision/vision
collected 70 items / 68 deselected / 2 selected
test/test_transforms.py::Tester::test_randomperspective PASSED [ 50%]
test/test_transforms.py::Tester::test_randomperspective_fill PASSED [100%]
================================================ warnings summary ================================================
torchvision/__init__.py:26
/home/stratum/build/myvision/vision/torchvision/__init__.py:26: UserWarning: You are importing torchvision within its own root folder (/home/stratum/build/myvision/vision). This is not expected to work and may give errors. Please exit the torchvision project source and relaunch your python interpreter.
warnings.warn(message.format(os.getcwd()))
-- Docs: https://docs.pytest.org/en/stable/warnings.html
================================== 2 passed, 68 deselected, 1 warning in 0.32s =================================== There was a dedicated cc @vfdev-5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tonystratum, looks good ! I left a comment about NotImplemented.
Could you also fix code formatting problem: https://app.circleci.com/pipelines/github/pytorch/vision/6019/workflows/90601780-4a06-4272-b03c-bdfecf5ca3c5/jobs/389040
Yeah, sorry for that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far, thanks @tonystratum !
I'll merge it once the CI is done.
@vfdev-5 Thanks for your time!) |
Summary: * initial fix * fill=0 * docstrings * fill type check * fill type check * set None to zero * unit tests * set instead of NotImplemented * fix W293 Reviewed By: datumbox Differential Revision: D26226611 fbshipit-source-id: acee01300be03ad94eab3beb1c711f5e6050f632 Co-authored-by: vfdev <[email protected]> Co-authored-by: Vasilis Vryniotis <[email protected]>
Originally (vision/nightly), when
torchvision.transforms.RandomRotation
is used with a Tensor of shape(C, H, W)
, without afill
argument, both in atorch.nn.Sequential()
:we get a following error:
Error
and by itself:
Error
The fix is to check, if
img
is aTensor
, and iffill
isNone
, set it to zero.Unit tests:
pytest test/test_transforms.py -vvv -k test_rotate
pytest test/test_transforms_tensor.py -vvv -k test_random_rotate
flake8 and mypy passed.
Hope this helps!