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

Add fast prescale option to upscaler settings (off by default) #16348

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

Conversation

LoganBooker
Copy link
Contributor

Description

By default, upscaling will loop several times to upscale incoming images to the target dimensions. This is necessary, as upscaling models work in fixed increments (x4 is common). However, for very small images, such as those generated by ADetailer for inpainting, this can regularly result two upscaling steps. The second step is often expensive, far exceeding the target dimensions, and is particularly wasteful as it will be forcibly downsized by the final part of the upscale method anyway.

Examining the behaviour, it's often the case that a minor resize using Lanczos before the upscaling loop would guarantee a single upscaling step that hits or slightly exceeds the target dimensions.

This commit introduces an optional value to the upscaler settings allowing this minor resize, should the incoming image fall below a certain threshold compared to the fixed scaling value of the upscaling model. By default, this setting is set to 1.0, disabling it. Values of 1.25-3.0 are recommended.

Screenshots/videos:

N/A

Checklist:

* By default, upscaling will loop up to 3 times to upscale the incoming image to the target dimensions. This is necessary, as upscaling models work in fixed increments (x4 is common).
* For very small images, such as those generated by ADetailer for inpainting, this can result in additional upscaling steps, which can be expensive. Usually the incoming image is only off by a small amount, so it can be preferable to do a minor upscale via Lanczos before the main upscaling step.
* We introduce an optional value to the upscaler settings to allow this minor upscale, should the incoming image fall below a certain threshold compared to the fixed scaling value of the upscaler model. By default, this setting is set to 1.0, effectively disabling it.
@light-and-ray
Copy link
Contributor

Also it's useful to add an option to select upscaler for this last step. For example this one is instant and I would like to use it for this 4x-Nomos8k-span-otf-medium

@light-and-ray
Copy link
Contributor

But I can't give a simple suggestion. Because in this implementation import recursion is unavoidable. I think it's better to move this prescale_threshold feature from Upscaler class into resize_image function. Also it's kinda more logically

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.

2 participants