"src/targets/vscode:/vscode.git/clone" did not exist on "55156faa4132e3de00b8b0cbd79dd6685514e03a"
__init__.py 1.48 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
12
13
14
# TODO: Fix this. We skip this method as it leads to
# RecursionError: maximum recursion depth exceeded while calling a Python object
# Until `disable` is removed, there will be graph breaks after all calls to functional transforms
@torch.compiler.disable
15
def wrap(wrappee, *, like, **kwargs):
16
    """[BETA] Convert a :class:`torch.Tensor` (``wrappee``) into the same :class:`~torchvision.tv_tensors.TVTensor` subclass as ``like``.
17

18
    If ``like`` is a :class:`~torchvision.tv_tensors.BoundingBoxes`, the ``format`` and ``canvas_size`` of
19
20
21
22
    ``like`` are assigned to ``wrappee``, unless they are passed as ``kwargs``.

    Args:
        wrappee (Tensor): The tensor to convert.
23
        like (:class:`~torchvision.tv_tensors.TVTensor`): The reference.
Nicolas Hug's avatar
Nicolas Hug committed
24
            ``wrappee`` will be converted into the same subclass as ``like``.
25
        kwargs: Can contain "format" and "canvas_size" if ``like`` is a :class:`~torchvision.tv_tensor.BoundingBoxes`.
26
27
28
29
30
31
32
33
34
35
            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))