Skip to content

Commit 165af7e

Browse files
authored
Inline InputPadder (#6582)
inline InputPadder
1 parent 6c5f0de commit 165af7e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

examples/community/rerender_a_video.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from diffusers.schedulers import KarrasDiffusionSchedulers
3333
from diffusers.utils import BaseOutput, deprecate, logging
3434
from diffusers.utils.torch_utils import is_compiled_module, randn_tensor
35-
from utils.utils import InputPadder # noqa: E402
3635

3736

3837
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -1172,3 +1171,24 @@ def denoising_loop(latents, mask=None, xtrg=None, noise_rescale=None):
11721171
return output_frames
11731172

11741173
return TextToVideoSDPipelineOutput(frames=output_frames)
1174+
1175+
1176+
class InputPadder:
1177+
"""Pads images such that dimensions are divisible by 8"""
1178+
1179+
def __init__(self, dims, mode="sintel", padding_factor=8):
1180+
self.ht, self.wd = dims[-2:]
1181+
pad_ht = (((self.ht // padding_factor) + 1) * padding_factor - self.ht) % padding_factor
1182+
pad_wd = (((self.wd // padding_factor) + 1) * padding_factor - self.wd) % padding_factor
1183+
if mode == "sintel":
1184+
self._pad = [pad_wd // 2, pad_wd - pad_wd // 2, pad_ht // 2, pad_ht - pad_ht // 2]
1185+
else:
1186+
self._pad = [pad_wd // 2, pad_wd - pad_wd // 2, 0, pad_ht]
1187+
1188+
def pad(self, *inputs):
1189+
return [F.pad(x, self._pad, mode="replicate") for x in inputs]
1190+
1191+
def unpad(self, x):
1192+
ht, wd = x.shape[-2:]
1193+
c = [self._pad[2], ht - self._pad[3], self._pad[0], wd - self._pad[1]]
1194+
return x[..., c[0] : c[1], c[2] : c[3]]

0 commit comments

Comments
 (0)