Skip to content

Added the KeyPoints TVTensor #8817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8253305
Added Keypoints to the library
Alexandre-SCHOEPP Dec 12, 2024
484561d
Improved KeyPoints to be exported
Alexandre-SCHOEPP Dec 13, 2024
3255890
Added kernels to support the keypoints
Alexandre-SCHOEPP Dec 13, 2024
7436636
Added tests for keypoints
Alexandre-SCHOEPP Dec 13, 2024
b35cba6
Applied ufmt formatting
Alexandre-SCHOEPP Dec 13, 2024
a19ec0b
Fixed the bugs found while testing
Alexandre-SCHOEPP Dec 16, 2024
5f4b188
Improved documentation to take KeyPoints into account
Alexandre-SCHOEPP Dec 17, 2024
cabce1c
Applied ufmt check
Alexandre-SCHOEPP Dec 17, 2024
d1b27ad
Fixed the hflip not being along the right coordinate
Alexandre-SCHOEPP Dec 17, 2024
6fa38f4
Merge branch 'main' into main
Alexandre-SCHOEPP Dec 18, 2024
05e4ad6
Merge branch 'main' into main
Alexandre-SCHOEPP Feb 10, 2025
03dc6c8
Merge branch 'main' into main
Alexandre-SCHOEPP Feb 20, 2025
d4d087c
Merge branch 'main' into main
Alexandre-SCHOEPP Mar 4, 2025
5a8c5b4
Fixed order of arguments
Alex-S-H-P Apr 30, 2025
dea31e2
Reworked logic of the conditions to better handle mutable/non mutable…
Alex-S-H-P Apr 30, 2025
71e20a5
Renamed out variable to be more similar with _resized_crop_bounding_b…
Alex-S-H-P Apr 30, 2025
2f77527
renamed _xyxy_to_points to _xyxy_to_keypoints for consistency
Alex-S-H-P Apr 30, 2025
517a6de
clarified _xyxy_to_points and changed the name of its caller for the …
Alex-S-H-P Apr 30, 2025
63ed4a5
Renamed half_point to more explicit single_coord_shape
Alex-S-H-P Apr 30, 2025
166c1ec
Integrated KeyPoints better in the transforms. It now warns alongside…
Alex-S-H-P Apr 30, 2025
fcfd597
Merge branch 'main' into main
Alexandre-SCHOEPP Apr 30, 2025
1cc3b6f
Fixed _geometry.py post botched merge request
Alex-S-H-P Apr 30, 2025
841de77
Review python 3.9 type hint and lint
AntoineSimoulin May 3, 2025
ff6ab48
Add specific keypoint tests
AntoineSimoulin May 3, 2025
0de59e7
Adjust variable names
AntoineSimoulin May 4, 2025
4b62ef4
Improved documentation inside of the KeyPoints class definition
Alex-S-H-P May 5, 2025
e99b82a
Improved convert_bounding_boxes_to_points to handle rotated bounding …
Alex-S-H-P May 5, 2025
a869f39
Applied ufmt
Alex-S-H-P May 5, 2025
6007b2c
Adding a type:ignore[override] on KeyPoints__repr__ as it also exist …
Alex-S-H-P May 5, 2025
b68b57b
Fixed flake8 compliance on "..." present in the line of the __init__ …
Alex-S-H-P May 5, 2025
801e24d
get_all_keypoints is now get_keypoints and returns the only keypoints…
Alex-S-H-P May 5, 2025
73a40a8
Fixed docstring on sanitize_keypoints
Alex-S-H-P May 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/tv_tensors.rst
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ info.

Image
Video
KeyPoints
BoundingBoxFormat
BoundingBoxes
Mask
11 changes: 10 additions & 1 deletion gallery/transforms/plot_tv_tensors.py
Original file line number Diff line number Diff line change
@@ -46,11 +46,12 @@
# Under the hood, they are needed in :mod:`torchvision.transforms.v2` to correctly dispatch to the appropriate function
# for the input data.
#
# :mod:`torchvision.tv_tensors` supports four types of TVTensors:
# :mod:`torchvision.tv_tensors` supports five types of TVTensors:
#
# * :class:`~torchvision.tv_tensors.Image`
# * :class:`~torchvision.tv_tensors.Video`
# * :class:`~torchvision.tv_tensors.BoundingBoxes`
# * :class:`~torchvision.tv_tensors.KeyPoints`
# * :class:`~torchvision.tv_tensors.Mask`
#
# What can I do with a TVTensor?
@@ -96,6 +97,7 @@
# :class:`~torchvision.tv_tensors.BoundingBoxes` requires the coordinate format as well as the size of the
# corresponding image (``canvas_size``) alongside the actual values. These
# metadata are required to properly transform the bounding boxes.
# In a similar fashion, :class:`~torchvision.tv_tensors.KeyPoints` also require the ``canvas_size`` metadata to be added.

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


keypoints = tv_tensors.KeyPoints(
[[17, 16], [344, 495], [0, 10], [0, 10]],
canvas_size=image.shape[-2:]
)
print(keypoints)

# %%
# Using ``tv_tensors.wrap()``
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15 changes: 15 additions & 0 deletions test/common_utils.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
import sys
import tempfile
import warnings
from collections.abc import Sequence
from subprocess import CalledProcessError, check_output, STDOUT

import numpy as np
@@ -400,6 +401,20 @@ def make_image_pil(*args, **kwargs):
return to_pil_image(make_image(*args, **kwargs))


def make_keypoints(
canvas_size: tuple[int, int] = DEFAULT_SIZE, *, num_points: int | Sequence[int] = 4, dtype=None, device="cpu"
) -> tv_tensors.KeyPoints:
"""Make the KeyPoints for testing purposes"""
if isinstance(num_points, int):
num_points = [num_points]
single_coord_shape: tuple[int, ...] = tuple(num_points) + (1,)
y = torch.randint(0, canvas_size[0] - 1, single_coord_shape, dtype=dtype, device=device)
x = torch.randint(0, canvas_size[1] - 1, single_coord_shape, dtype=dtype, device=device)
points = torch.cat((x, y), dim=-1)
keypoints = tv_tensors.KeyPoints(points, canvas_size=canvas_size)
return keypoints


def make_bounding_boxes(
canvas_size=DEFAULT_SIZE,
*,
Loading