Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
renzhc
diffusers_dcu
Commits
165af7ed
Unverified
Commit
165af7ed
authored
Mar 09, 2024
by
pravdomil
Committed by
GitHub
Mar 09, 2024
Browse files
Inline InputPadder (#6582)
inline InputPadder
parent
6c5f0de7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
1 deletion
+21
-1
examples/community/rerender_a_video.py
examples/community/rerender_a_video.py
+21
-1
No files found.
examples/community/rerender_a_video.py
View file @
165af7ed
...
@@ -32,7 +32,6 @@ from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionS
...
@@ -32,7 +32,6 @@ from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionS
from
diffusers.schedulers
import
KarrasDiffusionSchedulers
from
diffusers.schedulers
import
KarrasDiffusionSchedulers
from
diffusers.utils
import
BaseOutput
,
deprecate
,
logging
from
diffusers.utils
import
BaseOutput
,
deprecate
,
logging
from
diffusers.utils.torch_utils
import
is_compiled_module
,
randn_tensor
from
diffusers.utils.torch_utils
import
is_compiled_module
,
randn_tensor
from
utils.utils
import
InputPadder
# noqa: E402
logger
=
logging
.
get_logger
(
__name__
)
# pylint: disable=invalid-name
logger
=
logging
.
get_logger
(
__name__
)
# pylint: disable=invalid-name
...
@@ -1172,3 +1171,24 @@ class RerenderAVideoPipeline(StableDiffusionControlNetImg2ImgPipeline):
...
@@ -1172,3 +1171,24 @@ class RerenderAVideoPipeline(StableDiffusionControlNetImg2ImgPipeline):
return
output_frames
return
output_frames
return
TextToVideoSDPipelineOutput
(
frames
=
output_frames
)
return
TextToVideoSDPipelineOutput
(
frames
=
output_frames
)
class
InputPadder
:
"""Pads images such that dimensions are divisible by 8"""
def
__init__
(
self
,
dims
,
mode
=
"sintel"
,
padding_factor
=
8
):
self
.
ht
,
self
.
wd
=
dims
[
-
2
:]
pad_ht
=
(((
self
.
ht
//
padding_factor
)
+
1
)
*
padding_factor
-
self
.
ht
)
%
padding_factor
pad_wd
=
(((
self
.
wd
//
padding_factor
)
+
1
)
*
padding_factor
-
self
.
wd
)
%
padding_factor
if
mode
==
"sintel"
:
self
.
_pad
=
[
pad_wd
//
2
,
pad_wd
-
pad_wd
//
2
,
pad_ht
//
2
,
pad_ht
-
pad_ht
//
2
]
else
:
self
.
_pad
=
[
pad_wd
//
2
,
pad_wd
-
pad_wd
//
2
,
0
,
pad_ht
]
def
pad
(
self
,
*
inputs
):
return
[
F
.
pad
(
x
,
self
.
_pad
,
mode
=
"replicate"
)
for
x
in
inputs
]
def
unpad
(
self
,
x
):
ht
,
wd
=
x
.
shape
[
-
2
:]
c
=
[
self
.
_pad
[
2
],
ht
-
self
.
_pad
[
3
],
self
.
_pad
[
0
],
wd
-
self
.
_pad
[
1
]]
return
x
[...,
c
[
0
]
:
c
[
1
],
c
[
2
]
:
c
[
3
]]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment