Args: item: int, slice, or a BoolTensor Returns: Boxes: Create a new :class:`Boxes` by indexing. The following usage are allowed: 1. `new_boxes = boxes[3]`: return a `Boxes` which contains only one box. 2. `new_boxes = boxes[2:10]`:
(self, item)
| 211 | return keep |
| 212 | |
| 213 | def __getitem__(self, item) -> "Boxes": |
| 214 | """ |
| 215 | Args: |
| 216 | item: int, slice, or a BoolTensor |
| 217 | |
| 218 | Returns: |
| 219 | Boxes: Create a new :class:`Boxes` by indexing. |
| 220 | |
| 221 | The following usage are allowed: |
| 222 | |
| 223 | 1. `new_boxes = boxes[3]`: return a `Boxes` which contains only one box. |
| 224 | 2. `new_boxes = boxes[2:10]`: return a slice of boxes. |
| 225 | 3. `new_boxes = boxes[vector]`, where vector is a torch.BoolTensor |
| 226 | with `length = len(boxes)`. Nonzero elements in the vector will be selected. |
| 227 | |
| 228 | Note that the returned Boxes might share storage with this Boxes, |
| 229 | subject to Pytorch's indexing semantics. |
| 230 | """ |
| 231 | if isinstance(item, int): |
| 232 | return Boxes(self.tensor[item].view(1, -1)) |
| 233 | b = self.tensor[item] |
| 234 | assert b.dim() == 2, "Indexing on Boxes with {} failed to return a matrix!".format(item) |
| 235 | return Boxes(b) |
| 236 | |
| 237 | def __len__(self) -> int: |
| 238 | return self.tensor.shape[0] |