__init__.py 1.23 KB
Newer Older
1
import torch
2

3
from ._bounding_boxes import BoundingBoxes, BoundingBoxFormat
4
from ._image import Image
5
from ._mask import Mask
6
from ._torch_function_helpers import set_return_type
7
from ._tv_tensor import TVTensor
8
from ._video import Video
9

10
11

def wrap(wrappee, *, like, **kwargs):
12
    """[BETA] Convert a :class:`torch.Tensor` (``wrappee``) into the same :class:`~torchvision.tv_tensors.TVTensor` subclass as ``like``.
13

14
    If ``like`` is a :class:`~torchvision.tv_tensors.BoundingBoxes`, the ``format`` and ``canvas_size`` of
15
16
17
18
    ``like`` are assigned to ``wrappee``, unless they are passed as ``kwargs``.

    Args:
        wrappee (Tensor): The tensor to convert.
19
        like (:class:`~torchvision.tv_tensors.TVTensor`): The reference.
Nicolas Hug's avatar
Nicolas Hug committed
20
            ``wrappee`` will be converted into the same subclass as ``like``.
21
        kwargs: Can contain "format" and "canvas_size" if ``like`` is a :class:`~torchvision.tv_tensor.BoundingBoxes`.
22
23
24
25
26
27
28
29
30
31
            Ignored otherwise.
    """
    if isinstance(like, BoundingBoxes):
        return BoundingBoxes._wrap(
            wrappee,
            format=kwargs.get("format", like.format),
            canvas_size=kwargs.get("canvas_size", like.canvas_size),
        )
    else:
        return wrappee.as_subclass(type(like))