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

'Highres Fix' option for img2img as well as txt2img #2213

Open
stevenhales opened this issue Oct 10, 2022 · 19 comments
Open

'Highres Fix' option for img2img as well as txt2img #2213

stevenhales opened this issue Oct 10, 2022 · 19 comments
Labels
enhancement New feature or request

Comments

@stevenhales
Copy link

I really think the highres fix is valuable for txt2image, and would love to see this option available for img2img as well. Thanks

@TingTingin
Copy link

highres fix is img2img it takes the img gens at a smaller res and then upscales with img2img you can already do this with img2img just take the img your generating use the same or similar prompt reduce denoising rate then change resolution and you will effectively have a highresfix

@dfaker
Copy link
Collaborator

dfaker commented Oct 11, 2022

Not quite that straightforwards, but it's also not clear if an actual 'Highres Fix' run inside img2img would actually be any better than what you describe, could certainly be an interesting test.

@aleksusklim
Copy link

The only tricky thing Highres Fix does is calculates proper low-res dimensions according to your target resolution:

desired_pixel_count = 512 * 512
actual_pixel_count = self.width * self.height
scale = math.sqrt(desired_pixel_count / actual_pixel_count)
self.firstphase_width = math.ceil(scale * self.width / 64) * 64
self.firstphase_height = math.ceil(scale * self.height / 64) * 64
self.firstphase_width_truncated = int(scale * self.width)
self.firstphase_height_truncated = int(scale * self.height)

For example, if you want to manually apply hr_fix-alike behavior for 800*600 image, you will need to calculate this: (paste in browser JS-console, for example)

var W=800,H=600;
var S=Math.sqrt(512*512/(W*H));
console.log(Math.ceil(S*W/64)*64,Math.ceil(S*H/64)*64);

It gives 640 448, thus you need to generate an image with Width=640 and Height=448, and then transfer the result to img2img for upscaling with the same prompt.
Actually, I prefer doing it manually rather then with "Highres Fix" because it greatly saves time when I'm satisfied with lowres image, but want to experiment with "Denoising strength" (by the way, my experience shows that you ought to set it 0.3-0.6: when it less then 0.25 you'll have still blurry as lowres. but larger than 0.65 an image becomes scary psychedelic mess #1716! In contrary, you may safely raise CFG Scale up to 15-25, it will make the whole image much sharper).

I pre-calculated useful dimension ratios for myself, sorted by increasing area discrepancy: (for vertical orientation, swap the numbers)

  1. 512*512, square 1:1 (for 640×640, 768×768, 1024×1024)
  2. 704*384, wide 16:9 (for 960×540, 1280×720, 1600×900)
  3. 640*448, vga 3:4 (for 800×600, 1024×768, 1280×960)
  4. 768*384, double 2:1 (for 1024×512, 1200×600, 1600×800)

@jonwong666
Copy link

jonwong666 commented Oct 15, 2022

  • has anyone attempted to write a script to port the highres fix function to img2img?
  • How about adding a double image resolution checkbox in the Loopback script?

@AnAIGuy
Copy link

AnAIGuy commented Oct 16, 2022

This would be majorly helpful. I'm not entirely sure the internal details, but using img2img on resolutions above 512x512 has a strong tendency to produce multiple heads, stacked bodies, etc similar to using txt2img without highresfix. I primarily use img2img at very high denoising strength mainly just to sample an image's color pallet. Having a way to get highres results without the typical warping would be wonderful, whether that's a highresfix checkbox or loopback.

@shiftyjmusic
Copy link

We definitely need a fix for img2img. I use img2img to basically add more details to an lower res image by setting "everything to 50%" and it works perfectly as it will draw they same image just at higher res. But you can still see at the bottom of the image it will add weird stuff that weren't part of the original image, like extra heads or the concrete ground being transformed into weird architecture...

@akabez
Copy link

akabez commented Oct 19, 2022

I can confirm that highrez fix in img2img is not working. the minute you use 1024x1024 everything gets messed up.
Just to makes things clear I don't talk about upscaling, rather use an image as a template with basic details.
The reason is when using txt2img, it's very hard to get an image that is not cropped.

see attached images, exact same settings except resolution output

img2img @ 960x960
image

img2img @ 1024x1024
image

@jonwong666
Copy link

I believe this issue is somewhat related to a bug report I made a few days ago #2841
where the noise resize function does not work.
if it did work it should resolve the issue where we can use seed variation to generate a low-res seed for hi-res img2img

@Drakmour
Copy link

Was this problem solved? I still get multibody or extra heads if I put resolution higher that 512x512. I tried to make input img 512x512 and change it to resolution I want - same effect. The only way to fix this includes much more steps that i need, and it means much more time. I need to make first a small resolution image and then adding 10% of noise every step, to get what should be done from the start.

@hansolocambo
Copy link

The option of Highres Fix. is missing SO very much I definitely agree.
I generate a hundred let's say 512x512 images. I chose the one(s) that look already great. Send them to img2img in order to generate similar variants at 1024x1024 and ... I end up with 3 legs, 2 head, faces inside the body, pieces of legs and arms everywhere. It's a f..king mess.
Only way to use img2img is to reduce diffusion enough so that all results will be very very close the original. It sure works, but it's way less interesting.
Highres Fix option should be in img2img, most definitely agree. Hope it's something that's being implemented. As it shortens a lot perspectives of creativity.

@CuNiCoding
Copy link

I don't have any knowledge of how the underlying system works, so if someone more knowledgeable could comment, it would be great.

But if it isn't a dirty hack or requires a lot of code, I too would love to see the high res. fix option become available in img2img.

@mezotaken mezotaken added the enhancement New feature or request label Jan 12, 2023
@bbecausereasonss
Copy link

High-res fix is needed for (inpainting) 100%

@ghostsquad
Copy link

highres fix is img2img it takes the img gens at a smaller res and then upscales with img2img you can already do this with img2img just take the img your generating use the same or similar prompt reduce denoising rate then change resolution and you will effectively have a highresfix

I think the point here is that the steps are well known and can be automated but currently aren't for img2img.

@BlackShadow
Copy link

Any progress on this? This feature will be added?

@coderCK2
Copy link

I'd also like to see this implemented.
My scenario: I want to use inpainting to mask the subject but keep the background the same while running an X/Y/Z plot script using Prompt S/R, which is used to generate slight variations in the subject's appearance while keeping the pose fixed via ControlNet/OpenPose.
I can easily achieve the slight variations in the subject that I'm after in txt2img, while also doing a Hires. fix for each iteration of the script in order to add detail/sharpening; the issue is keeping the background the same, hence the need for inpainting. With inpainting however, I don't get the added detail/sharpening of Hires. fix. Trying to upscale in img2img results in super weird changes to the image (extra legs, bent arms, and horrific other things 🤣). Maybe I'm not using it correctly, and if not, then trying to do what I can achieve in txt2img is just not intuitive. My above scenario/process would greatly benefit from having Hires. fix in img2img.

@Nampo
Copy link

Nampo commented Jan 21, 2024

So, still no "Hires. fix" support in img2img ?
I know that hires fix is practically img2img already, but, we can NOT choose the >>upscaler<<.
We can choose the upscaler in Extras, for example (even two of them), but we can not choose the denoising strenght there.
There is no place where you have FULL control in A1111. It might be doable in ComfyUI

@light-and-ray
Copy link
Contributor

I started to develop it today

@w-e-w
Copy link
Collaborator

w-e-w commented Jan 22, 2024

@Nampo

I know that hires fix is practically img2img already, but, we can NOT choose the >>upscaler<<.

we always can
Setting > Upscaling > Upscaler for img2img

typically upscaler is something that you set and forget about it
so there's not much benefit for it to be placed on the UI by default

but if you do want that you can add it yourself
read wiki/User-Interface-Customizations#additional-options-for-txt2img--img2img
just add upscaler_for_img2img to Settings for img2img

image

@light-and-ray
Copy link
Contributor

Yes, it's useful. I use this + inpaint-difference extension, to simulate hires fix for inpaint. And it can be used for img2img upscaling with no tilling. Much convenient then Ultimate SD / SD upscale if you don't use tiles

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

No branches or pull requests