MCPcopy Create free account
hub / github.com/PolyU-ChenLab/UniPixel / transform_coords

Method transform_coords

sam2/utils/transforms.py:44–60  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

transform_boxesMethod · 0.95
_process_batchMethod · 0.80
_prep_promptsMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected