|
10 | 10 |
|
11 | 11 |
|
12 | 12 | 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 | + |
13 | 22 | XYXY = "XYXY"
|
14 | 23 | XYWH = "XYWH"
|
15 | 24 | CXCYWH = "CXCYWH"
|
16 | 25 |
|
17 | 26 |
|
18 | 27 | 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 | + |
19 | 42 | format: BoundingBoxFormat
|
20 | 43 | spatial_size: Tuple[int, int]
|
21 | 44 |
|
@@ -52,6 +75,20 @@ def wrap_like(
|
52 | 75 | format: Optional[BoundingBoxFormat] = None,
|
53 | 76 | spatial_size: Optional[Tuple[int, int]] = None,
|
54 | 77 | ) -> 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 | + |
55 | 92 | return cls._wrap(
|
56 | 93 | tensor,
|
57 | 94 | format=format if format is not None else other.format,
|
|
0 commit comments