-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): remove nested tiling in highres
- Loading branch information
Showing
10 changed files
with
154 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from logging import getLogger | ||
from typing import Optional | ||
|
||
from ..chain.base import ChainPipeline | ||
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 | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
def stage_highres( | ||
stage: StageParams, | ||
params: ImageParams, | ||
highres: HighresParams, | ||
upscale: UpscaleParams, | ||
chain: Optional[ChainPipeline] = None, | ||
) -> ChainPipeline: | ||
logger.info("staging highres pipeline at %s", highres.scale) | ||
|
||
if chain is None: | ||
chain = ChainPipeline() | ||
|
||
if highres.iterations < 1: | ||
logger.debug("no highres iterations, skipping") | ||
return chain | ||
|
||
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, | ||
overlap=params.overlap, | ||
) | ||
else: | ||
logger.debug("using simple upscaling for highres") | ||
chain.stage( | ||
UpscaleSimpleStage(), | ||
stage, | ||
overlap=params.overlap, | ||
upscale=upscale.with_args(scale=highres.scale, outscale=highres.scale), | ||
) | ||
|
||
chain.stage( | ||
BlendImg2ImgStage(), | ||
stage, | ||
overlap=params.overlap, | ||
strength=highres.strength, | ||
) | ||
|
||
return chain |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from logging import getLogger | ||
from typing import Optional | ||
|
||
from PIL import Image | ||
|
||
from ..params import ImageParams, StageParams, UpscaleParams | ||
from ..server import ServerContext | ||
from ..worker import WorkerContext | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
class UpscaleSimpleStage: | ||
def run( | ||
self, | ||
_job: WorkerContext, | ||
_server: ServerContext, | ||
_stage: StageParams, | ||
_params: ImageParams, | ||
source: Image.Image, | ||
*, | ||
method: str, | ||
upscale: UpscaleParams, | ||
stage_source: Optional[Image.Image] = None, | ||
**kwargs, | ||
) -> Image.Image: | ||
source = stage_source or source | ||
|
||
if upscale.scale <= 1: | ||
logger.debug( | ||
"simple upscale stage run with scale of %s, skipping", upscale.scale | ||
) | ||
return source | ||
|
||
scaled_size = (source.width * upscale.scale, source.height * upscale.scale) | ||
|
||
if method == "bilinear": | ||
logger.debug("using bilinear interpolation for highres") | ||
source = source.resize(scaled_size, resample=Image.Resampling.BILINEAR) | ||
elif method == "lanczos": | ||
logger.debug("using Lanczos interpolation for highres") | ||
source = source.resize(scaled_size, resample=Image.Resampling.LANCZOS) | ||
else: | ||
logger.warning("unknown upscaling method: %s", method) | ||
|
||
return source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters