From 1272d50d355fa380522274685fff8f2b74be7755 Mon Sep 17 00:00:00 2001 From: lllyasviel Date: Mon, 23 Oct 2023 06:40:18 -0700 Subject: [PATCH] fix math --- fooocus_version.py | 2 +- modules/util.py | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fooocus_version.py b/fooocus_version.py index 383afae..e634d37 100644 --- a/fooocus_version.py +++ b/fooocus_version.py @@ -1 +1 @@ -version = '2.1.733' +version = '2.1.734' diff --git a/modules/util.py b/modules/util.py index 2bd46fd..c5e8d1b 100644 --- a/modules/util.py +++ b/modules/util.py @@ -84,11 +84,22 @@ def get_image_shape_ceil(im): def set_image_shape_ceil(im, shape_ceil): - H, W, _ = im.shape - shape_ceil_before = get_shape_ceil(H, W) - k = float(shape_ceil) / shape_ceil_before - H = int(round(float(H) * k / 64.0) * 64) - W = int(round(float(W) * k / 64.0) * 64) + shape_ceil = float(shape_ceil) + + H_origin, W_origin, _ = im.shape + H, W = H_origin, W_origin + + for _ in range(256): + current_shape_ceil = get_shape_ceil(H, W) + if abs(current_shape_ceil - shape_ceil) < 0.1: + break + k = shape_ceil / current_shape_ceil + H = int(round(float(H) * k / 64.0) * 64) + W = int(round(float(W) * k / 64.0) * 64) + + if H == H_origin and W == W_origin: + return im + return resample_image(im, width=W, height=H)