feat: add method parameter for highres mode
This commit is contained in:
parent
0f79f420b7
commit
f451d8db74
|
@ -89,7 +89,11 @@ def run_txt2img_pipeline(
|
|||
callback=progress,
|
||||
)
|
||||
|
||||
for image, output in zip(result.images, outputs):
|
||||
image_outputs = list(zip(result.images, outputs))
|
||||
del result
|
||||
del pipe
|
||||
|
||||
for image, output in image_outputs:
|
||||
if highres.scale > 1:
|
||||
highres_progress = ChainProgress.from_progress(progress)
|
||||
|
||||
|
@ -99,7 +103,10 @@ def run_txt2img_pipeline(
|
|||
StageParams(),
|
||||
params,
|
||||
image,
|
||||
upscale=upscale,
|
||||
upscale=upscale.with_args(
|
||||
scale=1,
|
||||
outscale=1,
|
||||
),
|
||||
callback=highres_progress,
|
||||
)
|
||||
|
||||
|
@ -116,7 +123,26 @@ def run_txt2img_pipeline(
|
|||
)
|
||||
|
||||
def highres_tile(tile: Image.Image, dims):
|
||||
tile = tile.resize((size.height, size.width))
|
||||
if highres.method == "bilinear":
|
||||
logger.debug("using bilinear interpolation for highres")
|
||||
tile = tile.resize((size.height, size.width), resample=Image.Resampling.BILINEAR)
|
||||
elif highres.method == "lanczos":
|
||||
logger.debug("using Lanczos interpolation for highres")
|
||||
tile = tile.resize((size.height, size.width), resample=Image.Resampling.LANCZOS)
|
||||
else:
|
||||
logger.debug("using upscaling pipeline for highres")
|
||||
tile = run_upscale_correction(
|
||||
job,
|
||||
server,
|
||||
StageParams(),
|
||||
params,
|
||||
image,
|
||||
upscale=upscale.with_args(
|
||||
faces=False,
|
||||
),
|
||||
callback=highres_progress,
|
||||
)
|
||||
|
||||
if params.lpw:
|
||||
logger.debug("using LPW pipeline for highres")
|
||||
rng = torch.manual_seed(params.seed)
|
||||
|
|
|
@ -325,16 +325,19 @@ class HighresParams:
|
|||
scale: int,
|
||||
steps: int,
|
||||
strength: float,
|
||||
method: Literal["bilinear", "lanczos", "upscale"] = "lanczos",
|
||||
):
|
||||
self.scale = scale
|
||||
self.steps = steps
|
||||
self.strength = strength
|
||||
self.method = method
|
||||
|
||||
def resize(self, size: Size) -> Size:
|
||||
return Size(size.width * self.scale, size.height * self.scale)
|
||||
|
||||
def tojson(self):
|
||||
return {
|
||||
"method": self.method,
|
||||
"scale": self.scale,
|
||||
"steps": self.steps,
|
||||
"strength": self.strength,
|
||||
|
|
|
@ -51,6 +51,11 @@ mask_filters = {
|
|||
"gaussian-multiply": mask_filter_gaussian_multiply,
|
||||
"gaussian-screen": mask_filter_gaussian_screen,
|
||||
}
|
||||
highres_methods = {
|
||||
"bilinear": highres_method_bilinear,
|
||||
"lanczos": highres_method_lanczos,
|
||||
"upscale": highres_method_upscale,
|
||||
}
|
||||
|
||||
|
||||
# Available ORT providers
|
||||
|
@ -94,6 +99,10 @@ def get_extra_strings():
|
|||
return extra_strings
|
||||
|
||||
|
||||
def get_highres_methods():
|
||||
return highres_methods
|
||||
|
||||
|
||||
def get_mask_filters():
|
||||
return mask_filters
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ from .load import (
|
|||
get_available_platforms,
|
||||
get_config_value,
|
||||
get_correction_models,
|
||||
get_highres_methods,
|
||||
get_upscaling_models,
|
||||
)
|
||||
from .utils import get_model_path
|
||||
|
@ -179,6 +180,7 @@ def upscale_from_request() -> UpscaleParams:
|
|||
|
||||
|
||||
def highres_from_request() -> HighresParams:
|
||||
method = get_from_list(request.args, "highresMethod", get_highres_methods())
|
||||
scale = get_and_clamp_int(request.args, "highresScale", 1, 4, 1)
|
||||
steps = get_and_clamp_int(request.args, "highresSteps", 1, 200, 1)
|
||||
strength = get_and_clamp_float(request.args, "highresStrength", 0.5, 1.0, 0.0)
|
||||
|
@ -187,4 +189,5 @@ def highres_from_request() -> HighresParams:
|
|||
scale,
|
||||
steps,
|
||||
strength,
|
||||
method=method,
|
||||
)
|
||||
|
|
|
@ -22,6 +22,7 @@ MEMORY_ERRORS = [
|
|||
"hipErrorOutOfMemory",
|
||||
"MIOPEN failure 7",
|
||||
"out of memory",
|
||||
"rocblas_status_memory_error",
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -60,6 +60,14 @@
|
|||
"max": 1024,
|
||||
"step": 8
|
||||
},
|
||||
"highresMethods": {
|
||||
"default": "lanczos",
|
||||
"keys": [
|
||||
"bilinear",
|
||||
"lanczos",
|
||||
"upscale"
|
||||
]
|
||||
},
|
||||
"highresScale": {
|
||||
"default": 1,
|
||||
"min": 1,
|
||||
|
@ -76,7 +84,7 @@
|
|||
"default": 0.5,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.1
|
||||
"step": 0.01
|
||||
},
|
||||
"inversion": {
|
||||
"default": "",
|
||||
|
|
|
@ -64,6 +64,32 @@
|
|||
"max": 1024,
|
||||
"step": 8
|
||||
},
|
||||
"highresMethods": {
|
||||
"default": "lanczos",
|
||||
"keys": [
|
||||
"bilinear",
|
||||
"lanczos",
|
||||
"upscale"
|
||||
]
|
||||
},
|
||||
"highresScale": {
|
||||
"default": 1,
|
||||
"min": 1,
|
||||
"max": 4,
|
||||
"step": 1
|
||||
},
|
||||
"highresSteps": {
|
||||
"default": 0,
|
||||
"min": 1,
|
||||
"max": 200,
|
||||
"step": 1
|
||||
},
|
||||
"highresStrength": {
|
||||
"default": 0.5,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.01
|
||||
},
|
||||
"inversion": {
|
||||
"default": "",
|
||||
"keys": []
|
||||
|
|
|
@ -147,6 +147,7 @@ export interface BlendParams {
|
|||
export interface HighresParams {
|
||||
enabled: boolean;
|
||||
|
||||
highresMethod: string;
|
||||
highresScale: number;
|
||||
highresSteps: number;
|
||||
highresStrength: number;
|
||||
|
@ -503,6 +504,7 @@ export function makeClient(root: string, f = fetch): ApiClient {
|
|||
}
|
||||
|
||||
if (doesExist(highres) && highres.enabled) {
|
||||
url.searchParams.append('highresMethod', highres.highresMethod);
|
||||
url.searchParams.append('highresScale', highres.highresScale.toFixed(FIXED_INTEGER));
|
||||
url.searchParams.append('highresSteps', highres.highresSteps.toFixed(FIXED_INTEGER));
|
||||
url.searchParams.append('highresStrength', highres.highresStrength.toFixed(FIXED_FLOAT));
|
||||
|
|
|
@ -69,5 +69,22 @@ export function HighresControl() {
|
|||
});
|
||||
}}
|
||||
/>
|
||||
<FormControl>
|
||||
<InputLabel id={'highres-method'}>{t('parameter.highres.method')}</InputLabel>
|
||||
<Select
|
||||
labelId={'highres-method'}
|
||||
label={t('parameter.highres.method')}
|
||||
value={highres.highresMethod}
|
||||
onChange={(e) => {
|
||||
setHighres({
|
||||
highresMethod: e.target.value,
|
||||
});
|
||||
}}
|
||||
>
|
||||
{Object.entries(params.highresMethod.keys).map(([key, name]) =>
|
||||
<MenuItem key={key} value={name}>{t(`highresMethod.${name}`)}</MenuItem>)
|
||||
}
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Stack>;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ export function UpscaleControl() {
|
|||
}}
|
||||
/>
|
||||
<FormControl>
|
||||
<InputLabel id={'upscale-order'}>Upscale Order</InputLabel>
|
||||
<InputLabel id={'upscale-order'}>{t('parameter.upscale.order')}</InputLabel>
|
||||
<Select
|
||||
labelId={'upscale-order'}
|
||||
label={t('parameter.upscale.order')}
|
||||
|
|
|
@ -433,6 +433,7 @@ export function createStateSlices(server: ServerParams) {
|
|||
const createHighresSlice: Slice<HighresSlice> = (set) => ({
|
||||
highres: {
|
||||
enabled: false,
|
||||
highresMethod: '',
|
||||
highresSteps: server.highresSteps.default,
|
||||
highresScale: server.highresScale.default,
|
||||
highresStrength: server.highresStrength.default,
|
||||
|
@ -449,6 +450,7 @@ export function createStateSlices(server: ServerParams) {
|
|||
set({
|
||||
highres: {
|
||||
enabled: false,
|
||||
highresMethod: '',
|
||||
highresSteps: server.highresSteps.default,
|
||||
highresScale: server.highresScale.default,
|
||||
highresStrength: server.highresStrength.default,
|
||||
|
|
|
@ -12,6 +12,11 @@ export const I18N_STRINGS_DE = {
|
|||
},
|
||||
},
|
||||
generate: 'Erzeugen',
|
||||
highresMethod: {
|
||||
bilinear: '',
|
||||
lanczos: '',
|
||||
upscale: '',
|
||||
},
|
||||
history: {
|
||||
empty: 'Keine neuere Geschichte. Drücken Sie Generieren, um ein Bild zu erstellen.',
|
||||
},
|
||||
|
|
|
@ -7,6 +7,11 @@ export const I18N_STRINGS_EN = {
|
|||
},
|
||||
},
|
||||
generate: 'Generate',
|
||||
highresMethod: {
|
||||
bilinear: 'Bilinear',
|
||||
lanczos: 'Lanczos',
|
||||
upscale: 'Upscaling',
|
||||
},
|
||||
history: {
|
||||
empty: 'No recent history. Press Generate to create an image.',
|
||||
},
|
||||
|
|
|
@ -15,6 +15,11 @@ export const I18N_STRINGS_ES = {
|
|||
history: {
|
||||
empty: 'Sin antecedentes recientes. Presiona generar para crear una nueva imagen.',
|
||||
},
|
||||
highresMethod: {
|
||||
bilinear: '',
|
||||
lanczos: '',
|
||||
upscale: '',
|
||||
},
|
||||
input: {
|
||||
image: {
|
||||
empty: 'Por favor, seleccione una imagen.',
|
||||
|
|
|
@ -12,6 +12,11 @@ export const I18N_STRINGS_FR = {
|
|||
},
|
||||
},
|
||||
generate: 'générer',
|
||||
highresMethod: {
|
||||
bilinear: '',
|
||||
lanczos: '',
|
||||
upscale: '',
|
||||
},
|
||||
history: {
|
||||
empty: 'pas d\'histoire récente. appuyez sur générer pour créer une image.',
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue