Clip (in place) the boxes by limiting x coordinates to the range [0, width] and y coordinates to the range [0, height]. Args: box_size (height, width): The clipping box's size.
(self, box_size: Tuple[int, int])
| 179 | return area |
| 180 | |
| 181 | def clip(self, box_size: Tuple[int, int]) -> None: |
| 182 | """ |
| 183 | Clip (in place) the boxes by limiting x coordinates to the range [0, width] |
| 184 | and y coordinates to the range [0, height]. |
| 185 | |
| 186 | Args: |
| 187 | box_size (height, width): The clipping box's size. |
| 188 | """ |
| 189 | assert torch.isfinite(self.tensor).all(), "Box tensor contains infinite or NaN!" |
| 190 | h, w = box_size |
| 191 | x1 = self.tensor[:, 0].clamp(min=0, max=w) |
| 192 | y1 = self.tensor[:, 1].clamp(min=0, max=h) |
| 193 | x2 = self.tensor[:, 2].clamp(min=0, max=w) |
| 194 | y2 = self.tensor[:, 3].clamp(min=0, max=h) |
| 195 | self.tensor = torch.stack((x1, y1, x2, y2), dim=-1) |
| 196 | |
| 197 | def nonempty(self, threshold: float = 0.0) -> torch.Tensor: |
| 198 | """ |