Unverified Commit 1044d0fb authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

[CHERRYPICK] downgrade warnign for F.rotate with center and expand=True (#7921)


Co-authored-by: default avatarNicolas Hug <contact@nicolas-hug.com>
parent d60d5e71
...@@ -1380,7 +1380,6 @@ class TestVerticalFlip: ...@@ -1380,7 +1380,6 @@ class TestVerticalFlip:
assert_equal(output, input) assert_equal(output, input)
@pytest.mark.filterwarnings("ignore:The provided center argument has no effect")
class TestRotate: class TestRotate:
_EXHAUSTIVE_TYPE_AFFINE_KWARGS = dict( _EXHAUSTIVE_TYPE_AFFINE_KWARGS = dict(
# float, int # float, int
......
...@@ -590,9 +590,16 @@ class RandomRotation(Transform): ...@@ -590,9 +590,16 @@ class RandomRotation(Transform):
expand (bool, optional): Optional expansion flag. expand (bool, optional): Optional expansion flag.
If true, expands the output to make it large enough to hold the entire rotated image. If true, expands the output to make it large enough to hold the entire rotated image.
If false or omitted, make the output image the same size as the input image. If false or omitted, make the output image the same size as the input image.
Note that the expand flag assumes rotation around the center and no translation. Note that the expand flag assumes rotation around the center (see note below) and no translation.
center (sequence, optional): Optional center of rotation, (x, y). Origin is the upper left corner. center (sequence, optional): Optional center of rotation, (x, y). Origin is the upper left corner.
Default is the center of the image. Default is the center of the image.
.. note::
In theory, setting ``center`` has no effect if ``expand=True``, since the image center will become the
center of rotation. In practice however, due to numerical precision, this can lead to off-by-one
differences of the resulting image size compared to using the image center in the first place. Thus, when
setting ``expand=True``, it's best to leave ``center=None`` (default).
fill (number or tuple or dict, optional): Pixel fill value used when the ``padding_mode`` is constant. fill (number or tuple or dict, optional): Pixel fill value used when the ``padding_mode`` is constant.
Default is 0. If a tuple of length 3, it is used to fill R, G, B channels respectively. Default is 0. If a tuple of length 3, it is used to fill R, G, B channels respectively.
Fill value can be also a dictionary mapping data type to the fill value, e.g. Fill value can be also a dictionary mapping data type to the fill value, e.g.
......
...@@ -977,9 +977,6 @@ def rotate_image( ...@@ -977,9 +977,6 @@ def rotate_image(
center_f = [0.0, 0.0] center_f = [0.0, 0.0]
if center is not None: if center is not None:
if expand:
# TODO: Do we actually want to warn, or just document this?
warnings.warn("The provided center argument has no effect on the result if expand is True")
# Center values should be in pixel coordinates but translated such that (0, 0) corresponds to image center. # Center values should be in pixel coordinates but translated such that (0, 0) corresponds to image center.
center_f = [(c - s * 0.5) for c, s in zip(center, [width, height])] center_f = [(c - s * 0.5) for c, s in zip(center, [width, height])]
...@@ -1017,9 +1014,6 @@ def _rotate_image_pil( ...@@ -1017,9 +1014,6 @@ def _rotate_image_pil(
) -> PIL.Image.Image: ) -> PIL.Image.Image:
interpolation = _check_interpolation(interpolation) interpolation = _check_interpolation(interpolation)
if center is not None and expand:
warnings.warn("The provided center argument has no effect on the result if expand is True")
return _FP.rotate( return _FP.rotate(
image, angle, interpolation=pil_modes_mapping[interpolation], expand=expand, fill=fill, center=center image, angle, interpolation=pil_modes_mapping[interpolation], expand=expand, fill=fill, center=center
) )
...@@ -1033,9 +1027,6 @@ def rotate_bounding_boxes( ...@@ -1033,9 +1027,6 @@ def rotate_bounding_boxes(
expand: bool = False, expand: bool = False,
center: Optional[List[float]] = None, center: Optional[List[float]] = None,
) -> Tuple[torch.Tensor, Tuple[int, int]]: ) -> Tuple[torch.Tensor, Tuple[int, int]]:
if center is not None and expand:
warnings.warn("The provided center argument has no effect on the result if expand is True")
return _affine_bounding_boxes_with_expand( return _affine_bounding_boxes_with_expand(
bounding_boxes, bounding_boxes,
format=format, format=format,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment