1
0
Fork 0

feat: make enabling highres a parameter of its own

This commit is contained in:
Sean Sube 2023-07-02 19:07:59 -05:00
parent 3edf5e6c4d
commit 99c91a301c
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
7 changed files with 79 additions and 56 deletions

View File

@ -22,10 +22,15 @@ def stage_highres(
if chain is None:
chain = ChainPipeline()
if not highres.enabled:
logger.debug("highres not enabled, skipping")
return chain
if highres.iterations < 1:
logger.debug("no highres iterations, skipping")
return chain
for _i in range(highres.iterations):
if highres.method == "upscale":
logger.debug("using upscaling pipeline for highres")
stage_upscale_correction(

View File

@ -62,7 +62,6 @@ def run_txt2img_pipeline(
)
# apply highres
for _i in range(highres.iterations):
stage_highres(
stage,
params,
@ -152,7 +151,6 @@ def run_img2img_pipeline(
)
# highres, if selected
for _i in range(highres.iterations):
stage_highres(
stage,
params,
@ -234,8 +232,17 @@ def run_inpaint_pipeline(
noise_source=noise_source,
)
# apply upscaling and correction, before highres
first_upscale, after_upscale = split_upscale(upscale)
if first_upscale:
stage_upscale_correction(
stage,
params,
upscale=first_upscale,
chain=chain,
)
# apply highres
for _i in range(highres.iterations):
stage_highres(
stage,
params,
@ -248,7 +255,7 @@ def run_inpaint_pipeline(
stage_upscale_correction(
stage,
params,
upscale=upscale,
upscale=after_upscale,
chain=chain,
)
@ -303,7 +310,6 @@ def run_upscale_pipeline(
)
# apply highres
for _i in range(highres.iterations):
stage_highres(
stage,
params,

View File

@ -421,12 +421,14 @@ class UpscaleParams:
class HighresParams:
def __init__(
self,
enabled: bool,
scale: int,
steps: int,
strength: float,
method: Literal["bilinear", "lanczos", "upscale"] = "lanczos",
iterations: int = 1,
):
self.enabled = enabled
self.scale = scale
self.steps = steps
self.strength = strength
@ -441,6 +443,7 @@ class HighresParams:
def tojson(self):
return {
"enabled": self.enabled,
"iterations": self.iterations,
"method": self.method,
"scale": self.scale,

View File

@ -283,6 +283,7 @@ def upscale_from_request() -> UpscaleParams:
def highres_from_request() -> HighresParams:
enabled = get_boolean(request.args, "highres", get_config_value("highres"))
iterations = get_and_clamp_int(
request.args,
"highresIterations",
@ -313,6 +314,7 @@ def highres_from_request() -> HighresParams:
get_config_value("highresStrength", "min"),
)
return HighresParams(
enabled,
scale,
steps,
strength,

View File

@ -64,6 +64,9 @@
"max": 8192,
"step": 8
},
"highres": {
"default": false
},
"highresIterations": {
"default": 1,
"min": 1,

View File

@ -123,6 +123,7 @@ export function appendUpscaleToURL(url: URL, upscale: UpscaleParams) {
export function appendHighresToURL(url: URL, highres: HighresParams) {
if (highres.enabled) {
url.searchParams.append('highres', String(highres.enabled));
url.searchParams.append('highresIterations', highres.highresIterations.toFixed(FIXED_INTEGER));
url.searchParams.append('highresMethod', highres.highresMethod);
url.searchParams.append('highresScale', highres.highresScale.toFixed(FIXED_INTEGER));

View File

@ -68,6 +68,9 @@
"max": 8192,
"step": 8
},
"highres": {
"default": false
},
"highresMethod": {
"default": "lanczos",
"keys": [