-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[prototype] Clean up and port the resize kernel in V2 #6892
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
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfdf7e9
Ported `resize`
datumbox e86be02
Align with previous behaviour
datumbox 40ed9a5
Merge branch 'main' into prototype/port_resize
datumbox 5d6f9ea
Update torchvision/prototype/transforms/functional/_geometry.py
datumbox d8ead3f
Moving input verification on top of method.
datumbox c4fbf3a
Merge branch 'main' into prototype/port_resize
datumbox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| import PIL.Image | ||
| import torch | ||
| from torch.nn.functional import interpolate | ||
| from torchvision.prototype import features | ||
| from torchvision.transforms import functional_pil as _FP, functional_tensor as _FT | ||
| from torchvision.transforms.functional import ( | ||
|
|
@@ -122,13 +123,30 @@ def resize_image_tensor( | |
| if image.numel() > 0: | ||
| image = image.reshape(-1, num_channels, old_height, old_width) | ||
|
|
||
| image = _FT.resize( | ||
| align_corners: Optional[bool] = None | ||
| if interpolation == InterpolationMode.BILINEAR or interpolation == InterpolationMode.BICUBIC: | ||
| align_corners = False | ||
| elif antialias: | ||
| raise ValueError("Antialias option is supported for bilinear and bicubic interpolation modes only") | ||
|
|
||
| dtype = image.dtype | ||
| need_cast = dtype != torch.float32 and dtype != torch.float64 | ||
datumbox marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if need_cast: | ||
| image = image.to(dtype=torch.float32) | ||
|
|
||
| image = interpolate( | ||
| image, | ||
| size=[new_height, new_width], | ||
| interpolation=interpolation.value, | ||
| mode=interpolation.value, | ||
| align_corners=align_corners, | ||
| antialias=antialias, | ||
| ) | ||
|
|
||
| if need_cast: | ||
| if interpolation == InterpolationMode.BICUBIC and dtype == torch.uint8: | ||
| image = image.clamp_(min=0, max=255) | ||
| image = image.round_().to(dtype=dtype) | ||
|
Comment on lines
+146
to
+148
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder to self that I need to address this in #6830. |
||
|
|
||
| return image.reshape(shape[:-3] + (num_channels, new_height, new_width)) | ||
|
|
||
|
|
||
|
|
@@ -1312,9 +1330,11 @@ def resized_crop( | |
|
|
||
| def _parse_five_crop_size(size: List[int]) -> List[int]: | ||
| if isinstance(size, numbers.Number): | ||
| size = [int(size), int(size)] | ||
| s = int(size) | ||
| size = [s, s] | ||
| elif isinstance(size, (tuple, list)) and len(size) == 1: | ||
| size = [size[0], size[0]] | ||
| s = size[0] | ||
| size = [s, s] | ||
|
|
||
| if len(size) != 2: | ||
| raise ValueError("Please provide only two dimensions (h, w) for size.") | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.