Skip to content

Commit 809b71c

Browse files
Merge branch 'main' into rotated-bboxes-transforms
2 parents 4050cb9 + 6473b77 commit 809b71c

File tree

21 files changed

+1622
-119
lines changed

21 files changed

+1622
-119
lines changed

docs/source/transforms.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ range of the inputs.
101101
V1 or V2? Which one should I use?
102102
---------------------------------
103103

104-
**TL;DR** We recommending using the ``torchvision.transforms.v2`` transforms
104+
**TL;DR** We recommend using the ``torchvision.transforms.v2`` transforms
105105
instead of those in ``torchvision.transforms``. They're faster and they can do
106106
more things. Just change the import and you should be good to go. Moving
107107
forward, new features and improvements will only be considered for the v2
@@ -408,6 +408,7 @@ Miscellaneous
408408
v2.Lambda
409409
v2.SanitizeBoundingBoxes
410410
v2.ClampBoundingBoxes
411+
v2.ClampKeyPoints
411412
v2.UniformTemporalSubsample
412413
v2.JPEG
413414

@@ -421,6 +422,7 @@ Functionals
421422
v2.functional.erase
422423
v2.functional.sanitize_bounding_boxes
423424
v2.functional.clamp_bounding_boxes
425+
v2.functional.clamp_keypoints
424426
v2.functional.uniform_temporal_subsample
425427
v2.functional.jpeg
426428

docs/source/tv_tensors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ info.
2121

2222
Image
2323
Video
24+
KeyPoints
2425
BoundingBoxFormat
2526
BoundingBoxes
2627
Mask

gallery/transforms/plot_tv_tensors.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
# Under the hood, they are needed in :mod:`torchvision.transforms.v2` to correctly dispatch to the appropriate function
4747
# for the input data.
4848
#
49-
# :mod:`torchvision.tv_tensors` supports four types of TVTensors:
49+
# :mod:`torchvision.tv_tensors` supports five types of TVTensors:
5050
#
5151
# * :class:`~torchvision.tv_tensors.Image`
5252
# * :class:`~torchvision.tv_tensors.Video`
5353
# * :class:`~torchvision.tv_tensors.BoundingBoxes`
54+
# * :class:`~torchvision.tv_tensors.KeyPoints`
5455
# * :class:`~torchvision.tv_tensors.Mask`
5556
#
5657
# What can I do with a TVTensor?
@@ -96,6 +97,7 @@
9697
# :class:`~torchvision.tv_tensors.BoundingBoxes` requires the coordinate format as well as the size of the
9798
# corresponding image (``canvas_size``) alongside the actual values. These
9899
# metadata are required to properly transform the bounding boxes.
100+
# In a similar fashion, :class:`~torchvision.tv_tensors.KeyPoints` also require the ``canvas_size`` metadata to be added.
99101

100102
bboxes = tv_tensors.BoundingBoxes(
101103
[[17, 16, 344, 495], [0, 10, 0, 10]],
@@ -104,6 +106,13 @@
104106
)
105107
print(bboxes)
106108

109+
110+
keypoints = tv_tensors.KeyPoints(
111+
[[17, 16], [344, 495], [0, 10], [0, 10]],
112+
canvas_size=image.shape[-2:]
113+
)
114+
print(keypoints)
115+
107116
# %%
108117
# Using ``tv_tensors.wrap()``
109118
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^

test/common_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,12 @@ def make_image_pil(*args, **kwargs):
400400
return to_pil_image(make_image(*args, **kwargs))
401401

402402

403+
def make_keypoints(canvas_size=DEFAULT_SIZE, *, num_points=4, dtype=None, device="cpu"):
404+
y = torch.randint(0, canvas_size[0], size=(num_points, 1), dtype=dtype, device=device)
405+
x = torch.randint(0, canvas_size[1], size=(num_points, 1), dtype=dtype, device=device)
406+
return tv_tensors.KeyPoints(torch.cat((x, y), dim=-1), canvas_size=canvas_size)
407+
408+
403409
def make_bounding_boxes(
404410
canvas_size=DEFAULT_SIZE,
405411
*,

0 commit comments

Comments
 (0)