MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / point_sample

Function point_sample

PATH/core/models/decoders/losses/point_features.py:29–52  ·  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

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

Calls 1

dimMethod · 0.80

Tested by

no test coverage detected