Args: tensor (Tensor[float]): a Nx4 matrix. Each row is (x1, y1, x2, y2).
(self, tensor: torch.Tensor)
| 140 | """ |
| 141 | |
| 142 | def __init__(self, tensor: torch.Tensor): |
| 143 | """ |
| 144 | Args: |
| 145 | tensor (Tensor[float]): a Nx4 matrix. Each row is (x1, y1, x2, y2). |
| 146 | """ |
| 147 | device = tensor.device if isinstance(tensor, torch.Tensor) else torch.device("cpu") |
| 148 | tensor = torch.as_tensor(tensor, dtype=torch.float32, device=device) |
| 149 | if tensor.numel() == 0: |
| 150 | # Use reshape, so we don't end up creating a new tensor that does not depend on |
| 151 | # the inputs (and consequently confuses jit) |
| 152 | tensor = tensor.reshape((-1, 4)).to(dtype=torch.float32, device=device) |
| 153 | assert tensor.dim() == 2 and tensor.size(-1) == 4, tensor.size() |
| 154 | |
| 155 | self.tensor = tensor |
| 156 | |
| 157 | def clone(self) -> "Boxes": |
| 158 | """ |