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
05a36d5c
Unverified
Commit
05a36d5c
authored
Nov 24, 2022
by
Patrick von Platen
Committed by
GitHub
Nov 24, 2022
Browse files
Upscaling fixed (#1402)
* Upscaling fixed * up * more fixes * fix * more fixes * finish again * up
parent
cbfed0c2
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
34 deletions
+102
-34
tests/pipelines/stable_diffusion/test_stable_diffusion.py
tests/pipelines/stable_diffusion/test_stable_diffusion.py
+86
-18
tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py
...stable_diffusion/test_stable_diffusion_image_variation.py
+2
-3
tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py
...pelines/stable_diffusion/test_stable_diffusion_inpaint.py
+8
-7
tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py
.../stable_diffusion/test_stable_diffusion_inpaint_legacy.py
+3
-3
tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py
tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py
+2
-2
tests/test_pipelines.py
tests/test_pipelines.py
+1
-1
No files found.
tests/pipelines/stable_diffusion/test_stable_diffusion.py
View file @
05a36d5c
...
@@ -207,11 +207,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -207,11 +207,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
)[
0
]
)[
0
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
print
(
", "
.
join
(
image_slice
.
flatten
().
tolist
()))
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.5112
,
0.4692
,
0.4715
,
0.5206
,
0.4894
,
0.5114
,
0.5096
,
0.4932
,
0.4755
])
expected_slice
=
np
.
array
(
[
0.5643956661224365
,
0.6017904281616211
,
0.4799129366874695
,
0.5267305374145508
,
0.5584856271743774
,
0.46413588523864746
,
0.5159522294998169
,
0.4963662028312683
,
0.47919973731040955
,
]
)
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
...
@@ -256,12 +267,13 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -256,12 +267,13 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
num_inference_steps
=
2
,
num_inference_steps
=
2
,
output_type
=
"np"
,
output_type
=
"np"
,
)
)
sd_pipe
.
enable_attention_slicing
()
image
=
output
.
images
image
=
output
.
images
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
134
,
134
,
3
)
assert
image
.
shape
==
(
1
,
536
,
536
,
3
)
expected_slice
=
np
.
array
([
0.
7834
,
0.
548
8
,
0.
5781
,
0.4
6
,
0.
360
9
,
0.5
369
,
0.
542
,
0.4
855
,
0.
5557
])
expected_slice
=
np
.
array
([
0.
5445
,
0.
810
8
,
0.
6242
,
0.4
863
,
0.
577
9
,
0.5
423
,
0.
4749
,
0.4
589
,
0.
4616
])
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
...
@@ -303,11 +315,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -303,11 +315,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
)[
0
]
)[
0
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
print
(
", "
.
join
(
image_slice
.
flatten
().
tolist
()))
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.4937
,
0.4649
,
0.4716
,
0.5145
,
0.4889
,
0.513
,
0.513
,
0.4905
,
0.4738
])
expected_slice
=
np
.
array
(
[
0.5094760060310364
,
0.5674174427986145
,
0.46675148606300354
,
0.5125715136528015
,
0.5696930289268494
,
0.4674668312072754
,
0.5277683734893799
,
0.4964486062526703
,
0.494540274143219
,
]
)
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
...
@@ -370,11 +393,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -370,11 +393,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
)[
0
]
)[
0
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
print
(
", "
.
join
(
image_slice
.
flatten
().
tolist
()))
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.5067
,
0.4689
,
0.4614
,
0.5233
,
0.4903
,
0.5112
,
0.524
,
0.5069
,
0.4785
])
expected_slice
=
np
.
array
(
[
0.47082293033599854
,
0.5371589064598083
,
0.4562119245529175
,
0.5220914483070374
,
0.5733777284622192
,
0.4795039892196655
,
0.5465868711471558
,
0.5074326395988464
,
0.5042197108268738
,
]
)
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
...
@@ -416,11 +450,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -416,11 +450,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
)[
0
]
)[
0
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
print
(
", "
.
join
(
image_slice
.
flatten
().
tolist
()))
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.5067
,
0.4689
,
0.4614
,
0.5233
,
0.4903
,
0.5112
,
0.524
,
0.5069
,
0.4785
])
expected_slice
=
np
.
array
(
[
0.4707113206386566
,
0.5372191071510315
,
0.4563021957874298
,
0.5220003724098206
,
0.5734264850616455
,
0.4794946610927582
,
0.5463782548904419
,
0.5074145197868347
,
0.504422664642334
,
]
)
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
...
@@ -462,11 +507,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -462,11 +507,22 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
)[
0
]
)[
0
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
print
(
", "
.
join
(
image_slice
.
flatten
().
tolist
()))
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.5067
,
0.4689
,
0.4614
,
0.5233
,
0.4903
,
0.5112
,
0.524
,
0.5069
,
0.4785
])
expected_slice
=
np
.
array
(
[
0.47082313895225525
,
0.5371587872505188
,
0.4562119245529175
,
0.5220913887023926
,
0.5733776688575745
,
0.47950395941734314
,
0.546586811542511
,
0.5074326992034912
,
0.5042197108268738
,
]
)
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
...
@@ -539,7 +595,19 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -539,7 +595,19 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.4851
,
0.4617
,
0.4765
,
0.5127
,
0.4845
,
0.5153
,
0.5141
,
0.4886
,
0.4719
])
expected_slice
=
np
.
array
(
[
0.5108221173286438
,
0.5688379406929016
,
0.4685141146183014
,
0.5098261833190918
,
0.5657756328582764
,
0.4631010890007019
,
0.5226285457611084
,
0.49129390716552734
,
0.4899061322212219
,
]
)
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
def
test_stable_diffusion_num_images_per_prompt
(
self
):
def
test_stable_diffusion_num_images_per_prompt
(
self
):
...
@@ -700,18 +768,18 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -700,18 +768,18 @@ class StableDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
output
=
sd_pipe
(
prompt
,
number_of_steps
=
2
,
output_type
=
"np"
)
output
=
sd_pipe
(
prompt
,
number_of_steps
=
2
,
output_type
=
"np"
)
image_shape
=
output
.
images
[
0
].
shape
[:
2
]
image_shape
=
output
.
images
[
0
].
shape
[:
2
]
assert
image_shape
==
[
32
,
32
]
assert
image_shape
==
(
64
,
64
)
output
=
sd_pipe
(
prompt
,
number_of_steps
=
2
,
height
=
6
4
,
width
=
6
4
,
output_type
=
"np"
)
output
=
sd_pipe
(
prompt
,
number_of_steps
=
2
,
height
=
9
6
,
width
=
9
6
,
output_type
=
"np"
)
image_shape
=
output
.
images
[
0
].
shape
[:
2
]
image_shape
=
output
.
images
[
0
].
shape
[:
2
]
assert
image_shape
==
[
64
,
64
]
assert
image_shape
==
(
96
,
96
)
config
=
dict
(
sd_pipe
.
unet
.
config
)
config
=
dict
(
sd_pipe
.
unet
.
config
)
config
[
"sample_size"
]
=
96
config
[
"sample_size"
]
=
96
sd_pipe
.
unet
=
UNet2DConditionModel
.
from_config
(
config
)
sd_pipe
.
unet
=
UNet2DConditionModel
.
from_config
(
config
)
.
to
(
torch_device
)
output
=
sd_pipe
(
prompt
,
number_of_steps
=
2
,
output_type
=
"np"
)
output
=
sd_pipe
(
prompt
,
number_of_steps
=
2
,
output_type
=
"np"
)
image_shape
=
output
.
images
[
0
].
shape
[:
2
]
image_shape
=
output
.
images
[
0
].
shape
[:
2
]
assert
image_shape
==
[
96
,
96
]
assert
image_shape
==
(
192
,
192
)
@
slow
@
slow
...
...
tests/pipelines/stable_diffusion/test_stable_diffusion_image_variation.py
View file @
05a36d5c
...
@@ -154,11 +154,10 @@ class StableDiffusionImageVariationPipelineFastTests(PipelineTesterMixin, unitte
...
@@ -154,11 +154,10 @@ class StableDiffusionImageVariationPipelineFastTests(PipelineTesterMixin, unitte
)[
0
]
)[
0
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
print
(
image_slice
.
flatten
())
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.
4
93
5
,
0.
4784
,
0.480
2
,
0.
5027
,
0.4805
,
0.5149
,
0.51
43
,
0.48
7
9
,
0.4
731
])
expected_slice
=
np
.
array
([
0.
50
93
,
0.
5717
,
0.480
6
,
0.
4891
,
0.5552
,
0.4594
,
0.51
77
,
0.489
4
,
0.4
904
])
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-3
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-3
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-3
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-3
...
@@ -197,7 +196,7 @@ class StableDiffusionImageVariationPipelineFastTests(PipelineTesterMixin, unitte
...
@@ -197,7 +196,7 @@ class StableDiffusionImageVariationPipelineFastTests(PipelineTesterMixin, unitte
image_slice
=
image
[
-
1
,
-
3
:,
-
3
:,
-
1
]
image_slice
=
image
[
-
1
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
2
,
64
,
64
,
3
)
assert
image
.
shape
==
(
2
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.
4939
,
0.4627
,
0.4831
,
0.5
710
,
0.5
387
,
0.
4428
,
0.5
230
,
0.554
5
,
0.
4586
])
expected_slice
=
np
.
array
([
0.
6427
,
0.5452
,
0.5602
,
0.5
478
,
0.5
968
,
0.
6211
,
0.5
538
,
0.55
1
4
,
0.
5281
])
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-3
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-3
def
test_stable_diffusion_img_variation_num_images_per_prompt
(
self
):
def
test_stable_diffusion_img_variation_num_images_per_prompt
(
self
):
...
...
tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py
View file @
05a36d5c
...
@@ -167,8 +167,8 @@ class StableDiffusionInpaintPipelineFastTests(PipelineTesterMixin, unittest.Test
...
@@ -167,8 +167,8 @@ class StableDiffusionInpaintPipelineFastTests(PipelineTesterMixin, unittest.Test
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
"hf-internal-testing/tiny-random-clip"
)
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
"hf-internal-testing/tiny-random-clip"
)
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
).
resize
((
64
,
64
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
64
,
64
))
# make sure here that pndm scheduler skips prk
# make sure here that pndm scheduler skips prk
sd_pipe
=
StableDiffusionInpaintPipeline
(
sd_pipe
=
StableDiffusionInpaintPipeline
(
...
@@ -213,7 +213,8 @@ class StableDiffusionInpaintPipelineFastTests(PipelineTesterMixin, unittest.Test
...
@@ -213,7 +213,8 @@ class StableDiffusionInpaintPipelineFastTests(PipelineTesterMixin, unittest.Test
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.5075
,
0.4485
,
0.4558
,
0.5369
,
0.5369
,
0.5236
,
0.5127
,
0.4983
,
0.4776
])
expected_slice
=
np
.
array
([
0.4723
,
0.5731
,
0.3939
,
0.5441
,
0.5922
,
0.4392
,
0.5059
,
0.4651
,
0.4474
])
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
...
@@ -226,8 +227,8 @@ class StableDiffusionInpaintPipelineFastTests(PipelineTesterMixin, unittest.Test
...
@@ -226,8 +227,8 @@ class StableDiffusionInpaintPipelineFastTests(PipelineTesterMixin, unittest.Test
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
"hf-internal-testing/tiny-random-clip"
)
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
"hf-internal-testing/tiny-random-clip"
)
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
).
resize
((
64
,
64
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
64
,
64
))
# make sure here that pndm scheduler skips prk
# make sure here that pndm scheduler skips prk
sd_pipe
=
StableDiffusionInpaintPipeline
(
sd_pipe
=
StableDiffusionInpaintPipeline
(
...
@@ -268,8 +269,8 @@ class StableDiffusionInpaintPipelineFastTests(PipelineTesterMixin, unittest.Test
...
@@ -268,8 +269,8 @@ class StableDiffusionInpaintPipelineFastTests(PipelineTesterMixin, unittest.Test
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
"hf-internal-testing/tiny-random-clip"
)
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
"hf-internal-testing/tiny-random-clip"
)
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
).
resize
((
64
,
64
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
64
,
64
))
# put models in fp16
# put models in fp16
unet
=
unet
.
half
()
unet
=
unet
.
half
()
...
...
tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py
View file @
05a36d5c
...
@@ -168,7 +168,7 @@ class StableDiffusionInpaintLegacyPipelineFastTests(PipelineTesterMixin, unittes
...
@@ -168,7 +168,7 @@ class StableDiffusionInpaintLegacyPipelineFastTests(PipelineTesterMixin, unittes
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
)
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
)
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
32
,
32
))
# make sure here that pndm scheduler skips prk
# make sure here that pndm scheduler skips prk
sd_pipe
=
StableDiffusionInpaintPipelineLegacy
(
sd_pipe
=
StableDiffusionInpaintPipelineLegacy
(
...
@@ -227,7 +227,7 @@ class StableDiffusionInpaintLegacyPipelineFastTests(PipelineTesterMixin, unittes
...
@@ -227,7 +227,7 @@ class StableDiffusionInpaintLegacyPipelineFastTests(PipelineTesterMixin, unittes
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
)
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
)
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
32
,
32
))
# make sure here that pndm scheduler skips prk
# make sure here that pndm scheduler skips prk
sd_pipe
=
StableDiffusionInpaintPipelineLegacy
(
sd_pipe
=
StableDiffusionInpaintPipelineLegacy
(
...
@@ -273,7 +273,7 @@ class StableDiffusionInpaintLegacyPipelineFastTests(PipelineTesterMixin, unittes
...
@@ -273,7 +273,7 @@ class StableDiffusionInpaintLegacyPipelineFastTests(PipelineTesterMixin, unittes
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
image
=
self
.
dummy_image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
)
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
)
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
32
,
32
))
# make sure here that pndm scheduler skips prk
# make sure here that pndm scheduler skips prk
sd_pipe
=
StableDiffusionInpaintPipelineLegacy
(
sd_pipe
=
StableDiffusionInpaintPipelineLegacy
(
...
...
tests/pipelines/stable_diffusion_safe/test_safe_diffusion.py
View file @
05a36d5c
...
@@ -156,7 +156,7 @@ class SafeDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -156,7 +156,7 @@ class SafeDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.5
112
,
0.
4692
,
0.47
15
,
0.52
0
6
,
0.
4894
,
0.5114
,
0.5
09
6
,
0.49
32
,
0.47
55
])
expected_slice
=
np
.
array
([
0.5
644
,
0.
6018
,
0.47
99
,
0.526
7
,
0.
5585
,
0.4641
,
0.5
1
6
,
0.49
64
,
0.47
92
])
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
...
@@ -202,7 +202,7 @@ class SafeDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
...
@@ -202,7 +202,7 @@ class SafeDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
assert
image
.
shape
==
(
1
,
64
,
64
,
3
)
expected_slice
=
np
.
array
([
0.
4937
,
0.4649
,
0.4
716
,
0.51
45
,
0.
4889
,
0.513
,
0.5
13
,
0.49
05
,
0.4
738
])
expected_slice
=
np
.
array
([
0.
5095
,
0.5674
,
0.4
668
,
0.51
26
,
0.
5697
,
0.4675
,
0.5
278
,
0.49
64
,
0.4
945
])
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
...
...
tests/test_pipelines.py
View file @
05a36d5c
...
@@ -367,7 +367,7 @@ class PipelineFastTests(unittest.TestCase):
...
@@ -367,7 +367,7 @@ class PipelineFastTests(unittest.TestCase):
image
=
self
.
dummy_image
().
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
image
=
self
.
dummy_image
().
cpu
().
permute
(
0
,
2
,
3
,
1
)[
0
]
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
)
init_image
=
Image
.
fromarray
(
np
.
uint8
(
image
)).
convert
(
"RGB"
)
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
128
,
128
))
mask_image
=
Image
.
fromarray
(
np
.
uint8
(
image
+
4
)).
convert
(
"RGB"
).
resize
((
32
,
32
))
# make sure here that pndm scheduler skips prk
# make sure here that pndm scheduler skips prk
inpaint
=
StableDiffusionInpaintPipelineLegacy
(
inpaint
=
StableDiffusionInpaintPipelineLegacy
(
...
...
Prev
1
2
Next
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