Skip to content

Commit a367808

Browse files
authored
Merge branch 'main' into cutmixtut
2 parents afb15d8 + 8d4e879 commit a367808

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+791
-778
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ d367a01a18a3ae6bee13d8be3b63fd6a581ea46f
99
6ca9c76adb6daf2695d603ad623a9cf1c4f4806f
1010
# Fix unnecessary exploded black formatting (#7709)
1111
a335d916db0694770e8152f41e19195de3134523
12+
# Renaming: `BoundingBox` -> `BoundingBoxes` (#7778)
13+
332bff937c6711666191880fab57fa2f23ae772e

docs/source/datapoints.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ see e.g. :ref:`sphx_glr_auto_examples_plot_transforms_v2_e2e.py`.
1515
Image
1616
Video
1717
BoundingBoxFormat
18-
BoundingBox
18+
BoundingBoxes
1919
Mask

docs/source/transforms.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ Miscellaneous
206206
v2.RandomErasing
207207
Lambda
208208
v2.Lambda
209-
v2.SanitizeBoundingBox
210-
v2.ClampBoundingBox
209+
v2.SanitizeBoundingBoxes
210+
v2.ClampBoundingBoxes
211211
v2.UniformTemporalSubsample
212212

213213
.. _conversion_transforms:

gallery/plot_datapoints.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#
4848
# * :class:`~torchvision.datapoints.Image`
4949
# * :class:`~torchvision.datapoints.Video`
50-
# * :class:`~torchvision.datapoints.BoundingBox`
50+
# * :class:`~torchvision.datapoints.BoundingBoxes`
5151
# * :class:`~torchvision.datapoints.Mask`
5252
#
5353
# How do I construct a datapoint?
@@ -76,10 +76,10 @@
7676

7777
########################################################################################################################
7878
# In general, the datapoints can also store additional metadata that complements the underlying tensor. For example,
79-
# :class:`~torchvision.datapoints.BoundingBox` stores the coordinate format as well as the spatial size of the
79+
# :class:`~torchvision.datapoints.BoundingBoxes` stores the coordinate format as well as the spatial size of the
8080
# corresponding image alongside the actual values:
8181

