diff --git a/fooocus_version.py b/fooocus_version.py index 41656e7..5090582 100644 --- a/fooocus_version.py +++ b/fooocus_version.py @@ -1 +1 @@ -version = '2.1.41' +version = '2.1.42' diff --git a/modules/async_worker.py b/modules/async_worker.py index 3a54f9c..97dade2 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -29,7 +29,7 @@ def worker(): from modules.sdxl_styles import apply_style, aspect_ratios, fooocus_expansion from modules.private_logger import log from modules.expansion import safe_str - from modules.util import join_prompts, remove_empty_str, HWC3, resize_image, image_is_generated_in_current_ui + from modules.util import join_prompts, remove_empty_str, HWC3, resize_image, image_is_generated_in_current_ui, make_sure_that_image_is_not_too_large from modules.upscaler import perform_upscale try: @@ -288,6 +288,8 @@ def worker(): denoising_strength = 0.85 if advanced_parameters.overwrite_vary_strength > 0: denoising_strength = advanced_parameters.overwrite_vary_strength + + uov_input_image = make_sure_that_image_is_not_too_large(uov_input_image) initial_pixels = core.numpy_to_pytorch(uov_input_image) progressbar(13, 'VAE encoding ...') initial_latent = core.encode_vae(vae=pipeline.final_vae, pixels=initial_pixels) diff --git a/modules/util.py b/modules/util.py index 8ab81ed..95475ea 100644 --- a/modules/util.py +++ b/modules/util.py @@ -92,6 +92,18 @@ def resize_image(im, width, height, resize_mode=1): return np.array(res) +def make_sure_that_image_is_not_too_large(x): + H, W, C = x.shape + k = float(2048 * 2048) / float(H * W) + k = k ** 0.5 + if k < 1: + H_new = int(H * k) + W_new = int(W * k) + print(f'Image is too large - resizing from ({H}, {W}) to ({H_new}, {W_new}).') + x = resize_image(x, width=W_new, height=H_new, resize_mode=0) + return x + + def HWC3(x): assert x.dtype == np.uint8 if x.ndim == 2: