Skip to content

Commit fb115c2

Browse files
pmeierNicolasHug
andauthored
downgrade warnign for F.rotate with center and expand=True (#7907)
Co-authored-by: Nicolas Hug <[email protected]>
1 parent b828671 commit fb115c2

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

test/test_transforms_v2_refactored.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,6 @@ def test_transform_noop(self, make_input, device):
13801380
assert_equal(output, input)
13811381

13821382

1383-
@pytest.mark.filterwarnings("ignore:The provided center argument has no effect")
13841383
class TestRotate:
13851384
_EXHAUSTIVE_TYPE_AFFINE_KWARGS = dict(
13861385
# float, int

torchvision/transforms/v2/_geometry.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,16 @@ class RandomRotation(Transform):
590590
expand (bool, optional): Optional expansion flag.
591591
If true, expands the output to make it large enough to hold the entire rotated image.
592592
If false or omitted, make the output image the same size as the input image.
593-
Note that the expand flag assumes rotation around the center and no translation.
593+
Note that the expand flag assumes rotation around the center (see note below) and no translation.
594594
center (sequence, optional): Optional center of rotation, (x, y). Origin is the upper left corner.
595595
Default is the center of the image.
596+
597+
.. note::
598+
599+
In theory, setting ``center`` has no effect if ``expand=True``, since the image center will become the
600+
center of rotation. In practice however, due to numerical precision, this can lead to off-by-one
601+
differences of the resulting image size compared to using the image center in the first place. Thus, when
602+
setting ``expand=True``, it's best to leave ``center=None`` (default).
596603
fill (number or tuple or dict, optional): Pixel fill value used when the ``padding_mode`` is constant.
597604
Default is 0. If a tuple of length 3, it is used to fill R, G, B channels respectively.
598605
Fill value can be also a dictionary mapping data type to the fill value, e.g.

torchvision/transforms/v2/functional/_geometry.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,6 @@ def rotate_image(
977977

978978
center_f = [0.0, 0.0]
979979
if center is not None:
980-
if expand:
981-
# TODO: Do we actually want to warn, or just document this?
982-
warnings.warn("The provided center argument has no effect on the result if expand is True")
983980
# Center values should be in pixel coordinates but translated such that (0, 0) corresponds to image center.
984981
center_f = [(c - s * 0.5) for c, s in zip(center, [width, height])]
985982

@@ -1017,9 +1014,6 @@ def _rotate_image_pil(
10171014
) -> PIL.Image.Image:
10181015
interpolation = _check_interpolation(interpolation)
10191016

1020-
if center is not None and expand:
1021-
warnings.warn("The provided center argument has no effect on the result if expand is True")
1022-
10231017
return _FP.rotate(
10241018
image, angle, interpolation=pil_modes_mapping[interpolation], expand=expand, fill=fill, center=center
10251019
)
@@ -1033,9 +1027,6 @@ def rotate_bounding_boxes(
10331027
expand: bool = False,
10341028
center: Optional[List[float]] = None,
10351029
) -> Tuple[torch.Tensor, Tuple[int, int]]:
1036-
if center is not None and expand:
1037-
warnings.warn("The provided center argument has no effect on the result if expand is True")
1038-
10391030
return _affine_bounding_boxes_with_expand(
10401031
bounding_boxes,
10411032
format=format,

0 commit comments

Comments
 (0)