MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / coords_grid

Function coords_grid

diffusers/examples/community/rerender_a_video.py:40–56  ·  view source on GitHub ↗
(b, h, w, homogeneous=False, device=None)

Source from the content-addressed store, hash-verified

38
39
40def coords_grid(b, h, w, homogeneous=False, device=None):
41 y, x = torch.meshgrid(torch.arange(h), torch.arange(w)) # [H, W]
42
43 stacks = [x, y]
44
45 if homogeneous:
46 ones = torch.ones_like(x) # [H, W]
47 stacks.append(ones)
48
49 grid = torch.stack(stacks, dim=0).float() # [2, H, W] or [3, H, W]
50
51 grid = grid[None].repeat(b, 1, 1, 1) # [B, 2, H, W] or [B, 3, H, W]
52
53 if device is not None:
54 grid = grid.to(device)
55
56 return grid
57
58
59def bilinear_sample(img, sample_coords, mode="bilinear", padding_mode="zeros", return_mask=False):

Callers 1

flow_warpFunction · 0.70

Calls 1

toMethod · 0.45

Tested by

no test coverage detected