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)
| 19 | |
| 20 | |
| 21 | def 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 | |
| 47 | def generate_regular_grid_point_coords(R, side_size, device): |
no outgoing calls
no test coverage detected