AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
139.23k stars 26.42k forks source link

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

Open NPDX909 opened 1 month ago

NPDX909 commented 1 month ago

Checklist

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

Panchovix commented 1 month ago

I think draft fixes it https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/14794 (not pushed though)

w-e-w commented 1 month ago

note