Expects a torch tensor with length 2 in the last dimension. The coordinates can be in absolute image or normalized coordinates, If the coords are in absolute image coordinates, normalize should be set to True and original image size is required. Returns Un-norma
(
self, coords: torch.Tensor, normalize=False, orig_hw=None
)
| 42 | return img_batch |
| 43 | |
| 44 | def transform_coords( |
| 45 | self, coords: torch.Tensor, normalize=False, orig_hw=None |
| 46 | ) -> torch.Tensor: |
| 47 | """ |
| 48 | Expects a torch tensor with length 2 in the last dimension. The coordinates can be in absolute image or normalized coordinates, |
| 49 | If the coords are in absolute image coordinates, normalize should be set to True and original image size is required. |
| 50 | |
| 51 | Returns |
| 52 | Un-normalized coordinates in the range of [0, 1] which is expected by the SAM2 model. |
| 53 | """ |
| 54 | if normalize: |
| 55 | assert orig_hw is not None |
| 56 | h, w = orig_hw |
| 57 | coords = coords.clone() |
| 58 | coords[..., 0] = coords[..., 0] / w |
| 59 | coords[..., 1] = coords[..., 1] / h |
| 60 | |
| 61 | coords = coords * self.resolution # unnormalize coords |
| 62 | return coords |
| 63 | |
| 64 | def transform_boxes( |
| 65 | self, boxes: torch.Tensor, normalize=False, orig_hw=None |
no outgoing calls
no test coverage detected