82-
bounding_box = datapoints.BoundingBox(
82+
bounding_box = datapoints.BoundingBoxes(
8383
[17, 16, 344, 495], format=datapoints.BoundingBoxFormat.XYXY, spatial_size=image.shape[-2:]
8484
)
8585
print(bounding_box)
@@ -105,7 +105,7 @@ class PennFudanDataset(torch.utils.data.Dataset):
105105
def __getitem__(self, item):
106106
...
107107

108-
target["boxes"] = datapoints.BoundingBox(
108+
target["boxes"] = datapoints.BoundingBoxes(
109109
boxes,
110110
format=datapoints.BoundingBoxFormat.XYXY,
111111
spatial_size=F.get_spatial_size(img),
@@ -126,7 +126,7 @@ def __getitem__(self, item):
126126

127127
class WrapPennFudanDataset:
128128
def __call__(self, img, target):
129-
target["boxes"] = datapoints.BoundingBox(
129+
target["boxes"] = datapoints.BoundingBoxes(
130130
target["boxes"],
131131
format=datapoints.BoundingBoxFormat.XYXY,
132132
spatial_size=F.get_spatial_size(img),
@@ -147,7 +147,7 @@ def get_transform(train):
147147
########################################################################################################################
148148
# .. note::
149149
#
150-
# If both :class:`~torchvision.datapoints.BoundingBox`'es and :class:`~torchvision.datapoints.Mask`'s are included in
150+
# If both :class:`~torchvision.datapoints.BoundingBoxes`'es and :class:`~torchvision.datapoints.Mask`'s are included in
151151
# the sample, ``torchvision.transforms.v2`` will transform them both. Meaning, if you don't need both, dropping or
152152
# at least not wrapping the obsolete parts, can lead to a significant performance boost.
153153
#

gallery/plot_transforms_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def load_data():
2929

3030
masks = datapoints.Mask(merged_masks == labels.view(-1, 1, 1))
3131

32-
bounding_boxes = datapoints.BoundingBox(
32+
bounding_boxes = datapoints.BoundingBoxes(
3333
masks_to_boxes(masks), format=datapoints.BoundingBoxFormat.XYXY, spatial_size=image.shape[-2:]
3434
)
3535

gallery/plot_transforms_v2_e2e.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ def load_example_coco_detection_dataset(**kwargs):
106106
transforms.RandomHorizontalFlip(),
107107
transforms.ToImageTensor(),
108108
transforms.ConvertImageDtype(torch.float32),
109-
transforms.SanitizeBoundingBox(),
109+
transforms.SanitizeBoundingBoxes(),
110110
]
111111
)
112112

113113
########################################################################################################################
114114
# .. note::
115-
# Although the :class:`~torchvision.transforms.v2.SanitizeBoundingBox` transform is a no-op in this example, but it
115+
# Although the :class:`~torchvision.transforms.v2.SanitizeBoundingBoxes` transform is a no-op in this example, but it
116116
# should be placed at least once at the end of a detection pipeline to remove degenerate bounding boxes as well as
117117
# the corresponding labels and optionally masks. It is particularly critical to add it if
118118
# :class:`~torchvision.transforms.v2.RandomIoUCrop` was used.

references/detection/presets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(
7878
if use_v2:
7979
transforms += [
8080
T.ConvertBoundingBoxFormat(datapoints.BoundingBoxFormat.XYXY),
81-
T.SanitizeBoundingBox(),
81+
T.SanitizeBoundingBoxes(),
8282
]
8383

8484
self.transforms = T.Compose(transforms)

test/common_utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ def make_image_loaders_for_interpolation(
620620

621621

622622
@dataclasses.dataclass
623-
class BoundingBoxLoader(TensorLoader):
623+
class BoundingBoxesLoader(TensorLoader):
624624
format: datapoints.BoundingBoxFormat
625625
spatial_size: Tuple[int, int]
626626

@@ -639,25 +639,25 @@ def make_bounding_box(
639639
- (box[3] - box[1], box[2] - box[0]) for XYXY
640640
- (H, W) for XYWH and CXCYWH
641641
spatial_size: Size of the reference object, e.g. an image. Corresponds to the .spatial_size attribute on
642-
returned datapoints.BoundingBox
642+
returned datapoints.BoundingBoxes
643643
644644
To generate a valid joint sample, you need to set spatial_size here to the same value as size on the other maker
645645
functions, e.g.
646646
647647
.. code::
648648
649649
image = make_image=(size=size)
650-
bounding_box = make_bounding_box(spatial_size=size)
651-
assert F.get_spatial_size(bounding_box) == F.get_spatial_size(image)
650+
bounding_boxes = make_bounding_box(spatial_size=size)
651+
assert F.get_spatial_size(bounding_boxes) == F.get_spatial_size(image)
652652
653653
For convenience, if both size and spatial_size are omitted, spatial_size defaults to the same value as size for all
654654
other maker functions, e.g.
655655
656656
.. code::
657657
658658
image = make_image=()
659-
bounding_box = make_bounding_box()
660-
assert F.get_spatial_size(bounding_box) == F.get_spatial_size(image)
659+
bounding_boxes = make_bounding_box()
660+
assert F.get_spatial_size(bounding_boxes) == F.get_spatial_size(image)
661661
"""
662662

663663
def sample_position(values, max_value):
@@ -679,7 +679,7 @@ def sample_position(values, max_value):
679679
dtype = dtype or torch.float32
680680

681681
if any(dim == 0 for dim in batch_dims):
682-
return datapoints.BoundingBox(
682+
return datapoints.BoundingBoxes(
683683
torch.empty(*batch_dims, 4, dtype=dtype, device=device), format=format, spatial_size=spatial_size
684684
)
685685

@@ -705,7 +705,7 @@ def sample_position(values, max_value):
705705
else:
706706
raise ValueError(f"Format {format} is not supported")
707707

708-
return datapoints.BoundingBox(
708+
return datapoints.BoundingBoxes(
709709
torch.stack(parts, dim=-1).to(dtype=dtype, device=device), format=format, spatial_size=spatial_size
710710
)
711711

@@ -725,7 +725,7 @@ def fn(shape, dtype, device):
725725
format=format, spatial_size=spatial_size, batch_dims=batch_dims, dtype=dtype, device=device
726726
)
727727

728-
return BoundingBoxLoader(fn, shape=(*extra_dims, 4), dtype=dtype, format=format, spatial_size=spatial_size)
728+
return BoundingBoxesLoader(fn, shape=(*extra_dims, 4), dtype=dtype, format=format, spatial_size=spatial_size)
729729

730730

731731
def make_bounding_box_loaders(

test/test_datapoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_mask_instance(data):
2727
"format", ["XYXY", "CXCYWH", datapoints.BoundingBoxFormat.XYXY, datapoints.BoundingBoxFormat.XYWH]
2828
)
2929
def test_bbox_instance(data, format):
30-
bboxes = datapoints.BoundingBox(data, format=format, spatial_size=(32, 32))
30+
bboxes = datapoints.BoundingBoxes(data, format=format, spatial_size=(32, 32))
3131
assert isinstance(bboxes, torch.Tensor)
3232
assert bboxes.ndim == 2 and bboxes.shape[1] == 4
3333
if isinstance(format, str):
@@ -164,7 +164,7 @@ def test_wrap_like():
164164
[
165165
datapoints.Image(torch.rand(3, 16, 16)),
166166
datapoints.Video(torch.rand(2, 3, 16, 16)),
167-
datapoints.BoundingBox([0.0, 1.0, 2.0, 3.0], format=datapoints.BoundingBoxFormat.XYXY, spatial_size=(10, 10)),
167+
datapoints.BoundingBoxes([0.0, 1.0, 2.0, 3.0], format=datapoints.BoundingBoxFormat.XYXY, spatial_size=(10, 10)),
168168
datapoints.Mask(torch.randint(0, 256, (16, 16), dtype=torch.uint8)),
169169
],
170170
)

test/test_prototype_transforms.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from prototype_common_utils import make_label, make_one_hot_labels
2222

23-
from torchvision.datapoints import BoundingBox, BoundingBoxFormat, Image, Mask, Video
23+
from torchvision.datapoints import BoundingBoxes, BoundingBoxFormat, Image, Mask, Video
2424
from torchvision.prototype import datapoints, transforms
2525
from torchvision.transforms.v2._utils import _convert_fill_arg
2626
from torchvision.transforms.v2.functional import InterpolationMode, pil_to_tensor, to_image_pil
@@ -101,10 +101,10 @@ def test__extract_image_targets_assertion(self, mocker):
101101
self.create_fake_image(mocker, Image),
102102
# labels, bboxes, masks
103103
mocker.MagicMock(spec=datapoints.Label),
104-
mocker.MagicMock(spec=BoundingBox),
104+
mocker.MagicMock(spec=BoundingBoxes),
105105
mocker.MagicMock(spec=Mask),
106106
# labels, bboxes, masks
107-
mocker.MagicMock(spec=BoundingBox),
107+
mocker.MagicMock(spec=BoundingBoxes),
108108
mocker.MagicMock(spec=Mask),
109109
]
110110

@@ -122,11 +122,11 @@ def test__extract_image_targets(self, image_type, label_type, mocker):
122122
self.create_fake_image(mocker, image_type),
123123
# labels, bboxes, masks
124124
mocker.MagicMock(spec=label_type),
125-
mocker.MagicMock(spec=BoundingBox),
125+
mocker.MagicMock(spec=BoundingBoxes),
126126
mocker.MagicMock(spec=Mask),
127127
# labels, bboxes, masks
128128
mocker.MagicMock(spec=label_type),
129-
mocker.MagicMock(spec=BoundingBox),
129+
mocker.MagicMock(spec=BoundingBoxes),
130130
mocker.MagicMock(spec=Mask),
131131
]
132132

@@ -142,7 +142,7 @@ def test__extract_image_targets(self, image_type, label_type, mocker):
142142

143143
for target in targets:
144144
for key, type_ in [
145-
("boxes", BoundingBox),
145+
("boxes", BoundingBoxes),
146146
("masks", Mask),
147147
("labels", label_type),
148148
]:
@@ -163,7 +163,7 @@ def test__copy_paste(self, label_type):
163163
if label_type == datapoints.OneHotLabel:
164164
labels = torch.nn.functional.one_hot(labels, num_classes=5)
165165
target = {
166-
"boxes": BoundingBox(
166+
"boxes": BoundingBoxes(
167167
torch.tensor([[2.0, 3.0, 8.0, 9.0], [20.0, 20.0, 30.0, 30.0]]), format="XYXY", spatial_size=(32, 32)
168168
),
169169
"masks": Mask(masks),
@@ -178,7 +178,7 @@ def test__copy_paste(self, label_type):
178178
if label_type == datapoints.OneHotLabel:
179179
paste_labels = torch.nn.functional.one_hot(paste_labels, num_classes=5)
180180
paste_target = {
181-
"boxes": BoundingBox(
181+
"boxes": BoundingBoxes(
182182
torch.tensor([[12.0, 13.0, 19.0, 18.0], [1.0, 15.0, 8.0, 19.0]]), format="XYXY", spatial_size=(32, 32)
183183
),
184184
"masks": Mask(paste_masks),
@@ -332,7 +332,7 @@ def test__transform_culling(self, mocker):
332332
assert_equal(output["masks"], masks[is_valid])
333333
assert_equal(output["labels"], labels[is_valid])
334334

335-
def test__transform_bounding_box_clamping(self, mocker):
335+
def test__transform_bounding_boxes_clamping(self, mocker):
336336
batch_size = 3
337337
spatial_size = (10, 10)
338338

@@ -349,15 +349,15 @@ def test__transform_bounding_box_clamping(self, mocker):
349349
),
350350
)
351351

352-
bounding_box = make_bounding_box(
352+
bounding_boxes = make_bounding_box(
353353
format=BoundingBoxFormat.XYXY, spatial_size=spatial_size, batch_dims=(batch_size,)
354354
)
355-
mock = mocker.patch("torchvision.prototype.transforms._geometry.F.clamp_bounding_box")
355+
mock = mocker.patch("torchvision.prototype.transforms._geometry.F.clamp_bounding_boxes")
356356

357357
transform = transforms.FixedSizeCrop((-1, -1))
358358
mocker.patch("torchvision.prototype.transforms._geometry.has_any", return_value=True)
359359

360-
transform(bounding_box)
360+
transform(bounding_boxes)
361361

362362
mock.assert_called_once()
363363

@@ -390,7 +390,7 @@ class TestPermuteDimensions:
390390
def test_call(self, dims, inverse_dims):
391391
sample = dict(
392392
image=make_image(),
393-
bounding_box=make_bounding_box(format=BoundingBoxFormat.XYXY),
393+
bounding_boxes=make_bounding_box(format=BoundingBoxFormat.XYXY),
394394
video=make_video(),
395395
str="str",
396396
int=0,
@@ -434,7 +434,7 @@ class TestTransposeDimensions:
434434
def test_call(self, dims):
435435
sample = dict(
436436
image=make_image(),
437-
bounding_box=make_bounding_box(format=BoundingBoxFormat.XYXY),
437+
bounding_boxes=make_bounding_box(format=BoundingBoxFormat.XYXY),
438438
video=make_video(),
439439
str="str",
440440
int=0,

0 commit comments

Comments
 (0)