-
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
[BC-breaking] Introduced InterpolationModes and deprecated arguments: resample and fillcolor #2952
Merged
fmassa
merged 16 commits into
pytorch:master
from
Quansight:vfdev-5/deprecate-resample-fillcolor
Nov 27, 2020
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1b22ddc
Deprecated arguments: resample and fillcolor
vfdev-5 20c7177
Updates according to the review
vfdev-5 7f621a3
Merge branch 'master' into vfdev-5/deprecate-resample-fillcolor
vfdev-5 1bc499e
Added tests to check warnings and asserted BC
vfdev-5 f0d0257
Merge branch 'master' into vfdev-5/deprecate-resample-fillcolor
vfdev-5 453722c
Merge branch 'master' into vfdev-5/deprecate-resample-fillcolor
vfdev-5 d9c48d6
Merge branch 'master' of github.com:pytorch/vision into vfdev-5/depre…
vfdev-5 665350e
[WIP] Interpolation modes
vfdev-5 ceadb65
Added InterpolationModes enum
vfdev-5 e609722
Merge branch 'vfdev-5/deprecate-resample-fillcolor' of github.com:Qua…
vfdev-5 ed1b509
Merge branch 'master' into vfdev-5/deprecate-resample-fillcolor
vfdev-5 3768519
Added supported for int values for interpolation for BC
vfdev-5 6335042
Merge branch 'master' into vfdev-5/deprecate-resample-fillcolor
vfdev-5 4fb7790
Merge branch 'vfdev-5/deprecate-resample-fillcolor' of github.com:Qua…
vfdev-5 cf3d711
Removed useless test code
vfdev-5 6907505
Fix flake8
vfdev-5 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 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
This file contains 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
This file contains 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
This file contains 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 | ||||
---|---|---|---|---|---|---|
|
@@ -793,8 +793,8 @@ def _get_inverse_affine_matrix( | |||||
|
||||||
|
||||||
def rotate( | ||||||
img: Tensor, angle: float, resample: int = 0, expand: bool = False, | ||||||
center: Optional[List[int]] = None, fill: Optional[int] = None | ||||||
img: Tensor, angle: float, interpolation: int = 0, expand: bool = False, | ||||||
center: Optional[List[int]] = None, fill: Optional[int] = None, resample: Optional[int] = None | ||||||
) -> Tensor: | ||||||
"""Rotate the image by angle. | ||||||
The image can be a PIL Image or a Tensor, in which case it is expected | ||||||
|
@@ -803,7 +803,7 @@ def rotate( | |||||
Args: | ||||||
img (PIL Image or Tensor): image to be rotated. | ||||||
angle (float or int): rotation angle value in degrees, counter-clockwise. | ||||||
resample (``PIL.Image.NEAREST`` or ``PIL.Image.BILINEAR`` or ``PIL.Image.BICUBIC``, optional): | ||||||
interpolation (``PIL.Image.NEAREST`` or ``PIL.Image.BILINEAR`` or ``PIL.Image.BICUBIC``, optional): | ||||||
An optional resampling filter. See `filters`_ for more information. | ||||||
If omitted, or if the image has mode "1" or "P", it is set to ``PIL.Image.NEAREST``. | ||||||
expand (bool, optional): Optional expansion flag. | ||||||
|
@@ -817,21 +817,29 @@ def rotate( | |||||
Defaults to 0 for all bands. This option is only available for ``pillow>=5.2.0``. | ||||||
This option is not supported for Tensor input. Fill value for the area outside the transform in the output | ||||||
image is always 0. | ||||||
resample (int, optional): deprecated argument and will be removed since v0.10.0. | ||||||
Please use `arg`:interpolation: instead. | ||||||
|
||||||
Returns: | ||||||
PIL Image or Tensor: Rotated image. | ||||||
|
||||||
.. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters | ||||||
|
||||||
""" | ||||||
if resample is not None: | ||||||
warnings.warn( | ||||||
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead" | ||||||
) | ||||||
interpolation = resample | ||||||
|
||||||
if not isinstance(angle, (int, float)): | ||||||
raise TypeError("Argument angle should be int or float") | ||||||
|
||||||
if center is not None and not isinstance(center, (list, tuple)): | ||||||
raise TypeError("Argument center should be a sequence") | ||||||
|
||||||
if not isinstance(img, torch.Tensor): | ||||||
return F_pil.rotate(img, angle=angle, resample=resample, expand=expand, center=center, fill=fill) | ||||||
return F_pil.rotate(img, angle=angle, interpolation=interpolation, expand=expand, center=center, fill=fill) | ||||||
|
||||||
center_f = [0.0, 0.0] | ||||||
if center is not None: | ||||||
|
@@ -842,12 +850,13 @@ def rotate( | |||||
# due to current incoherence of rotation angle direction between affine and rotate implementations | ||||||
# we need to set -angle. | ||||||
matrix = _get_inverse_affine_matrix(center_f, -angle, [0.0, 0.0], 1.0, [0.0, 0.0]) | ||||||
return F_t.rotate(img, matrix=matrix, resample=resample, expand=expand, fill=fill) | ||||||
return F_t.rotate(img, matrix=matrix, interpolation=interpolation, expand=expand, fill=fill) | ||||||
|
||||||
|
||||||
def affine( | ||||||
img: Tensor, angle: float, translate: List[int], scale: float, shear: List[float], | ||||||
resample: int = 0, fillcolor: Optional[int] = None | ||||||
interpolation: int = 0, fill: Optional[int] = None, resample: Optional[int] = None, | ||||||
fillcolor: Optional[int] = None | ||||||
) -> Tensor: | ||||||
"""Apply affine transformation on the image keeping image center invariant. | ||||||
The image can be a PIL Image or a Tensor, in which case it is expected | ||||||
|
@@ -861,17 +870,33 @@ def affine( | |||||
shear (float or tuple or list): shear angle value in degrees between -180 to 180, clockwise direction. | ||||||
If a tuple of list is specified, the first value corresponds to a shear parallel to the x axis, while | ||||||
the second value corresponds to a shear parallel to the y axis. | ||||||
resample (``PIL.Image.NEAREST`` or ``PIL.Image.BILINEAR`` or ``PIL.Image.BICUBIC``, optional): | ||||||
interpolation (``PIL.Image.NEAREST`` or ``PIL.Image.BILINEAR`` or ``PIL.Image.BICUBIC``, optional): | ||||||
An optional resampling filter. See `filters`_ for more information. | ||||||
If omitted, or if the image is PIL Image and has mode "1" or "P", it is set to ``PIL.Image.NEAREST``. | ||||||
If input is Tensor, only ``PIL.Image.NEAREST`` and ``PIL.Image.BILINEAR`` are supported. | ||||||
fillcolor (int): Optional fill color for the area outside the transform in the output image (Pillow>=5.0.0). | ||||||
fill (int): Optional fill color for the area outside the transform in the output image (Pillow>=5.0.0). | ||||||
This option is not supported for Tensor input. Fill value for the area outside the transform in the output | ||||||
image is always 0. | ||||||
fillcolor (tuple or int, optional): deprecated argument and will be removed since v0.10.0. | ||||||
Please use `arg`:fill: instead. | ||||||
resample (int, optional): deprecated argument and will be removed since v0.10.0. | ||||||
Please use `arg`:interpolation: instead. | ||||||
|
||||||
Returns: | ||||||
PIL Image or Tensor: Transformed image. | ||||||
""" | ||||||
if resample is not None: | ||||||
warnings.warn( | ||||||
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead" | ||||||
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. nit: I'm not a native English speaker, but I feel like
Suggested change
This is a minor nit (which applies to the other messages as well), so I'm not considering this as a merge-blocking issue. |
||||||
) | ||||||
interpolation = resample | ||||||
|
||||||
if fillcolor is not None: | ||||||
warnings.warn( | ||||||
"Argument fillcolor is deprecated and will be removed since v0.10.0. Please, use fill instead" | ||||||
) | ||||||
fill = fillcolor | ||||||
|
||||||
if not isinstance(angle, (int, float)): | ||||||
raise TypeError("Argument angle should be int or float") | ||||||
|
||||||
|
@@ -913,11 +938,11 @@ def affine( | |||||
center = [img_size[0] * 0.5, img_size[1] * 0.5] | ||||||
matrix = _get_inverse_affine_matrix(center, angle, translate, scale, shear) | ||||||
|
||||||
return F_pil.affine(img, matrix=matrix, resample=resample, fillcolor=fillcolor) | ||||||
return F_pil.affine(img, matrix=matrix, interpolation=interpolation, fill=fill) | ||||||
|
||||||
translate_f = [1.0 * t for t in translate] | ||||||
matrix = _get_inverse_affine_matrix([0.0, 0.0], angle, translate_f, scale, shear) | ||||||
return F_t.affine(img, matrix=matrix, resample=resample, fillcolor=fillcolor) | ||||||
return F_t.affine(img, matrix=matrix, interpolation=interpolation, fill=fill) | ||||||
|
||||||
|
||||||
@torch.jit.unused | ||||||
|
This file contains 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
Oops, something went wrong.
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.
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.