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
ca783a0f
Unverified
Commit
ca783a0f
authored
Apr 17, 2023
by
Patrick von Platen
Committed by
GitHub
Apr 17, 2023
Browse files
[Bug fix] Make sure correct timesteps are chosen for img2img (#3128)
Make sure correct timesteps are chosen for img2img
parent
beb848e2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
5 deletions
+33
-5
src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py
...pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py
+1
-1
src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py
...rs/pipelines/stable_diffusion/pipeline_cycle_diffusion.py
+1
-1
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py
...s/stable_diffusion/pipeline_stable_diffusion_depth2img.py
+1
-1
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py
...nes/stable_diffusion/pipeline_stable_diffusion_img2img.py
+1
-1
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py
...ble_diffusion/pipeline_stable_diffusion_inpaint_legacy.py
+1
-1
tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py
...pelines/stable_diffusion/test_stable_diffusion_img2img.py
+28
-0
No files found.
src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py
View file @
ca783a0f
...
...
@@ -503,7 +503,7 @@ class AltDiffusionImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMixin
init_timestep
=
min
(
int
(
num_inference_steps
*
strength
),
num_inference_steps
)
t_start
=
max
(
num_inference_steps
-
init_timestep
,
0
)
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
:]
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
*
self
.
scheduler
.
order
:]
return
timesteps
,
num_inference_steps
-
t_start
...
...
src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py
View file @
ca783a0f
...
...
@@ -528,7 +528,7 @@ class CycleDiffusionPipeline(DiffusionPipeline, TextualInversionLoaderMixin):
init_timestep
=
min
(
int
(
num_inference_steps
*
strength
),
num_inference_steps
)
t_start
=
max
(
num_inference_steps
-
init_timestep
,
0
)
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
:]
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
*
self
.
scheduler
.
order
:]
return
timesteps
,
num_inference_steps
-
t_start
...
...
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py
View file @
ca783a0f
...
...
@@ -390,7 +390,7 @@ class StableDiffusionDepth2ImgPipeline(DiffusionPipeline, TextualInversionLoader
init_timestep
=
min
(
int
(
num_inference_steps
*
strength
),
num_inference_steps
)
t_start
=
max
(
num_inference_steps
-
init_timestep
,
0
)
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
:]
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
*
self
.
scheduler
.
order
:]
return
timesteps
,
num_inference_steps
-
t_start
...
...
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py
View file @
ca783a0f
...
...
@@ -511,7 +511,7 @@ class StableDiffusionImg2ImgPipeline(DiffusionPipeline, TextualInversionLoaderMi
init_timestep
=
min
(
int
(
num_inference_steps
*
strength
),
num_inference_steps
)
t_start
=
max
(
num_inference_steps
-
init_timestep
,
0
)
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
:]
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
*
self
.
scheduler
.
order
:]
return
timesteps
,
num_inference_steps
-
t_start
...
...
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py
View file @
ca783a0f
...
...
@@ -507,7 +507,7 @@ class StableDiffusionInpaintPipelineLegacy(DiffusionPipeline, TextualInversionLo
init_timestep
=
min
(
int
(
num_inference_steps
*
strength
),
num_inference_steps
)
t_start
=
max
(
num_inference_steps
-
init_timestep
,
0
)
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
:]
timesteps
=
self
.
scheduler
.
timesteps
[
t_start
*
self
.
scheduler
.
order
:]
return
timesteps
,
num_inference_steps
-
t_start
...
...
tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py
View file @
ca783a0f
...
...
@@ -25,6 +25,7 @@ from diffusers import (
AutoencoderKL
,
DDIMScheduler
,
DPMSolverMultistepScheduler
,
HeunDiscreteScheduler
,
LMSDiscreteScheduler
,
PNDMScheduler
,
StableDiffusionImg2ImgPipeline
,
...
...
@@ -416,6 +417,33 @@ class StableDiffusionImg2ImgPipelineSlowTests(unittest.TestCase):
for
module
in
pipe
.
text_encoder
,
pipe
.
unet
,
pipe
.
vae
:
assert
module
.
device
==
torch
.
device
(
"cpu"
)
def
test_img2img_2nd_order
(
self
):
sd_pipe
=
StableDiffusionImg2ImgPipeline
.
from_pretrained
(
"runwayml/stable-diffusion-v1-5"
)
sd_pipe
.
scheduler
=
HeunDiscreteScheduler
.
from_config
(
sd_pipe
.
scheduler
.
config
)
sd_pipe
.
to
(
torch_device
)
sd_pipe
.
set_progress_bar_config
(
disable
=
None
)
inputs
=
self
.
get_inputs
(
torch_device
)
inputs
[
"num_inference_steps"
]
=
10
inputs
[
"strength"
]
=
0.75
image
=
sd_pipe
(
**
inputs
).
images
[
0
]
expected_image
=
load_numpy
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/img2img/img2img_heun.npy"
)
max_diff
=
np
.
abs
(
expected_image
-
image
).
max
()
assert
max_diff
<
5e-2
inputs
=
self
.
get_inputs
(
torch_device
)
inputs
[
"num_inference_steps"
]
=
11
inputs
[
"strength"
]
=
0.75
image_other
=
sd_pipe
(
**
inputs
).
images
[
0
]
mean_diff
=
np
.
abs
(
image
-
image_other
).
mean
()
# images should be very similar
assert
mean_diff
<
5e-2
def
test_stable_diffusion_img2img_pipeline_multiple_of_8
(
self
):
init_image
=
load_image
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
...
...
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