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

Function bilinear_sampler

core/utils/utils.py:58–72  ·  view source on GitHub ↗

Wrapper for grid_sample, uses pixel coordinates

(img, coords, mode='bilinear', mask=False)

Source from the content-addressed store, hash-verified

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 """
60 H, W = img.shape[-2:]
61 xgrid, ygrid = coords.split([1,1], dim=-1)
62 xgrid = 2*xgrid/(W-1) - 1
63 ygrid = 2*ygrid/(H-1) - 1
64
65 grid = torch.cat([xgrid, ygrid], dim=-1)
66 img = F.grid_sample(img, grid, align_corners=True)
67
68 if mask:
69 mask = (xgrid > -1) & (ygrid > -1) & (xgrid < 1) & (ygrid < 1)
70 return img, mask.float()
71
72 return img
73
74def indexing(img, coords, mask=False):
75 """ Wrapper for grid_sample, uses pixel coordinates """

Callers 12

__call__Method · 0.90
sampler_gaussianFunction · 0.90
sampler_gaussian_zyFunction · 0.90
sampler_gaussian_fixFunction · 0.90
sampler_gaussian_pyramidFunction · 0.90
sampler_gaussian_fix_MHFunction · 0.90
samplerFunction · 0.90
retrieve_tokensFunction · 0.90
forwardMethod · 0.90
encode_flow_tokenMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected