From c5c365b6d59a79afee2bdd924ffed2c3bfa93a53 Mon Sep 17 00:00:00 2001 From: Jordan Thompson Date: Sun, 24 Sep 2023 11:44:20 -0700 Subject: [PATCH] Allow configurable slicing --- README.md | 2 ++ nodes_freelunch.py | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d2bd98e..9b3ce51 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ - `multiscale_mode` (`COMBO`): A list of available multiscale modes: - `["Default", "Bandpass", "Low-Pass", "High-Pass", "Pass-Through", "Gaussian-Blur", "Edge-Enhancement", "Sharpen", "Multi-Bandpass", "Multi-Low-Pass", "Multi-High-Pass", "Multi-Pass-Through", "Multi-Gaussian-Blur", "Multi-Edge-Enhancement", "Multi-Sharpen"]` - `multiscale_strength` (`FLOAT`, Default: 1.0, Range: [0.0, 1.0], Step: 0.001): Strength of scaling +- `b1_slice` (`INT`, Default: 640, Range: [64, 1280], Step: 1): The size of the array slice for b1 operation +- `b2_slice` (`INT`, Default: 640, Range: [64, 640], Step: 1): The size of the array slice for b2 operation - `b1` (`FLOAT`, Default: 1.1, Range: [0.0, 10.0], Step: 0.001): `b1` output multiplier - `b2` (`FLOAT`, Default: 1.2, Range: [0.0, 10.0], Step: 0.001): `b2` output multiplier - `s1` (`FLOAT`, Default: 0.9, Range: [0.0, 10.0], Step: 0.001): `s1` Fourier transform scale strength diff --git a/nodes_freelunch.py b/nodes_freelunch.py index 1426594..9583a74 100644 --- a/nodes_freelunch.py +++ b/nodes_freelunch.py @@ -213,6 +213,8 @@ class WAS_FreeU: "model": ("MODEL",), "multiscale_mode": (list(mscales.keys()),), "multiscale_strength": ("FLOAT", {"default": 1.0, "max": 1.0, "min": 0, "step": 0.001}), + "slice_b1": ("INT", {"default": 640, "min": 64, "max": 1280, "step": 1}), + "slice_b2": ("INT", {"default": 320, "min": 64, "max": 640, "step": 1}), "b1": ("FLOAT", {"default": 1.1, "min": 0.0, "max": 10.0, "step": 0.001}), "b2": ("FLOAT", {"default": 1.2, "min": 0.0, "max": 10.0, "step": 0.001}), "s1": ("FLOAT", {"default": 0.9, "min": 0.0, "max": 10.0, "step": 0.001}), @@ -235,7 +237,7 @@ class WAS_FreeU: CATEGORY = "_for_testing" - def patch(self, model, multiscale_mode, multiscale_strength, b1, b2, s1, s2, b1_mode="add", b1_blend=1.0, b2_mode="add", b2_blend=1.0, threshold=1.0, use_override_scales="false", override_scales=""): + def patch(self, model, multiscale_mode, multiscale_strength, slice_b1, slice_b2, b1, b2, s1, s2, b1_mode="add", b1_blend=1.0, b2_mode="add", b2_blend=1.0, threshold=1.0, use_override_scales="false", override_scales=""): def output_block_patch(h, hsp, transformer_options): scales_list = [] if use_override_scales == "true": @@ -250,14 +252,14 @@ class WAS_FreeU: scales = mscales[multiscale_mode] if use_override_scales == "false" else scales_list if h.shape[1] == 1280: - h_t = h[:,:640] + h_t = h[:,:slice_b1] h_r = h_t * b1 - h[:,:640] = blending_modes[b1_mode](h_t, h_r, b1_blend) + h[:,:slice_b1] = blending_modes[b1_mode](h_t, h_r, b1_blend) hsp = Fourier_filter(hsp, threshold=threshold, scale=s1, scales=scales, strength=multiscale_strength) - if h.shape[1] == 640: - h_t = h[:,:320] - h_r = h[:,:320] * b2 - h[:,:320] = blending_modes[b2_mode](h_t, h_r, b2_blend) + if h.shape[1] == slice_b1: + h_t = h[:,:slice_b2] + h_r = h_t * b2 + h[:,:slice_b2] = blending_modes[b2_mode](h_t, h_r, b2_blend) hsp = Fourier_filter(hsp, threshold=threshold, scale=s2, scales=scales, strength=multiscale_strength) return h, hsp