Fix for big scale factor

This commit is contained in:
Антон Антонов
2023-01-02 16:29:57 +03:00
parent 1620d54853
commit f1b668c63a

View File

@@ -9,10 +9,11 @@ from modules.processing import Processed
from modules.shared import opts, cmd_opts, state
def upscale(p, init_img, upscaler_index, tileSize, padding):
scale_factor = max(p.width, p.height) // tileSize
scale_factor = max(p.width, p.height) // max(init_img.width, init_img.height)
print(f"Canva size: {p.width}x{p.height}")
print(f"Tile size: {tileSize}")
print(f"Image size: {init_img.width}x{init_img.height}")
print(f"Scale factor: {scale_factor}")
upscaler = shared.sd_upscalers[upscaler_index]
p.extra_generation_params["SD upscale overlap"] = padding
@@ -20,10 +21,26 @@ def upscale(p, init_img, upscaler_index, tileSize, padding):
initial_info = None
seed = p.seed
if upscaler.name != "None":
upscaled_img = upscaler.scaler.upscale(init_img, scale_factor, upscaler.data_path)
upscaled_img = init_img
if upscaler.name == "None":
return upscaled_img.resize((p.width, p.height), resample=Image.LANCZOS)
if scale_factor > 4:
iterations = math.ceil(scale_factor / 4)
else:
upscaled_img = init_img
iterations = 1
print(f"Total iterations: {iterations}")
for i in range(iterations):
if i + 1 == iterations:
current_scale_factor = scale_factor - i * 4
else:
current_scale_factor = 4
print(f"Upscaling iteration {i} with scale factor {current_scale_factor}")
upscaled_img = upscaler.scaler.upscale(init_img, current_scale_factor, upscaler.data_path)
return upscaled_img.resize((p.width, p.height), resample=Image.LANCZOS)
@@ -45,7 +62,7 @@ class Script(scripts.Script):
seam_pass_denoise = gr.Slider(label='Seam pass denoise', minimum=0, maximum=1, step=0.01, value=0.25)
seam_pass_padding = gr.Slider(label='Seam pass padding', minimum=0, maximum=128, step=1, value=32)
return [info, upscaler_index, tileSize, mask_blur, padding, seam_pass_enabled, seam_pass_width, seam_pass_denoise, seam_pass_padding]
return [info, tileSize, mask_blur, padding, seam_pass_enabled, seam_pass_width, seam_pass_denoise, seam_pass_padding, upscaler_index]
def run(self, p, _, tileSize, mask_blur, padding, seam_pass_enabled, seam_pass_width, seam_pass_denoise, seam_pass_padding, upscaler_index):
processing.fix_seed(p)