-
Notifications
You must be signed in to change notification settings - Fork 6.4k
update: FluxKontextInpaintPipeline support #11820
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
Conversation
Awesome. 👍 |
Fantastic! Would be cool to have a demo for it on Hugging Face Spaces while the PR gets reviewed :-) |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the super cool PR! I left some comments
would you be able to provide more results for different strength values for both with and without the image_reference?
image: Optional[PipelineImageInput] = None, | ||
image_reference: Optional[PipelineImageInput] = None, | ||
mask_image: PipelineImageInput = None, | ||
masked_image_latents: PipelineImageInput = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's not support masked_image_latents
for now so that we can simplify the logic a bit here - it's not used here
else: | ||
masked_image = masked_image_latents | ||
|
||
mask, masked_image_latents = self.prepare_mask_latents( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see masked_image_latents being used in this pipeline, let's remove logics that we don't need here
Hi @yiyixuxu, I just updated the code based on your comments — thank you so much! About updating the results with more Inpainting with text onlyInpainting with image conditioningIt seems that |
While waiting for the PR to be reviewed, feel free to test it using: |
Thanks again @vuongminh1907 Tested using Working good with nunchaku optimization. Will do more tests. Kindly review and merge. Nunchaku output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a test case? will merge soon
Just to confirm @yiyixuxu , should I add another test case, or will you take care of it? |
Hi! Nice work! Can you add a custom node to ComfyUI to support this ? @vuongminh1907 |
|
@nne998, I think ComfyUI can also work, these are 2 examples: |
@vuongminh1907 How about the image_reference parameter? Will that work with existing nodes? Edit: Apologies for being somewhat off-topic with a ComfyUI question. I was linked here from a ComfyUI issue and didn't realize I'd switched repos at first. |
@strawberrymelonpanda, I’ll take a look at the |
would you be able to add a test case? can reference the current tests for flux pipelines https://github.com/huggingface/diffusers/tree/main/tests/pipelines/flux |
thanks @yiyixuxu , I added test case and it passed all checks. |
@bot /style |
Style bot fixed some files and pushed the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you so much!
* update: FluxKontextInpaintPipeline support * fix: Refactor code, remove mask_image_latents and ruff check * feat: Add test case and fix with pytest * Apply style fixes * copies --------- Co-authored-by: YiYi Xu <yixu310@gmail.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Hi, is there a ComfyUI workflow that you can share that already includes "Inpainting with image conditioning"? |
Hi there, I’ve tested the 'Kontext Inpainting Conditioning' node in ComfyUI, and it works great! Could you add support for reference image conditioning to this node? @vuongminh1907 |
@HaydenCupcake I've been trying your pipeline and it seems to working only on your given example images when reference image is also given. It also doesn't work if we modify the image size ratios of your source image and reference image. Any idea what might be the issue? |
|
@yiyixuxu I have encountered the same problem with @HaydenCupcake |
@Samuel-Recovery-123 @kkumar61 Please could you share the input images and prompt for me to check quickly. |
hi @kkumar61
|
@yiyixuxu after enough tests, it seems to be an issue with the understanding of Kontext itself. May be it's not related to the pipeline. Thanks for your attention into this! |
@yiyixuxu @nitinmukesh I've an interesting finding, you might want to take a look at it and let me know what are your thoughts on this! Source Image- Target product to be placed- ![]() Output-- ![]() now with another shot of the same target product-- ![]() output-- ![]() |
@kkumar61 Kontext wasn't trained for using masks, the model was trained to use the whole image so your result makes sense, if you want a product placement you should not use inpainting but the regular pipeline or else you're going to get similar results until you win the lottery and the model places the sofa in the exact same spot that your mask allows it. To me, this pipeline will only work for some very specific scenarios like the dinosaur one, if you have multiple objects in your image and you just want to change a specific one of them, then you can mask it to so the model works on that one, but again, you can just draw a rectangle over it an tell the model to change the "object" inside the rectangle. |
@kkumar61 @asomoza , Kontext Inpainting works well only with text conditioning. When using a reference image, it doesn't perform as well because the model wasn't trained for that task. Naturally, it works only with specific cases. If you want to try inpainting with references, let's train a LoRA for your own task( Like ACE did) using this |
🚀 What does this PR do?
Hello! 👋 I'm truly impressed with Flux Kontext, but I noticed that inpainting functionality hasn’t been fully integrated yet. This PR adds support for inpainting using the 🤗 Diffusers library.
This contribution introduces:
🎯 Inpainting with text only
✅ Result using FluxKontextInpaintPipeline:

🧩 Inpainting with image conditioning
📥 Input image, mask, and reference image:



🎉 Output using FluxKontextInpaintPipeline:

I hope this PR will be helpful for the community and contribute positively to the Diffusers ecosystem! 🌱
Core library: