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)
| 59 | return point_coords |
| 60 | |
| 61 | def point_sample(input, point_coords, **kwargs): |
| 62 | """ |
| 63 | A wrapper around :function:`torch.nn.functional.grid_sample` to support 3D point_coords tensors. |
| 64 | Unlike :function:`torch.nn.functional.grid_sample` it assumes `point_coords` to lie inside |
| 65 | [0, 1] x [0, 1] square. |
| 66 | |
| 67 | Args: |
| 68 | input (Tensor): A tensor of shape (N, C, H, W) that contains features map on a H x W grid. |
| 69 | point_coords (Tensor): A tensor of shape (N, P, 2) or (N, Hgrid, Wgrid, 2) that contains |
| 70 | [0, 1] x [0, 1] normalized point coordinates. |
| 71 | |
| 72 | Returns: |
| 73 | output (Tensor): A tensor of shape (N, C, P) or (N, C, Hgrid, Wgrid) that contains |
| 74 | features for points in `point_coords`. The features are obtained via bilinear |
| 75 | interplation from `input` the same way as :function:`torch.nn.functional.grid_sample`. |
| 76 | """ |
| 77 | add_dim = False |
| 78 | if point_coords.dim() == 3: |
| 79 | add_dim = True |
| 80 | point_coords = point_coords.unsqueeze(2) |
| 81 | output = F.grid_sample(input, 2.0 * point_coords - 1.0, **kwargs) |
| 82 | if add_dim: |
| 83 | output = output.squeeze(3) |
| 84 | return output |
| 85 | |
| 86 | def color_map(n: int = 256, normalized: bool = False): |
| 87 | def bitget(byteval, idx): |
no outgoing calls
no test coverage detected