MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / point_sample

Function point_sample

semantic_sam/modules/point_features.py:21–44  ·  view source on GitHub ↗

A wrapper around :function:`torch.nn.functional.grid_sample` to support 3D point_coords tensors. Unlike :function:`torch.nn.functional.grid_sample` it assumes `point_coords` to lie inside [0, 1] x [0, 1] square. Args: input (Tensor): A tensor of shape (N, C, H, W) that cont

(input, point_coords, **kwargs)

Source from the content-addressed store, hash-verified

19
20
21def point_sample(input, point_coords, **kwargs):
22 """
23 A wrapper around :function:`torch.nn.functional.grid_sample` to support 3D point_coords tensors.
24 Unlike :function:`torch.nn.functional.grid_sample` it assumes `point_coords` to lie inside
25 [0, 1] x [0, 1] square.
26
27 Args:
28 input (Tensor): A tensor of shape (N, C, H, W) that contains features map on a H x W grid.
29 point_coords (Tensor): A tensor of shape (N, P, 2) or (N, Hgrid, Wgrid, 2) that contains
30 [0, 1] x [0, 1] normalized point coordinates.
31
32 Returns:
33 output (Tensor): A tensor of shape (N, C, P) or (N, C, Hgrid, Wgrid) that contains
34 features for points in `point_coords`. The features are obtained via bilinear
35 interplation from `input` the same way as :function:`torch.nn.functional.grid_sample`.
36 """
37 add_dim = False
38 if point_coords.dim() == 3:
39 add_dim = True
40 point_coords = point_coords.unsqueeze(2)
41 output = F.grid_sample(input, 2.0 * point_coords - 1.0, **kwargs)
42 if add_dim:
43 output = output.squeeze(3)
44 return output
45
46
47def generate_regular_grid_point_coords(R, side_size, device):

Callers 7

loss_masksMethod · 0.90
loss_masksMethod · 0.90
sample_point_labelsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected