Skip to content

Commit a376f79

Browse files
pmeierNicolasHug
andauthored
add docs for datapoints (#7312)
Co-authored-by: Nicolas Hug <[email protected]>
1 parent be798ef commit a376f79

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

docs/source/datapoints.rst

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Datapoints
2+
==========
3+
4+
.. currentmodule:: torchvision.datapoints
5+
.. autosummary::
6+
:toctree: generated/
7+
:template: class.rst
8+
9+
Image
10+
Video
11+
BoundingBoxFormat
12+
BoundingBox
13+
Mask

docs/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ architectures, and common image transformations for computer vision.
3131
:maxdepth: 2
3232
:caption: Package Reference
3333

34+
datapoints
3435
transforms
3536
models
3637
datasets

torchvision/datapoints/_bounding_box.py

+37
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,35 @@
1010

1111

1212
class BoundingBoxFormat(Enum):
13+
"""[BETA] Coordinate format of a bounding box.
14+
15+
Available formats are
16+
17+
* ``XYXY``
18+
* ``XYWH``
19+
* ``CXCYWH``
20+
"""
21+
1322
XYXY = "XYXY"
1423
XYWH = "XYWH"
1524
CXCYWH = "CXCYWH"
1625

1726

1827
class BoundingBox(Datapoint):
28+
"""[BETA] :class:`torch.Tensor` subclass for bounding boxes.
29+
30+
Args:
31+
data: Any data that can be turned into a tensor with :func:`torch.as_tensor`.
32+
format (BoundingBoxFormat, str): Format of the bounding box.
33+
spatial_size (two-tuple of ints): Height and width of the corresponding image or video.
34+
dtype (torch.dtype, optional): Desired data type of the bounding box. If omitted, will be inferred from
35+
``data``.
36+
device (torch.device, optional): Desired device of the bounding box. If omitted and ``data`` is a
37+
:class:`torch.Tensor`, the device is taken from it. Otherwise, the bounding box is constructed on the CPU.
38+
requires_grad (bool, optional): Whether autograd should record operations on the bounding box. If omitted and
39+
``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
40+
"""
41+
1942
format: BoundingBoxFormat
2043
spatial_size: Tuple[int, int]
2144

@@ -52,6 +75,20 @@ def wrap_like(
5275
format: Optional[BoundingBoxFormat] = None,
5376
spatial_size: Optional[Tuple[int, int]] = None,
5477
) -> BoundingBox:
78+
"""Wrap a :class:`torch.Tensor` as :class:`BoundingBox` from a reference.
79+
80+
Args:
81+
other (BoundingBox): Reference bounding box.
82+
tensor (Tensor): Tensor to be wrapped as :class:`BoundingBox`
83+
format (BoundingBoxFormat, str, optional): Format of the bounding box. If omitted, it is taken from the
84+
reference.
85+
spatial_size (two-tuple of ints, optional): Height and width of the corresponding image or video. If
86+
omitted, it is taken from the reference.
87+
88+
"""
89+
if isinstance(format, str):
90+
format = BoundingBoxFormat.from_str(format.upper())
91+
5592
return cls._wrap(
5693
tensor,
5794
format=format if format is not None else other.format,

torchvision/datapoints/_image.py

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010

1111

1212
class Image(Datapoint):
13+
"""[BETA] :class:`torch.Tensor` subclass for images.
14+
15+
Args:
16+
data (tensor-like, PIL.Image.Image): Any data that can be turned into a tensor with :func:`torch.as_tensor` as
17+
well as PIL images.
18+
dtype (torch.dtype, optional): Desired data type of the bounding box. If omitted, will be inferred from
19+
``data``.
20+
device (torch.device, optional): Desired device of the bounding box. If omitted and ``data`` is a
21+
:class:`torch.Tensor`, the device is taken from it. Otherwise, the bounding box is constructed on the CPU.
22+
requires_grad (bool, optional): Whether autograd should record operations on the bounding box. If omitted and
23+
``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
24+
"""
25+
1326
@classmethod
1427
def _wrap(cls, tensor: torch.Tensor) -> Image:
1528
image = tensor.as_subclass(cls)

torchvision/datapoints/_mask.py

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010

1111

1212
class Mask(Datapoint):
13+
"""[BETA] :class:`torch.Tensor` subclass for segmentation and detection masks.
14+
15+
Args:
16+
data (tensor-like, PIL.Image.Image): Any data that can be turned into a tensor with :func:`torch.as_tensor` as
17+
well as PIL images.
18+
dtype (torch.dtype, optional): Desired data type of the bounding box. If omitted, will be inferred from
19+
``data``.
20+
device (torch.device, optional): Desired device of the bounding box. If omitted and ``data`` is a
21+
:class:`torch.Tensor`, the device is taken from it. Otherwise, the bounding box is constructed on the CPU.
22+
requires_grad (bool, optional): Whether autograd should record operations on the bounding box. If omitted and
23+
``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
24+
"""
25+
1326
@classmethod
1427
def _wrap(cls, tensor: torch.Tensor) -> Mask:
1528
return tensor.as_subclass(cls)

torchvision/datapoints/_video.py

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99

1010

1111
class Video(Datapoint):
12+
"""[BETA] :class:`torch.Tensor` subclass for videos.
13+
14+
Args:
15+
data (tensor-like): Any data that can be turned into a tensor with :func:`torch.as_tensor`.
16+
dtype (torch.dtype, optional): Desired data type of the bounding box. If omitted, will be inferred from
17+
``data``.
18+
device (torch.device, optional): Desired device of the bounding box. If omitted and ``data`` is a
19+
:class:`torch.Tensor`, the device is taken from it. Otherwise, the bounding box is constructed on the CPU.
20+
requires_grad (bool, optional): Whether autograd should record operations on the bounding box. If omitted and
21+
``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
22+
"""
23+
1224
@classmethod
1325
def _wrap(cls, tensor: torch.Tensor) -> Video:
1426
video = tensor.as_subclass(cls)

0 commit comments

Comments
 (0)