Skip to content

Commit 5d476f5

Browse files
noskillyiyixuxu
andauthored
adapt masked im2im pipeline for SDXL (#7790)
* adapt masked im2im pipeline for SDXL * usage for masked im2im stable diffusion XL pipeline * style * style * style --------- Co-authored-by: YiYi Xu <yixu310@gmail.com>
1 parent da18fbd commit 5d476f5

File tree

2 files changed

+723
-3
lines changed

2 files changed

+723
-3
lines changed

examples/community/README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Please also check out our [Community Scripts](https://github.com/huggingface/dif
5050
| Stable Diffusion XL Long Weighted Prompt Pipeline | A pipeline support unlimited length of prompt and negative prompt, use A1111 style of prompt weighting | [Stable Diffusion XL Long Weighted Prompt Pipeline](#stable-diffusion-xl-long-weighted-prompt-pipeline) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1LsqilswLR40XLLcp6XFOl5nKb_wOe26W?usp=sharing) | [Andrew Zhu](https://xhinker.medium.com/) |
5151
| FABRIC - Stable Diffusion with feedback Pipeline | pipeline supports feedback from liked and disliked images | [Stable Diffusion Fabric Pipeline](#stable-diffusion-fabric-pipeline) | - | [Shauray Singh](https://shauray8.github.io/about_shauray/) |
5252
| sketch inpaint - Inpainting with non-inpaint Stable Diffusion | sketch inpaint much like in automatic1111 | [Masked Im2Im Stable Diffusion Pipeline](#stable-diffusion-masked-im2im) | - | [Anatoly Belikov](https://github.com/noskill) |
53+
| sketch inpaint xl - Inpainting with non-inpaint Stable Diffusion | sketch inpaint much like in automatic1111 | [Masked Im2Im Stable Diffusion XL Pipeline](#stable-diffusion-xl-masked-im2im) | - | [Anatoly Belikov](https://github.com/noskill) |
5354
| prompt-to-prompt | change parts of a prompt and retain image structure (see [paper page](https://prompt-to-prompt.github.io/)) | [Prompt2Prompt Pipeline](#prompt2prompt-pipeline) | - | [Umer H. Adil](https://twitter.com/UmerHAdil) |
5455
| Latent Consistency Pipeline | Implementation of [Latent Consistency Models: Synthesizing High-Resolution Images with Few-Step Inference](https://arxiv.org/abs/2310.04378) | [Latent Consistency Pipeline](#latent-consistency-pipeline) | - | [Simian Luo](https://github.com/luosiallen) |
5556
| Latent Consistency Img2img Pipeline | Img2img pipeline for Latent Consistency Models | [Latent Consistency Img2Img Pipeline](#latent-consistency-img2img-pipeline) | - | [Logan Zoellner](https://github.com/nagolinc) |
@@ -2581,15 +2582,52 @@ result.images[0].save("result.png")
25812582

25822583
original image mech.png
25832584

2584-
<img src=<https://github.com/noskill/diffusers/assets/733626/10ad972d-d655-43cb-8de1-039e3d79e849> width="25%" >
2585+
<img src=https://github.com/noskill/diffusers/assets/733626/10ad972d-d655-43cb-8de1-039e3d79e849 width="25%" >
25852586

25862587
image with mask mech_painted.png
25872588

2588-
<img src=<https://github.com/noskill/diffusers/assets/733626/c334466a-67fe-4377-9ff7-f46021b9c224> width="25%" >
2589+
<img src=https://github.com/noskill/diffusers/assets/733626/c334466a-67fe-4377-9ff7-f46021b9c224 width="25%" >
25892590

25902591
result:
25912592

2592-
<img src=<https://github.com/noskill/diffusers/assets/733626/23a0a71d-51db-471e-926a-107ac62512a8> width="25%" >
2593+
<img src=https://github.com/noskill/diffusers/assets/733626/23a0a71d-51db-471e-926a-107ac62512a8 width="25%" >
2594+
2595+
### Masked Im2Im Stable Diffusion Pipeline XL
2596+
2597+
This pipeline implements sketch inpaint feature from A1111 for non-inpaint models. The following code reads two images, original and one with mask painted over it. It computes mask as a difference of two images and does the inpainting in the area defined by the mask. Latent code is initialized from the image with the mask by default so the color of the mask affects the result.
2598+
2599+
```
2600+
img = PIL.Image.open("./mech.png")
2601+
# read image with mask painted over
2602+
img_paint = PIL.Image.open("./mech_painted.png")
2603+
2604+
pipeline = MaskedStableDiffusionXLImg2ImgPipeline.from_pretrained("frankjoshua/juggernautXL_v8Rundiffusion", dtype=torch.float16)
2605+
2606+
pipeline.to('cuda')
2607+
pipeline.enable_xformers_memory_efficient_attention()
2608+
2609+
prompt = "a mech warrior wearing a mask"
2610+
seed = 8348273636437
2611+
for i in range(10):
2612+
generator = torch.Generator(device="cuda").manual_seed(seed + i)
2613+
print(seed + i)
2614+
result = pipeline(prompt=prompt, blur=48, image=img_paint, original_image=img, strength=0.9,
2615+
generator=generator, num_inference_steps=60, num_images_per_prompt=1)
2616+
im = result.images[0]
2617+
im.save(f"result{i}.png")
2618+
```
2619+
2620+
original image mech.png
2621+
2622+
<img src=https://github.com/noskill/diffusers/assets/733626/10ad972d-d655-43cb-8de1-039e3d79e849 width="25%" >
2623+
2624+
image with mask mech_painted.png
2625+
2626+
<img src=https://github.com/noskill/diffusers/assets/733626/c334466a-67fe-4377-9ff7-f46021b9c224 width="25%" >
2627+
2628+
result:
2629+
2630+
<img src=https://github.com/noskill/diffusers/assets/733626/5043fb57-a785-4606-a5ba-a36704f7cb42 width="25%" >
25932631

25942632
### Prompt2Prompt Pipeline
25952633

0 commit comments

Comments
 (0)