MCPcopy Create free account
hub / github.com/deepbrainai-research/float / upfirdn2d_native

Function upfirdn2d_native

models/float/styledecoder.py:12–29  ·  view source on GitHub ↗
(input, kernel, up_x, up_y, down_x, down_y, pad_x0, pad_x1, pad_y0, pad_y1)

Source from the content-addressed store, hash-verified

10
11
12def upfirdn2d_native(input, kernel, up_x, up_y, down_x, down_y, pad_x0, pad_x1, pad_y0, pad_y1):
13 _, minor, in_h, in_w = input.shape
14 kernel_h, kernel_w = kernel.shape
15
16 out = input.view(-1, minor, in_h, 1, in_w, 1)
17 out = F.pad(out, [0, up_x - 1, 0, 0, 0, up_y - 1, 0, 0])
18 out = out.view(-1, minor, in_h * up_y, in_w * up_x)
19
20 out = F.pad(out, [max(pad_x0, 0), max(pad_x1, 0), max(pad_y0, 0), max(pad_y1, 0)])
21 out = out[:, :, max(-pad_y0, 0): out.shape[2] - max(-pad_y1, 0),
22 max(-pad_x0, 0): out.shape[3] - max(-pad_x1, 0), ]
23
24 out = out.reshape([-1, 1, in_h * up_y + pad_y0 + pad_y1, in_w * up_x + pad_x0 + pad_x1])
25 w = torch.flip(kernel, [0, 1]).view(1, 1, kernel_h, kernel_w)
26 out = F.conv2d(out, w)
27 out = out.reshape(-1, minor, in_h * up_y + pad_y0 + pad_y1 - kernel_h + 1,
28 in_w * up_x + pad_x0 + pad_x1 - kernel_w + 1, )
29 return out[:, :, ::down_y, ::down_x]
30
31
32def upfirdn2d(input, kernel, up=1, down=1, pad=(0, 0)):

Callers 1

upfirdn2dFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected