_video.py 1.57 KB
Newer Older
1
2
from __future__ import annotations

3
from typing import Any, Optional, Union
4
5
6

import torch

7
from ._datapoint import Datapoint
8
9


10
class Video(Datapoint):
Philip Meier's avatar
Philip Meier committed
11
12
13
14
15
16
17
18
19
20
21
22
    """[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``.
    """

23
24
25
26
27
28
    def __new__(
        cls,
        data: Any,
        *,
        dtype: Optional[torch.dtype] = None,
        device: Optional[Union[torch.device, str, int]] = None,
29
        requires_grad: Optional[bool] = None,
30
    ) -> Video:
31
        tensor = cls._to_tensor(data, dtype=dtype, device=device, requires_grad=requires_grad)
32
33
        if data.ndim < 4:
            raise ValueError
34
        return tensor.as_subclass(cls)
35

36
    def __repr__(self, *, tensor_contents: Any = None) -> str:  # type: ignore[override]
37
        return self._make_repr()
38

39

Philip Meier's avatar
Philip Meier committed
40
41
42
43
_VideoType = Union[torch.Tensor, Video]
_VideoTypeJIT = torch.Tensor
_TensorVideoType = Union[torch.Tensor, Video]
_TensorVideoTypeJIT = torch.Tensor