2023-07-02 17:16:13 +00:00
|
|
|
from logging import getLogger
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from ..chain.blend_img2img import BlendImg2ImgStage
|
|
|
|
from ..chain.upscale import stage_upscale_correction
|
|
|
|
from ..chain.upscale_simple import UpscaleSimpleStage
|
|
|
|
from ..params import HighresParams, ImageParams, StageParams, UpscaleParams
|
2023-11-19 00:13:13 +00:00
|
|
|
from .pipeline import ChainPipeline
|
2023-07-02 17:16:13 +00:00
|
|
|
|
|
|
|
logger = getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def stage_highres(
|
|
|
|
stage: StageParams,
|
|
|
|
params: ImageParams,
|
|
|
|
highres: HighresParams,
|
|
|
|
upscale: UpscaleParams,
|
|
|
|
chain: Optional[ChainPipeline] = None,
|
2023-08-30 01:53:16 +00:00
|
|
|
prompt_index: Optional[int] = None,
|
2023-07-02 17:16:13 +00:00
|
|
|
) -> ChainPipeline:
|
|
|
|
logger.info("staging highres pipeline at %s", highres.scale)
|
|
|
|
|
|
|
|
if chain is None:
|
|
|
|
chain = ChainPipeline()
|
|
|
|
|
2023-07-03 00:07:59 +00:00
|
|
|
if not highres.enabled:
|
|
|
|
logger.debug("highres not enabled, skipping")
|
|
|
|
return chain
|
|
|
|
|
2023-07-02 17:16:13 +00:00
|
|
|
if highres.iterations < 1:
|
|
|
|
logger.debug("no highres iterations, skipping")
|
|
|
|
return chain
|
|
|
|
|
2023-08-30 01:53:16 +00:00
|
|
|
for i in range(highres.iterations):
|
2023-07-03 00:07:59 +00:00
|
|
|
if highres.method == "upscale":
|
|
|
|
logger.debug("using upscaling pipeline for highres")
|
|
|
|
stage_upscale_correction(
|
|
|
|
stage,
|
|
|
|
params,
|
|
|
|
upscale=upscale.with_args(
|
|
|
|
faces=False,
|
|
|
|
scale=highres.scale,
|
|
|
|
outscale=highres.scale,
|
|
|
|
),
|
|
|
|
chain=chain,
|
2023-11-05 01:41:58 +00:00
|
|
|
overlap=params.vae_overlap,
|
2023-07-03 00:07:59 +00:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
logger.debug("using simple upscaling for highres")
|
|
|
|
chain.stage(
|
|
|
|
UpscaleSimpleStage(),
|
|
|
|
stage,
|
|
|
|
method=highres.method,
|
2023-11-05 01:41:58 +00:00
|
|
|
overlap=params.vae_overlap,
|
2023-07-03 00:07:59 +00:00
|
|
|
upscale=upscale.with_args(scale=highres.scale, outscale=highres.scale),
|
|
|
|
)
|
|
|
|
|
2023-07-02 17:16:13 +00:00
|
|
|
chain.stage(
|
2023-07-03 00:07:59 +00:00
|
|
|
BlendImg2ImgStage(),
|
2023-11-25 18:25:16 +00:00
|
|
|
stage.with_args(outscale=1),
|
2023-11-05 01:41:58 +00:00
|
|
|
overlap=params.vae_overlap,
|
2023-08-30 01:53:16 +00:00
|
|
|
prompt_index=prompt_index + i,
|
2023-07-03 00:07:59 +00:00
|
|
|
strength=highres.strength,
|
2023-07-02 17:16:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return chain
|