Skip to content

Commit 90a578b

Browse files
committed
Add clamping_mode to rotate and set it to none in test
1 parent 064eb9f commit 90a578b

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

test/test_transforms_v2.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,6 @@ def test_functional(self, make_input):
20812081
(F.rotate_image, torch.Tensor),
20822082
(F._geometry._rotate_image_pil, PIL.Image.Image),
20832083
(F.rotate_image, tv_tensors.Image),
2084-
(F.rotate_bounding_boxes, tv_tensors.BoundingBoxes),
20852084
(F.rotate_mask, tv_tensors.Mask),
20862085
(F.rotate_video, tv_tensors.Video),
20872086
(F.rotate_keypoints, tv_tensors.KeyPoints),
@@ -2201,7 +2200,7 @@ def _recenter_bounding_boxes_after_expand(self, bounding_boxes, *, recenter_xy):
22012200
(bounding_boxes.to(torch.float64) - torch.tensor(translate)).to(bounding_boxes.dtype), like=bounding_boxes
22022201
)
22032202

2204-
def _reference_rotate_bounding_boxes(self, bounding_boxes, *, angle, expand, center, canvas_size=None):
2203+
def _reference_rotate_bounding_boxes(self, bounding_boxes, *, angle, expand, center):
22052204
if center is None:
22062205
center = [s * 0.5 for s in bounding_boxes.canvas_size[::-1]]
22072206
cx, cy = center
@@ -2227,36 +2226,30 @@ def _reference_rotate_bounding_boxes(self, bounding_boxes, *, angle, expand, cen
22272226
output = helper(
22282227
bounding_boxes,
22292228
affine_matrix=affine_matrix,
2230-
new_canvas_size=new_canvas_size if canvas_size is None else canvas_size,
2229+
new_canvas_size=new_canvas_size,
22312230
clamp=False,
22322231
)
22332232

2234-
return F.clamp_bounding_boxes(self._recenter_bounding_boxes_after_expand(output, recenter_xy=recenter_xy)).to(
2235-
bounding_boxes
2236-
)
2233+
return self._recenter_bounding_boxes_after_expand(output, recenter_xy=recenter_xy).to(bounding_boxes)
22372234

22382235
@pytest.mark.parametrize("format", list(tv_tensors.BoundingBoxFormat))
22392236
@pytest.mark.parametrize("angle", _CORRECTNESS_AFFINE_KWARGS["angle"])
22402237
@pytest.mark.parametrize("expand", [False, True])
22412238
@pytest.mark.parametrize("center", _CORRECTNESS_AFFINE_KWARGS["center"])
22422239
def test_functional_bounding_boxes_correctness(self, format, angle, expand, center):
2243-
bounding_boxes = make_bounding_boxes(format=format)
2240+
bounding_boxes = make_bounding_boxes(format=format, clamping_mode="none")
22442241

22452242
actual = F.rotate(bounding_boxes, angle=angle, expand=expand, center=center)
22462243
expected = self._reference_rotate_bounding_boxes(bounding_boxes, angle=angle, expand=expand, center=center)
22472244
torch.testing.assert_close(F.get_size(actual), F.get_size(expected), atol=2 if expand else 0, rtol=0)
2248-
2249-
expected = self._reference_rotate_bounding_boxes(
2250-
bounding_boxes, angle=angle, expand=expand, center=center, canvas_size=actual.canvas_size
2251-
)
22522245
torch.testing.assert_close(actual, expected)
22532246

22542247
@pytest.mark.parametrize("format", list(tv_tensors.BoundingBoxFormat))
22552248
@pytest.mark.parametrize("expand", [False, True])
22562249
@pytest.mark.parametrize("center", _CORRECTNESS_AFFINE_KWARGS["center"])
22572250
@pytest.mark.parametrize("seed", list(range(5)))
22582251
def test_transform_bounding_boxes_correctness(self, format, expand, center, seed):
2259-
bounding_boxes = make_bounding_boxes(format=format)
2252+
bounding_boxes = make_bounding_boxes(format=format, clamping_mode="none")
22602253

22612254
transform = transforms.RandomRotation(**self._CORRECTNESS_TRANSFORM_AFFINE_RANGES, expand=expand, center=center)
22622255

@@ -2268,10 +2261,6 @@ def test_transform_bounding_boxes_correctness(self, format, expand, center, seed
22682261

22692262
expected = self._reference_rotate_bounding_boxes(bounding_boxes, **params, expand=expand, center=center)
22702263
torch.testing.assert_close(F.get_size(actual), F.get_size(expected), atol=2 if expand else 0, rtol=0)
2271-
2272-
expected = self._reference_rotate_bounding_boxes(
2273-
bounding_boxes, **params, expand=expand, center=center, canvas_size=actual.canvas_size
2274-
)
22752264
torch.testing.assert_close(actual, expected)
22762265

22772266
def _recenter_keypoints_after_expand(self, keypoints, *, recenter_xy):

torchvision/transforms/v2/functional/_geometry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,7 @@ def rotate_bounding_boxes(
14491449
angle: float,
14501450
expand: bool = False,
14511451
center: Optional[list[float]] = None,
1452+
clamping_mode: CLAMPING_MODE_TYPE = "soft",
14521453
) -> tuple[torch.Tensor, tuple[int, int]]:
14531454
return _affine_bounding_boxes_with_expand(
14541455
bounding_boxes,
@@ -1460,6 +1461,7 @@ def rotate_bounding_boxes(
14601461
shear=[0.0, 0.0],
14611462
center=center,
14621463
expand=expand,
1464+
clamping_mode=clamping_mode,
14631465
)
14641466

14651467

@@ -1474,6 +1476,7 @@ def _rotate_bounding_boxes_dispatch(
14741476
angle=angle,
14751477
expand=expand,
14761478
center=center,
1479+
clamping_mode=inpt.clamping_mode,
14771480
)
14781481
return tv_tensors.wrap(output, like=inpt, canvas_size=canvas_size)
14791482

0 commit comments

Comments
 (0)