MCPcopy Create free account
hub / github.com/drinkingcoder/FlowFormer-Official / forward_interpolate

Function forward_interpolate

core/utils/utils.py:28–56  ·  view source on GitHub ↗
(flow)

Source from the content-addressed store, hash-verified

26 return x[..., c[0]:c[1], c[2]:c[3]]
27
28def forward_interpolate(flow):
29 flow = flow.detach().cpu().numpy()
30 dx, dy = flow[0], flow[1]
31
32 ht, wd = dx.shape
33 x0, y0 = np.meshgrid(np.arange(wd), np.arange(ht))
34
35 x1 = x0 + dx
36 y1 = y0 + dy
37
38 x1 = x1.reshape(-1)
39 y1 = y1.reshape(-1)
40 dx = dx.reshape(-1)
41 dy = dy.reshape(-1)
42
43 valid = (x1 > 0) & (x1 < wd) & (y1 > 0) & (y1 < ht)
44 x1 = x1[valid]
45 y1 = y1[valid]
46 dx = dx[valid]
47 dy = dy[valid]
48
49 flow_x = interpolate.griddata(
50 (x1, y1), dx, (x0, y0), method='nearest', fill_value=0)
51
52 flow_y = interpolate.griddata(
53 (x1, y1), dy, (x0, y0), method='nearest', fill_value=0)
54
55 flow = np.stack([flow_x, flow_y], axis=0)
56 return torch.from_numpy(flow).float()
57
58def bilinear_sampler(img, coords, mode='bilinear', mask=False):
59 """ Wrapper for grid_sample, uses pixel coordinates """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected