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]: Scale by 1x in 1.7.0 does nothing on "Extras tab" and "SD Upscale" script #14738

Open
2 of 6 tasks
marchcat69 opened this issue Jan 23, 2024 · 3 comments
Open
2 of 6 tasks
Labels
bug Report of a confirmed bug

Comments

@marchcat69
Copy link

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?

In 1.7.0 version of Webui, if I select a scale factor of 1 when processing an image on the Extras tab or in the SD upscale script on Img2img tab, then the image is processed with no changes. I don't need to resize the image, I just want to use 1x Denoise model, 1x Colorize model or 1x Texturize model or other 1x GAN models with upscale factor of 1. In 1.5.2 webui version everything worked as expected.

Steps to reproduce the problem

  1. Go to Extras tab or use "SD upscale" script on Img2img tab with denoise strength = 0.
  2. Set Upscale factor of 1
  3. Select any upscaler and press "Generate"
  4. The image will not be changed

What should have happened?

The image must be denoised, colorised or textured without resizing, depending on the selected upscaler model

What browsers do you use to access the UI ?

No response

Sysinfo

"Platform": "Linux-5.8.0-2-amd64-x86_64-with-glibc2.31",
"Python": "3.11.4",
"Version": "v1.7.0",
"Commit": "cf2772fab0af5573da775e7437e6acdca424f26e",

    "torch_version": "2.1.0",
    "is_debug_build": "False",
    "cuda_compiled_version": "11.8",
    "gcc_version": "(Debian 10.2.1-6) 10.2.1 20210110",
    "clang_version": "11.0.1-2",
    "cmake_version": "version 3.26.3",
    "os": "Debian GNU/Linux 11 (bullseye) (x86_64)",
    "libc_version": "glibc-2.31",
    "python_version": "3.11.4 (main, Sep 14 2023, 15:29:16) [GCC 10.2.1 20210110] (64-bit runtime)",
    "python_platform": "Linux-5.8.0-2-amd64-x86_64-with-glibc2.31",
    "is_cuda_available": "True",
    "cuda_runtime_version": null,
    "cuda_module_loading": "LAZY",
    "nvidia_driver_version": "545.23.06",
    "nvidia_gpu_models": "GPU 0: NVIDIA GeForce RTX 2060",

    "pip_version": "pip3",
    "pip_packages": [
        "numpy==1.23.5",
        "open-clip-torch==2.20.0",
        "pytorch-lightning==1.9.4",
        "pytorch-triton==2.1.0+9e3e10c5ed",
        "torch==2.1.0.dev20230725+cu118",
        "torchdiffeq==0.2.3",
        "torchmetrics==1.0.1",
        "torchsde==0.2.6",
        "torchvision==0.16.0.dev20230725+cu118"

Console logs

SD upscaling will process a total of 1 images tiled as 1x1 per upscale in a total of 1 batches.
0it [00:00, ?it/s]

Additional information

No response

@marchcat69 marchcat69 added the bug-report Report of a bug, yet to be confirmed label Jan 23, 2024
@Cyberbeing
Copy link
Contributor

Cyberbeing commented Jan 26, 2024

The issue is being caused by this commit: 4a66638
@AUTOMATIC1111 made a well-intentioned change for v1.7.0 to prevent Upscaling from running when input size >= output size, which makes sense for avoiding unneeded 'upscaling', but forgot this code is also used 1x scale post-processing models where input size == output size.

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

You can either revert the change to upscaler.py, or do something like the following and it will fix 1x scale models, while partially retaining the intentions of the commit to at least abort when input size > output size, but not equal. The line at bottom may not be needed (maybe it does nothing?), but I re-added it just in case.

        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

            if img.width >= dest_w and img.height >= dest_h:
                break

The proper solution here would likely be to store the internal model scale somewhere (see https://github.com/chaiNNer-org/chaiNNer/blob/main/backend/src/packages/chaiNNer_pytorch/pytorch/utility/get_model_scale.py for reference for how model scale can be grabbed), and only abort the input size == output size case when the model scale is >1. Maybe the webui could parse all upscale models when loaded and add the model scale value to cache.json or something. Though this is just a random thought, as it may make the code too complex for such a simple intention.

@marchcat69
Copy link
Author

You can either revert the change to upscaler.py, or do something like the following and it will fix 1x scale models, while partially retaining the intentions of the commit to at least abort when input size > output size, but not equal. The line at bottom may not be needed (maybe it does nothing?), but I re-added it just in case.

Thanks a lot. Changing just this line fixes all issues:
if img.width > dest_w and img.height > dest_h:
Now all works like a charm.

@riperbot
Copy link

riperbot commented Mar 3, 2024

This is a great and simple solution! Now we can even just sharpen/enhance an image without resizing it using 4x-UltraSharp or something like that!

@catboxanon catboxanon added bug Report of a confirmed bug and removed bug-report Report of a bug, yet to be confirmed labels Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Report of a confirmed bug
Projects
None yet
Development

No branches or pull requests

4 participants