MCPcopy
hub / github.com/KlingAIResearch/LivePortrait / make_coordinate_grid

Function make_coordinate_grid

src/modules/util.py:41–58  ·  view source on GitHub ↗
(spatial_size, ref, **kwargs)

Source from the content-addressed store, hash-verified

39
40
41def make_coordinate_grid(spatial_size, ref, **kwargs):
42 d, h, w = spatial_size
43 x = torch.arange(w).type(ref.dtype).to(ref.device)
44 y = torch.arange(h).type(ref.dtype).to(ref.device)
45 z = torch.arange(d).type(ref.dtype).to(ref.device)
46
47 # NOTE: must be right-down-in
48 x = (2 * (x / (w - 1)) - 1) # the x axis faces to the right
49 y = (2 * (y / (h - 1)) - 1) # the y axis faces to the bottom
50 z = (2 * (z / (d - 1)) - 1) # the z axis faces to the inner
51
52 yy = y.view(1, -1, 1).repeat(d, 1, w)
53 xx = x.view(1, 1, -1).repeat(d, h, 1)
54 zz = z.view(-1, 1, 1).repeat(1, h, w)
55
56 meshed = torch.cat([xx.unsqueeze_(3), yy.unsqueeze_(3), zz.unsqueeze_(3)], 3)
57
58 return meshed
59
60
61class ConvT2d(nn.Module):

Callers 2

kp2gaussianFunction · 0.85
create_sparse_motionsMethod · 0.85

Calls 1

toMethod · 0.80

Tested by

no test coverage detected