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
OpenDAS
diffusers
Commits
bb99623d
Unverified
Commit
bb99623d
authored
Feb 05, 2024
by
Dhruv Nair
Committed by
GitHub
Feb 05, 2024
Browse files
Update IP Adapter tests to use cosine similarity distance (#6806)
* update * update
parent
fdf55b1f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
19 deletions
+27
-19
tests/pipelines/ip_adapters/test_ip_adapter_stable_diffusion.py
...pipelines/ip_adapters/test_ip_adapter_stable_diffusion.py
+27
-19
No files found.
tests/pipelines/ip_adapters/test_ip_adapter_stable_diffusion.py
View file @
bb99623d
...
...
@@ -35,6 +35,7 @@ from diffusers.models.attention_processor import AttnProcessor, AttnProcessor2_0
from
diffusers.utils
import
load_image
from
diffusers.utils.testing_utils
import
(
enable_full_determinism
,
numpy_cosine_similarity_distance
,
require_torch_gpu
,
slow
,
torch_device
,
...
...
@@ -119,7 +120,8 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin):
expected_slice
=
np
.
array
([
0.80810547
,
0.88183594
,
0.9296875
,
0.9189453
,
0.9848633
,
1.0
,
0.97021484
,
1.0
,
1.0
])
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
pipeline
.
load_ip_adapter
(
"h94/IP-Adapter"
,
subfolder
=
"models"
,
weight_name
=
"ip-adapter-plus_sd15.bin"
)
...
...
@@ -131,7 +133,8 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin):
[
0.30444336
,
0.26513672
,
0.22436523
,
0.2758789
,
0.25585938
,
0.20751953
,
0.25390625
,
0.24633789
,
0.21923828
]
)
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
def
test_image_to_image
(
self
):
image_encoder
=
self
.
get_image_encoder
(
repo_id
=
"h94/IP-Adapter"
,
subfolder
=
"models/image_encoder"
)
...
...
@@ -149,7 +152,8 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin):
[
0.22167969
,
0.21875
,
0.21728516
,
0.22607422
,
0.21948242
,
0.23925781
,
0.22387695
,
0.25268555
,
0.2722168
]
)
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
pipeline
.
load_ip_adapter
(
"h94/IP-Adapter"
,
subfolder
=
"models"
,
weight_name
=
"ip-adapter-plus_sd15.bin"
)
...
...
@@ -161,7 +165,8 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin):
[
0.35913086
,
0.265625
,
0.26367188
,
0.24658203
,
0.19750977
,
0.39990234
,
0.15258789
,
0.20336914
,
0.5517578
]
)
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
def
test_inpainting
(
self
):
image_encoder
=
self
.
get_image_encoder
(
repo_id
=
"h94/IP-Adapter"
,
subfolder
=
"models/image_encoder"
)
...
...
@@ -179,7 +184,8 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin):
[
0.27148438
,
0.24047852
,
0.22167969
,
0.23217773
,
0.21118164
,
0.21142578
,
0.21875
,
0.20751953
,
0.20019531
]
)
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
pipeline
.
load_ip_adapter
(
"h94/IP-Adapter"
,
subfolder
=
"models"
,
weight_name
=
"ip-adapter-plus_sd15.bin"
)
...
...
@@ -187,11 +193,8 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin):
images
=
pipeline
(
**
inputs
).
images
image_slice
=
images
[
0
,
:
3
,
:
3
,
-
1
].
flatten
()
expected_slice
=
np
.
array
(
[
0.27294922
,
0.24023438
,
0.21948242
,
0.23242188
,
0.20825195
,
0.2055664
,
0.21679688
,
0.20336914
,
0.19360352
]
)
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
def
test_text_to_image_model_cpu_offload
(
self
):
image_encoder
=
self
.
get_image_encoder
(
repo_id
=
"h94/IP-Adapter"
,
subfolder
=
"models/image_encoder"
)
...
...
@@ -233,11 +236,10 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin):
images
=
pipeline
(
**
inputs
).
images
image_slice
=
images
[
0
,
:
3
,
:
3
,
-
1
].
flatten
()
expected_slice
=
np
.
array
(
[
0.18115234
,
0.13500977
,
0.13427734
,
0.24194336
,
0.17138672
,
0.16625977
,
0.4260254
,
0.43359375
,
0.4416504
]
)
expected_slice
=
np
.
array
([
0.1958
,
0.1475
,
0.1396
,
0.2412
,
0.1658
,
0.1533
,
0.3997
,
0.4055
,
0.4128
])
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
def
test_unload
(
self
):
image_encoder
=
self
.
get_image_encoder
(
repo_id
=
"h94/IP-Adapter"
,
subfolder
=
"models/image_encoder"
)
...
...
@@ -277,7 +279,9 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin):
expected_slice
=
np
.
array
(
[
0.5234375
,
0.53515625
,
0.5629883
,
0.57128906
,
0.59521484
,
0.62109375
,
0.57910156
,
0.6201172
,
0.6508789
]
)
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
@
slow
...
...
@@ -314,7 +318,8 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin):
]
)
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
image_encoder
=
self
.
get_image_encoder
(
repo_id
=
"h94/IP-Adapter"
,
subfolder
=
"models/image_encoder"
)
...
...
@@ -339,7 +344,8 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin):
[
0.0576596
,
0.05600825
,
0.04479006
,
0.05288461
,
0.05461192
,
0.05137569
,
0.04867965
,
0.05301541
,
0.04939842
]
)
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
def
test_image_to_image_sdxl
(
self
):
image_encoder
=
self
.
get_image_encoder
(
repo_id
=
"h94/IP-Adapter"
,
subfolder
=
"sdxl_models/image_encoder"
)
...
...
@@ -432,7 +438,8 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin):
[
0.14181179
,
0.1493012
,
0.14283323
,
0.14602411
,
0.14915377
,
0.15015268
,
0.14725655
,
0.15009224
,
0.15164584
]
)
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-3
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
image_encoder
=
self
.
get_image_encoder
(
repo_id
=
"h94/IP-Adapter"
,
subfolder
=
"models/image_encoder"
)
feature_extractor
=
self
.
get_image_processor
(
"laion/CLIP-ViT-bigG-14-laion2B-39B-b160k"
)
...
...
@@ -457,4 +464,5 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin):
expected_slice
=
np
.
array
([
0.1398
,
0.1476
,
0.1407
,
0.1442
,
0.1470
,
0.1480
,
0.1449
,
0.1481
,
0.1494
])
assert
np
.
allclose
(
image_slice
,
expected_slice
,
atol
=
1e-4
,
rtol
=
1e-4
)
max_diff
=
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
assert
max_diff
<
5e-4
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