Skip to content

Commit 9e0c2dd

Browse files
committed
Make soft the default clamping_mode, and add a test
1 parent 62f5f78 commit 9e0c2dd

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

test/common_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def make_bounding_boxes(
410410
canvas_size=DEFAULT_SIZE,
411411
*,
412412
format=tv_tensors.BoundingBoxFormat.XYXY,
413-
clamping_mode="hard", # TODOBB
413+
clamping_mode="soft",
414414
num_boxes=1,
415415
dtype=None,
416416
device="cpu",

test/test_tv_tensors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,8 @@ def test_return_type_input():
406406
tv_tensors.set_return_type("typo")
407407

408408
tv_tensors.set_return_type("tensor")
409+
410+
411+
def test_box_clamping_mode_default():
412+
assert tv_tensors.BoundingBoxes([0, 0, 10, 10], format="XYXY", canvas_size=(100, 100)).clamping_mode == "soft"
413+
assert tv_tensors.BoundingBoxes([0, 0, 10, 10, 0], format="XYWHR", canvas_size=(100, 100)).clamping_mode == "soft"

torchvision/transforms/v2/functional/_geometry.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def resize_bounding_boxes(
522522
size: Optional[list[int]],
523523
max_size: Optional[int] = None,
524524
format: tv_tensors.BoundingBoxFormat = tv_tensors.BoundingBoxFormat.XYXY,
525-
clamping_mode: CLAMPING_MODE_TYPE = "hard", # TODOBB soft
525+
clamping_mode: CLAMPING_MODE_TYPE = "soft",
526526
) -> tuple[torch.Tensor, tuple[int, int]]:
527527
# We set the default format as `tv_tensors.BoundingBoxFormat.XYXY`
528528
# to ensure backward compatibility.
@@ -1108,7 +1108,7 @@ def _affine_bounding_boxes_with_expand(
11081108
shear: list[float],
11091109
center: Optional[list[float]] = None,
11101110
expand: bool = False,
1111-
clamping_mode: CLAMPING_MODE_TYPE = "hard", # TODOBB soft
1111+
clamping_mode: CLAMPING_MODE_TYPE = "soft",
11121112
) -> tuple[torch.Tensor, tuple[int, int]]:
11131113
if bounding_boxes.numel() == 0:
11141114
return bounding_boxes, canvas_size
@@ -1211,7 +1211,7 @@ def affine_bounding_boxes(
12111211
scale: float,
12121212
shear: list[float],
12131213
center: Optional[list[float]] = None,
1214-
clamping_mode: CLAMPING_MODE_TYPE = "hard", # TODOBB soft
1214+
clamping_mode: CLAMPING_MODE_TYPE = "soft",
12151215
) -> torch.Tensor:
12161216
out_box, _ = _affine_bounding_boxes_with_expand(
12171217
bounding_boxes,
@@ -1740,7 +1740,7 @@ def pad_bounding_boxes(
17401740
canvas_size: tuple[int, int],
17411741
padding: list[int],
17421742
padding_mode: str = "constant",
1743-
clamping_mode: CLAMPING_MODE_TYPE = "hard", # TODOBB soft
1743+
clamping_mode: CLAMPING_MODE_TYPE = "soft",
17441744
) -> tuple[torch.Tensor, tuple[int, int]]:
17451745
if padding_mode not in ["constant"]:
17461746
# TODO: add support of other padding modes
@@ -1858,7 +1858,7 @@ def crop_bounding_boxes(
18581858
left: int,
18591859
height: int,
18601860
width: int,
1861-
clamping_mode: CLAMPING_MODE_TYPE = "hard", # TODOBB soft
1861+
clamping_mode: CLAMPING_MODE_TYPE = "soft",
18621862
) -> tuple[torch.Tensor, tuple[int, int]]:
18631863

18641864
# Crop or implicit pad if left and/or top have negative values:
@@ -2098,7 +2098,7 @@ def perspective_bounding_boxes(
20982098
startpoints: Optional[list[list[int]]],
20992099
endpoints: Optional[list[list[int]]],
21002100
coefficients: Optional[list[float]] = None,
2101-
clamping_mode: CLAMPING_MODE_TYPE = "hard", # TODOBB soft
2101+
clamping_mode: CLAMPING_MODE_TYPE = "soft",
21022102
) -> torch.Tensor:
21032103
if bounding_boxes.numel() == 0:
21042104
return bounding_boxes
@@ -2413,7 +2413,7 @@ def elastic_bounding_boxes(
24132413
format: tv_tensors.BoundingBoxFormat,
24142414
canvas_size: tuple[int, int],
24152415
displacement: torch.Tensor,
2416-
clamping_mode: CLAMPING_MODE_TYPE = "hard", # TODOBB soft
2416+
clamping_mode: CLAMPING_MODE_TYPE = "soft",
24172417
) -> torch.Tensor:
24182418
expected_shape = (1, canvas_size[0], canvas_size[1], 2)
24192419
if not isinstance(displacement, torch.Tensor):

torchvision/tv_tensors/_bounding_boxes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __new__(
105105
*,
106106
format: BoundingBoxFormat | str,
107107
canvas_size: tuple[int, int],
108-
clamping_mode: CLAMPING_MODE_TYPE = "hard", # TODOBB change default to soft!
108+
clamping_mode: CLAMPING_MODE_TYPE = "soft",
109109
dtype: torch.dtype | None = None,
110110
device: torch.device | str | int | None = None,
111111
requires_grad: bool | None = None,

0 commit comments

Comments
 (0)