| 54 | box_dim: int = 0 |
| 55 | |
| 56 | def __init__(self, |
| 57 | data: Union[Tensor, np.ndarray, Sequence], |
| 58 | dtype: Optional[torch.dtype] = None, |
| 59 | device: Optional[DeviceType] = None, |
| 60 | clone: bool = True) -> None: |
| 61 | if isinstance(data, (np.ndarray, Tensor, Sequence)): |
| 62 | data = torch.as_tensor(data) |
| 63 | else: |
| 64 | raise TypeError('boxes should be Tensor, ndarray, or Sequence, ', |
| 65 | f'but got {type(data)}') |
| 66 | |
| 67 | if device is not None or dtype is not None: |
| 68 | data = data.to(dtype=dtype, device=device) |
| 69 | # Clone the data to avoid potential bugs |
| 70 | if clone: |
| 71 | data = data.clone() |
| 72 | # handle the empty input like [] |
| 73 | if data.numel() == 0: |
| 74 | data = data.reshape((-1, self.box_dim)) |
| 75 | |
| 76 | assert data.dim() >= 2 and data.size(-1) == self.box_dim, \ |
| 77 | ('The boxes dimension must >= 2 and the length of the last ' |
| 78 | f'dimension must be {self.box_dim}, but got boxes with ' |
| 79 | f'shape {data.shape}.') |
| 80 | self.tensor = data |
| 81 | |
| 82 | def convert_to(self, dst_type: Union[str, type]) -> 'BaseBoxes': |
| 83 | """Convert self to another box type. |