Skip to content

Fixed rotate with expand inconsistency #5677

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

Merged
merged 3 commits into from
Mar 25, 2022

Conversation

vfdev-5
Copy link
Collaborator

@vfdev-5 vfdev-5 commented Mar 25, 2022

Description:

  • Fixed rotate with expand inconsistency between torch vs PIL on odd-sized images
  • Updated tests
  • Rewritten bmm -> matmul

This PR fixes output size inconsistency of odd-sized images.

Before:

import torch
import torchvision
from torchvision.transforms.functional import rotate

print(torchvision.__version__)

img = torch.ones(3, 7, 33, dtype=torch.uint8)

out = rotate(img, angle=67, expand=True)
print(out.shape[1:][::-1])

from PIL import Image

pil_img = Image.new("RGB", (33, 7))
pil_out = rotate(pil_img, angle=67, expand=True)
print(pil_out.size)
> 
0.13.0a0+1af20e8
torch.Size([20, 34])
(21, 35)

Now:

> 
0.13.0a0+050a5c9
torch.Size([21, 35])
(21, 35)

@facebook-github-bot
Copy link

facebook-github-bot commented Mar 25, 2022

💊 CI failures summary and remediations

As of commit 260d021 (more details on the Dr. CI page):


  • 1/1 failures introduced in this PR

1 failure not recognized by patterns:

Job Step Action
CircleCI cmake_linux_gpu Build torchvision C++ distribution and test 🔁 rerun

This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@datumbox
Copy link
Contributor

@vfdev-5 could you elaborate on what inconsistency are you fixing? It's worth adding some details on the PR. Should this be considered a bug fix?

Also why do we change the tests? Is it to provide better corner cases? Or the previous test inputs would fail if you keep them the same on this PR?

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 25, 2022

@datumbox thanks for asking for clarifications ! I updated PR's description.

The issue is with output size which is different for torch image and PIL image if input has odd size (e.g. 7, 33). Current tests are not using odd sizes thus CI does not complain.
Context: in the prototype tests, @pmeier is using odd sizes for tests and segmentation mask tests were failing on this case and it appears that the roots are here.

I changed updated the tests such that:

  • include failing case
  • reduce the number of rotations to reduce CI time. If I keep @pytest.mark.parametrize("angle", range(-180, 180, 17)) as it was, there is no failures just slower.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the work and the clarifications.

Please tag the PR accordingly before merging.

@vfdev-5 vfdev-5 merged commit a26534c into pytorch:main Mar 25, 2022
@vfdev-5 vfdev-5 deleted the fixed-rotate-expand-consistency-pth-pil branch March 25, 2022 14:15
facebook-github-bot pushed a commit that referenced this pull request Apr 5, 2022
Summary:
* Fixed rotate with expand inconsistency between torch vs PIL on odd-sized images

* Update functional_tensor.py

(Note: this ignores all push blocking failures!)

Reviewed By: datumbox

Differential Revision: D35216781

fbshipit-source-id: 74b5179278634b9289f7a939a7a88fb0c5f37fd0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants