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

[Bug]: Upscaler.py causes infinite loop (fix inside) #16234

Open
3 of 6 tasks
NPDX909 opened this issue Jul 18, 2024 · 2 comments
Open
3 of 6 tasks

[Bug]: Upscaler.py causes infinite loop (fix inside) #16234

NPDX909 opened this issue Jul 18, 2024 · 2 comments
Labels
bug-report Report of a bug, yet to be confirmed

Comments

@NPDX909
Copy link

NPDX909 commented Jul 18, 2024

Checklist

  • The issue exists after disabling all extensions
  • The issue exists on a clean installation of webui
  • The issue is caused by an extension, but I believe it is caused by a bug in the webui
  • The issue exists in the current version of the webui
  • The issue has not been reported before recently
  • The issue has been reported before but has not been fixed yet

What happened?

The current (9d4fdc4) copy of upscaler.py does not fix the 1x upscaler infinite loop issue: https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/upscaler.py. Here is what is wrong ...

The if statement on line 59 checks three conditions simultaneously: img.width >= dest_w, img.height >= dest_h, and scale != 1.
The loop will break only if all three conditions are met. If any one of them is not met, the loop will continue to the next iteration.

The code inside the loop does not include any logic for upscaling the image. Without upscaling logic, the image dimensions will not change, and the conditions will not be reevaluated correctly.

There is no check to see if the dimensions of the image have changed after a potential upscaling operation. This means there's no way to break the loop if the upscaling doesn't affect the image dimensions.

So here's what I tried to do:

  1. Check if the image dimensions are already at or above the desired width and height. If so, it breaks out of the loop.
  2. Store the current dimensions of the image in shape.
  3. Upscale the image using the do_upscale method and the selected model.
  4. Check if the dimensions of the image are the same after upscaling. If so, it breaks out of the loop.

Remove lines 59-61 in upscaler.py and insert this instead

for _ in range(3):
            if img.width >= dest_w and img.height >= dest_h:
                break

            shape = (img.width, img.height)

            img = self.do_upscale(img, selected_model)

            if shape == (img.width, img.height):
                break

Hooray, it upscales now!


sysinfo-2024-07-18-21-29.json

Chrome Version 126.0.6478.127 Windows 10 2080 GTX with 8GB

Steps to reproduce the problem

Use any upscaler and set "upscale by" to 1x

What should have happened?

Should've upscaled

What browsers do you use to access the UI ?

Google Chrome

Sysinfo

sysinfo-2024-07-18-21-29.json

Console logs

wasn't saving them to txt sorry

Additional information

No response

@NPDX909 NPDX909 added the bug-report Report of a bug, yet to be confirmed label Jul 18, 2024
@Panchovix
Copy link

I think draft fixes it #14794 (not pushed though)

@w-e-w w-e-w mentioned this issue Jul 19, 2024
4 tasks
@w-e-w
Copy link
Collaborator

w-e-w commented Jul 19, 2024

note

  • the description of the issue is wrong, infinite loop can not cannot occur as it is cap to 3 loops
  • the proposed fixed with cause no upscall to be performed when scale is set to 1x

people set scale to 1x when using 1x upscaller models, in this case it should perform "upscale" 1 time and then break
if your fix is used, no upscale will be perform when scale is set to 1x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-report Report of a bug, yet to be confirmed
Projects
None yet
Development

No branches or pull requests

3 participants