-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[feat]Add strength in flux_fill pipeline (denoising strength for fluxfill) #10603
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
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've left some comments. However, we should note that Flux Fill is intended to fill areas based on a text description and not for object removal.
self.mask_processor = VaeImageProcessor( | ||
vae_scale_factor=self.vae_scale_factor * 2, | ||
vae_latent_channels=latent_channels, | ||
vae_latent_channels=self.vae.config.latent_channels, |
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.
We need to use latent_channels
here not the config directly. This allows pipelines to be used without the component e.g. FluxFillPipeline(vae=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.
I didn't know that, Thanks, I changed. :)
@@ -627,6 +659,8 @@ def disable_vae_tiling(self): | |||
# Copied from diffusers.pipelines.flux.pipeline_flux.FluxPipeline.prepare_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.
Can we copy from FluxImg2ImgPipeline.prepare_latents
or FluxInpaintPipeline.prepare_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.
Sure , That would be more clean. Thanks for the review :)
@@ -809,6 +866,10 @@ def __call__( | |||
self._joint_attention_kwargs = joint_attention_kwargs | |||
self._interrupt = False | |||
|
|||
original_image = image |
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.
Unused?
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.
yep :) Maby that came from sdxl inpaint pipeline, but it is not used in this pipeline
@@ -855,13 +952,13 @@ def __call__( | |||
if masked_image_latents is not 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.
Above # 6. Prepare mask and masked image latents
.
Thankyou for the fast and kind review, I'll revise it and test :) |
Co-authored-by: hlky <[email protected]>
Co-authored-by: hlky <[email protected]>
Co-authored-by: hlky <[email protected]>
Hmm, Maby I missed the intention than ;) @hlky Thanks for the review again, I changed the code that you've reviewed. |
Hi, you're saying you used lama to remove the object before doing this? If that's what you did, you're just essentially using this pipeline as an img2img one and the model as just a refiner. The original fill model was trained to do this without the need of changing the strength and this is from the original implementation, I'm not saying that what you're doing is wrong though, people used redux in a more different and creative way and it works alright but I want to understand your use case since I haven't encountered the need to lower the strength to make it work. Did you try what you're doing here with just the regular Flux model and the img2img pipeline? |
Thanks for your response :) I tried with sdxl model with img2img model. But not flux image2image. As I use this pipeline an image edit pipeline, I just want to use the single pipeline as an object adder or outpainter but also object remover. If I have to use my case with flux img2img pipeline I can do that, but as you know flux model is quite large. If I can use fluxfill pipeline with |
@Suprhimp To confirm, you're using lama cleaner to remove the object first? |
@hlky Yep I used lamacleaner before both case (my pipeline, and default pipeline) |
lama with the refiner is very good at removing objects. I thought the whole point of Flux fill was to replace or insert an object. Big difference there. |
Hmm I think even we use fluxfill without lamainpainter to replace or insert an object, There will be certian point to need stength. Maby, keep the original color masked but change object, or change object but referenced based image in masked area. You guys think it is unecessary to use strength referer to the orignal masked area in replace or insert an object? |
This are valid use cases but that it's again just a nasked img2img, in fact, if you want to preserve as much of the original image intact, you should always do it with img2img instead of this pipeline, and just replace the new part in the original image. Still I think they're valid points and also the one that you don't want to switch models because they're really big, but this will make the pipeline more complex, @yiyixuxu WDYT? |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
This would be a welcome addition, would be good to be able to use strength with flux fill |
@jonluca we're still waiting for @yiyixuxu feedback here, but in the meantime, do you have some demo images of using the strength with the vanilla flux fill pipeline? I mean without using it as a refiner only or with another inpainting model like lama cleaner. |
@asomoza I think it's ok to support if you think the use case is meaningful :) |
I +1 this use case. |
sure, I think it's worth it because of the VRAM usage of Flux, I'll do some quick tests as soon as possible. In the meantime @Suprhimp would you mind resolving the conflicts or do you prefer if I take it over? |
I'll try right away:) @asomoza |
@asomoza I fixed conflict and I did test with my code, it seems work well to me |
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. |
@bot /style |
Style fixes have been applied. View the workflow run here. |
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 took the liberty to fix the bad name in the prepare_latents
copy, hope you don't mind, but now we have an issue with it.
image = image.to(device=device, dtype=dtype) | ||
image_latents = self._encode_vae_image(image=image, generator=generator) | ||
if batch_size > image_latents.shape[0] and batch_size % image_latents.shape[0] == 0: | ||
# expand init_latents for batch_size | ||
additional_image_per_prompt = batch_size // image_latents.shape[0] | ||
image_latents = torch.cat([image_latents] * additional_image_per_prompt, dim=0) | ||
elif batch_size > image_latents.shape[0] and batch_size % image_latents.shape[0] != 0: | ||
raise ValueError( | ||
f"You have passed a list of generators of length {len(generator)}, but requested an effective batch" | ||
f" size of {batch_size}. Make sure the batch size matches the length of the generators." | ||
f"Cannot duplicate `image` of batch size {image_latents.shape[0]} to {batch_size} text prompts." |
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.
this part it's not the same as the prepare_latents
in FluxImg2ImgPipeline but you're commenting that this function was copied from it.
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 detail review, and yes, since FluxImg2ImgPipeline was updated 2 weeks ago, It has to be changed.
So I updated prepare_latents
function as same with in FluxImg2ImgPipeline.
And also I tested with my code, it works well. (honestly, it works better than before i think, lol)
thanks a lot! Failing tests are not related to this PR |
Thank you! I wanted to revise the last part as well, but I couldn't respond because I couldn't use the computer at that time. But I wanted to merge this PR quickly, so I asked for help. |
What does this PR do?
allows the fluxfill pipeline to have a denoising strength (denoising strength).
Before submitting
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@yiyixuxu and @asomoza
I use fluxfill pipeline to edit image or outpatin. Yes it works very well but I don't agree
Flux Fill pipeline does not require
strengthas an input like regular inpainting pipelines
this line in the docs.When remove object in the image, We need denoising strength I guess. without denoising strength I can't get clean image that remove object that I want.
let me gives you an example I tested.
this is mask and original image that I want to edit.
And this is the result with denoising strength (0.6 with revised pipeline) and none(default pipeline)
I did lama inpaint to remove more clearly in both case but output is different.
As you can see with denoising strength we can have more control with the image quality. So I think there is no reason to not use denoising strength in fluxfill pipeline
I changed the fluxfill pipeline code with reference sdxl inpaint pipeline.
So, I think there would be things that need to be fixed.
Thanks for reading :)