Unverified Commit a376f797 authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

add docs for datapoints (#7312)


Co-authored-by: default avatarNicolas Hug <contact@nicolas-hug.com>
parent be798eff
Datapoints
==========
.. currentmodule:: torchvision.datapoints
.. autosummary::
:toctree: generated/
:template: class.rst
Image
Video
BoundingBoxFormat
BoundingBox
Mask
...@@ -31,6 +31,7 @@ architectures, and common image transformations for computer vision. ...@@ -31,6 +31,7 @@ architectures, and common image transformations for computer vision.
:maxdepth: 2 :maxdepth: 2
:caption: Package Reference :caption: Package Reference
datapoints
transforms transforms
models models
datasets datasets
......
...@@ -10,12 +10,35 @@ from ._datapoint import _FillTypeJIT, Datapoint ...@@ -10,12 +10,35 @@ from ._datapoint import _FillTypeJIT, Datapoint
class BoundingBoxFormat(Enum): class BoundingBoxFormat(Enum):
"""[BETA] Coordinate format of a bounding box.
Available formats are
* ``XYXY``
* ``XYWH``
* ``CXCYWH``
"""
XYXY = "XYXY" XYXY = "XYXY"
XYWH = "XYWH" XYWH = "XYWH"
CXCYWH = "CXCYWH" CXCYWH = "CXCYWH"
class BoundingBox(Datapoint): class BoundingBox(Datapoint):
"""[BETA] :class:`torch.Tensor` subclass for bounding boxes.
Args:
data: Any data that can be turned into a tensor with :func:`torch.as_tensor`.
format (BoundingBoxFormat, str): Format of the bounding box.
spatial_size (two-tuple of ints): Height and width of the corresponding image or video.
dtype (torch.dtype, optional): Desired data type of the bounding box. If omitted, will be inferred from
``data``.
device (torch.device, optional): Desired device of the bounding box. If omitted and ``data`` is a
:class:`torch.Tensor`, the device is taken from it. Otherwise, the bounding box is constructed on the CPU.
requires_grad (bool, optional): Whether autograd should record operations on the bounding box. If omitted and
``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
"""
format: BoundingBoxFormat format: BoundingBoxFormat
spatial_size: Tuple[int, int] spatial_size: Tuple[int, int]
...@@ -52,6 +75,20 @@ class BoundingBox(Datapoint): ...@@ -52,6 +75,20 @@ class BoundingBox(Datapoint):
format: Optional[BoundingBoxFormat] = None, format: Optional[BoundingBoxFormat] = None,
spatial_size: Optional[Tuple[int, int]] = None, spatial_size: Optional[Tuple[int, int]] = None,
) -> BoundingBox: ) -> BoundingBox:
"""Wrap a :class:`torch.Tensor` as :class:`BoundingBox` from a reference.
Args:
other (BoundingBox): Reference bounding box.
tensor (Tensor): Tensor to be wrapped as :class:`BoundingBox`
format (BoundingBoxFormat, str, optional): Format of the bounding box. If omitted, it is taken from the
reference.
spatial_size (two-tuple of ints, optional): Height and width of the corresponding image or video. If
omitted, it is taken from the reference.
"""
if isinstance(format, str):
format = BoundingBoxFormat.from_str(format.upper())
return cls._wrap( return cls._wrap(
tensor, tensor,
format=format if format is not None else other.format, format=format if format is not None else other.format,
......
...@@ -10,6 +10,19 @@ from ._datapoint import _FillTypeJIT, Datapoint ...@@ -10,6 +10,19 @@ from ._datapoint import _FillTypeJIT, Datapoint
class Image(Datapoint): class Image(Datapoint):
"""[BETA] :class:`torch.Tensor` subclass for images.
Args:
data (tensor-like, PIL.Image.Image): Any data that can be turned into a tensor with :func:`torch.as_tensor` as
well as PIL images.
dtype (torch.dtype, optional): Desired data type of the bounding box. If omitted, will be inferred from
``data``.
device (torch.device, optional): Desired device of the bounding box. If omitted and ``data`` is a
:class:`torch.Tensor`, the device is taken from it. Otherwise, the bounding box is constructed on the CPU.
requires_grad (bool, optional): Whether autograd should record operations on the bounding box. If omitted and
``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
"""
@classmethod @classmethod
def _wrap(cls, tensor: torch.Tensor) -> Image: def _wrap(cls, tensor: torch.Tensor) -> Image:
image = tensor.as_subclass(cls) image = tensor.as_subclass(cls)
......
...@@ -10,6 +10,19 @@ from ._datapoint import _FillTypeJIT, Datapoint ...@@ -10,6 +10,19 @@ from ._datapoint import _FillTypeJIT, Datapoint
class Mask(Datapoint): class Mask(Datapoint):
"""[BETA] :class:`torch.Tensor` subclass for segmentation and detection masks.
Args:
data (tensor-like, PIL.Image.Image): Any data that can be turned into a tensor with :func:`torch.as_tensor` as
well as PIL images.
dtype (torch.dtype, optional): Desired data type of the bounding box. If omitted, will be inferred from
``data``.
device (torch.device, optional): Desired device of the bounding box. If omitted and ``data`` is a
:class:`torch.Tensor`, the device is taken from it. Otherwise, the bounding box is constructed on the CPU.
requires_grad (bool, optional): Whether autograd should record operations on the bounding box. If omitted and
``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
"""
@classmethod @classmethod
def _wrap(cls, tensor: torch.Tensor) -> Mask: def _wrap(cls, tensor: torch.Tensor) -> Mask:
return tensor.as_subclass(cls) return tensor.as_subclass(cls)
......
...@@ -9,6 +9,18 @@ from ._datapoint import _FillTypeJIT, Datapoint ...@@ -9,6 +9,18 @@ from ._datapoint import _FillTypeJIT, Datapoint
class Video(Datapoint): class Video(Datapoint):
"""[BETA] :class:`torch.Tensor` subclass for videos.
Args:
data (tensor-like): Any data that can be turned into a tensor with :func:`torch.as_tensor`.
dtype (torch.dtype, optional): Desired data type of the bounding box. If omitted, will be inferred from
``data``.
device (torch.device, optional): Desired device of the bounding box. If omitted and ``data`` is a
:class:`torch.Tensor`, the device is taken from it. Otherwise, the bounding box is constructed on the CPU.
requires_grad (bool, optional): Whether autograd should record operations on the bounding box. If omitted and
``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
"""
@classmethod @classmethod
def _wrap(cls, tensor: torch.Tensor) -> Video: def _wrap(cls, tensor: torch.Tensor) -> Video:
video = tensor.as_subclass(cls) video = tensor.as_subclass(cls)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment