MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / warp

Function warp

diffsynth/extensions/RIFE/__init__.py:8–23  ·  view source on GitHub ↗
(tenInput, tenFlow, device)

Source from the content-addressed store, hash-verified

6
7
8def warp(tenInput, tenFlow, device):
9 backwarp_tenGrid = {}
10 k = (str(tenFlow.device), str(tenFlow.size()))
11 if k not in backwarp_tenGrid:
12 tenHorizontal = torch.linspace(-1.0, 1.0, tenFlow.shape[3], device=device).view(
13 1, 1, 1, tenFlow.shape[3]).expand(tenFlow.shape[0], -1, tenFlow.shape[2], -1)
14 tenVertical = torch.linspace(-1.0, 1.0, tenFlow.shape[2], device=device).view(
15 1, 1, tenFlow.shape[2], 1).expand(tenFlow.shape[0], -1, -1, tenFlow.shape[3])
16 backwarp_tenGrid[k] = torch.cat(
17 [tenHorizontal, tenVertical], 1).to(device)
18
19 tenFlow = torch.cat([tenFlow[:, 0:1, :, :] / ((tenInput.shape[3] - 1.0) / 2.0),
20 tenFlow[:, 1:2, :, :] / ((tenInput.shape[2] - 1.0) / 2.0)], 1)
21
22 g = (backwarp_tenGrid[k] + tenFlow).permute(0, 2, 3, 1)
23 return torch.nn.functional.grid_sample(input=tenInput, grid=g, mode='bilinear', padding_mode='border', align_corners=True)
24
25
26def conv(in_planes, out_planes, kernel_size=3, stride=1, padding=1, dilation=1):

Callers 1

forwardMethod · 0.85

Calls 1

toMethod · 0.45

Tested by

no test coverage detected