-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Multi-image masking for single IP Adapter #7499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1141aaf
Support multiimage masking
fabiorigano 854b843
Restore ipadaptermaskprocessor
fabiorigano d42d358
Update conditions
fabiorigano c63e6af
Add test
fabiorigano a7b4c44
Merge branch 'main' into multiimageipmask
sayakpaul b6fdc96
Update src/diffusers/models/attention_processor.py
fabiorigano df31fe6
Apply suggestions from code review
fabiorigano d0d9308
Fix conditions
fabiorigano 7d3a794
Add fast test
fabiorigano 654c15e
Fix style
fabiorigano cf1ddce
Fix tests
fabiorigano ac377a8
Merge branch 'main' into multiimageipmask
yiyixuxu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -544,3 +544,33 @@ def test_ip_adapter_multiple_masks(self): | |||
|
|
||||
| max_diff = numpy_cosine_similarity_distance(image_slice, expected_slice) | ||||
| assert max_diff < 5e-4 | ||||
|
|
||||
| def test_ip_adapter_multiple_masks_one_adapter(self): | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is slow test. I was wondering if it's possible to add a fast test like
?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, I missed that I'll add it now |
||||
| image_encoder = self.get_image_encoder(repo_id="h94/IP-Adapter", subfolder="models/image_encoder") | ||||
| pipeline = StableDiffusionXLPipeline.from_pretrained( | ||||
| "stabilityai/stable-diffusion-xl-base-1.0", | ||||
| image_encoder=image_encoder, | ||||
| torch_dtype=self.dtype, | ||||
| ) | ||||
| pipeline.enable_model_cpu_offload() | ||||
| pipeline.load_ip_adapter( | ||||
| "h94/IP-Adapter", subfolder="sdxl_models", weight_name=["ip-adapter-plus-face_sdxl_vit-h.safetensors"] | ||||
| ) | ||||
| pipeline.set_ip_adapter_scale([[0.7, 0.7]]) | ||||
|
|
||||
| inputs = self.get_dummy_inputs(for_masks=True) | ||||
| masks = inputs["cross_attention_kwargs"]["ip_adapter_masks"] | ||||
| processor = IPAdapterMaskProcessor() | ||||
| masks = processor.preprocess(masks) | ||||
| masks = masks.reshape(1, masks.shape[0], masks.shape[2], masks.shape[3]) | ||||
| inputs["cross_attention_kwargs"]["ip_adapter_masks"] = [masks] | ||||
| ip_images = inputs["ip_adapter_image"] | ||||
| inputs["ip_adapter_image"] = [[image[0] for image in ip_images]] | ||||
| images = pipeline(**inputs).images | ||||
| image_slice = images[0, :3, :3, -1].flatten() | ||||
| expected_slice = np.array( | ||||
| [0.79474676, 0.7977683, 0.8013954, 0.7988008, 0.7970615, 0.8029355, 0.80614823, 0.8050743, 0.80627424] | ||||
| ) | ||||
|
|
||||
| max_diff = numpy_cosine_similarity_distance(image_slice, expected_slice) | ||||
| assert max_diff < 5e-4 | ||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.