MCPcopy Create free account
hub / github.com/00why00/JoDiffusion / point_sample

Function point_sample

utils/utils.py:61–84  ·  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

59 return point_coords
60
61def 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
86def color_map(n: int = 256, normalized: bool = False):
87 def bitget(byteval, idx):

Callers 4

matcherMethod · 0.90
loss_masksMethod · 0.90
loss_ceMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected