Skip to content
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

Draft: hiresfix for img2img #14721

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

light-and-ray
Copy link
Contributor

@light-and-ray light-and-ray commented Jan 21, 2024

Add Hires. fix option into img2img tab #2213. Useful for generating images with high denoise straight. E.g. photo -> painting

Current implementation has issues:

  • doesn't work for inpaint. Both only masked and full picture
  • wrong total steps num in console progress bar
  • not implemented new feature with upscale image from gallery (and it won't be implemented for inpaint, I think. Only with regeneration with previos options + upscaler for img2img override, how I did in my sd-webui-replacer extension)
  • XYZ plot
  • paste fields
  • I don't know what is about API. Does txt2img api support hires. fix? I don't see it

Checklist:

hr_sampler_name: str = None
hr_prompt: str = ''
hr_negative_prompt: str = ''

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved fields and methods connected with hires fix from Txt2Img class into parent class to not dublicate

old_denoising_strength = self.denoising_strength
self.denoising_strength = self.hr_denoising_strength
samples = self.sample_hr_pass(samples, decoded_samples, seeds, subseeds, subseed_strength, prompts)
self.denoising_strength = old_denoising_strength

if self.mask is not None:
blended_samples = samples * self.nmask + self.init_latent * self.mask
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is problem with inpaint. I can't understand what I need to do, to fit upscaled area into input image. Someone who know, maybe @AUTOMATIC1111, can you fix it?

dev-stable-diffusion-webui/modules/sd_samplers_cfg_denoiser.py", line 113, in apply_blend
        blended_latent = current_latent * self.nmask + self.init_latent * self.mask
                         ~~~~~~~~~~~~~~~^~~~~~~~~~~~
    RuntimeError: The size of tensor a (128) must match the size of tensor b (64) at non-singleton dimension 3

@@ -666,6 +666,35 @@ def copy_image(img):

elif category == "accordions":
with gr.Row(elem_id="img2img_accordions", elem_classes="accordions"):

with InputAccordion(False, label="Hires. fix", elem_id="img2img_hr") as enable_hr:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just copied all staff, and changed elem_id s and denoise_straight -> hr_denoise_straight

@light-and-ray light-and-ray changed the title Draft: hiresfix for img2img first commit Draft: hiresfix for img2img Jan 21, 2024
self.height = self.firstphase_height

self.cached_hr_uc = StableDiffusionProcessingTxt2Img.cached_hr_uc
self.cached_hr_c = StableDiffusionProcessingTxt2Img.cached_hr_c
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like I forgot to change class name

@w-e-w
Copy link
Collaborator

w-e-w commented Jan 22, 2024

I think it makes more sense to just extend loopback script with image upscaling
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/8a6a4ad894c2e28bcb6924490396997bfed7f07f/scripts/loopback.py
or create a new script similer to loopback that is more specific to the usecase of "img2img hries fix"

hires fix in txt2img already adds a bunch to complexity to the pip line
so I don't think implementing this directly into the img2img pipeline is a good idea

@light-and-ray
Copy link
Contributor Author

@w-e-w I see, I will try it. I will make alternative pr

@light-and-ray
Copy link
Contributor Author

I thought it will hard to implement inpainting hires fix, but it is vice versa easier because I just need to override 1 variable in first pass (upscaler for img2img), and it's very easy for scripts

1 similar comment
@light-and-ray
Copy link
Contributor Author

I thought it will hard to implement inpainting hires fix, but it is vice versa easier because I just need to override 1 variable in first pass (upscaler for img2img), and it's very easy for scripts

@w-e-w
Copy link
Collaborator

w-e-w commented Jan 22, 2024

I don't know what is about API. Does txt2img api support hires. fix? I don't see it

yes, look again
enable_hr denoising_strength hr_scale ......

@light-and-ray
Copy link
Contributor Author

@w-e-w I have quickly explored loopback code, and understood few things:

  1. It's selectable script. I think it's possible to make always on script, but it's really unnecessary for hires fix. I have no one selectable script, for which hires fix would be useful
  2. There are a lot of things I need to add inside loopback, and It will be look too complicated and too specific for "loops = 2". So it's better to make it like extension or built-in script. I think second is better, because we can support new button to hires picture from gallery. And also we can make old hires fix for txt2img deprecated (Should we?)
  3. For txt2img hires fix also is not necessary to be inside general ui, it can be selectable script . And I agree it looks like a crutch inside txt2img pipeline

So I decided to make a new pr with selectable script for img2img[/txt2img], called like pass into hiresfix automatically, and support of new ✨ button. It would be better then just copy hires.fix crutch from txt2img into img2img

@light-and-ray light-and-ray marked this pull request as draft January 22, 2024 12:52
@w-e-w
Copy link
Collaborator

w-e-w commented Jan 22, 2024

And also we can make old hires fix for txt2img deprecated (Should we?)

I have concerted proposing to deprecate hires fix but drop the idea long ago
because I feel that it will cause chaos as lots of extensions already have different behaviors that is built on top of the current hires fix pipeline

I suggest that you join discord server (if you haven't already) and passed your ideas with the other developers and especially AUTO befor making lots of changes otherwise you work may go to waste

discord invire link is on wiki/Contributing

@light-and-ray
Copy link
Contributor Author

One more thing, ✨ button takes options from ui. It can takes from selectable script, but it less intuitive. Mb if I call script just "hires fix options" it will be more intuitive

I suggest that you join discord server

okay

@strawberrymelonpanda
Copy link

strawberrymelonpanda commented Apr 19, 2024

@light-and-ray Curious if anything came from the discord discussions. I've wanted a ✨ button / HRFix for Img2img for awhile.

@light-and-ray
Copy link
Contributor Author

@light-and-ray Curious if anything came from the discord discussions. I've wanted a ✨ button / HRFix for Img2img for awhile.

Nope nothing. Implementation in this pr is bad, because it duplicates txt2img hires fix, which is bad. Implementing new hires fix is okay, but nobody is interested

I'm not interested too, because for inpaint here it is hard to make, and my extension Replacer has improved hiresfix which now supports custom masks and fixing only one image from gallery. Maybe later I will implement hires fix for non-inpainting img2img as an extension of built-in script. Extension is more likely, because hires fix with no inpaint support looks bad for built-in feature

@strawberrymelonpanda
Copy link

Fair enough! Thanks for the info.

This draft might be better than nothing for now. I'll try out Replacer as well, maybe its hr-fix could be used stand-alone with a non-matching replacement prompt or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants