From 7e32f9ccb4edd8e256c2a22a34fbe22aca685fb2 Mon Sep 17 00:00:00 2001 From: lllyasviel Date: Sun, 28 Jan 2024 08:03:36 -0800 Subject: [PATCH] i --- README.md | 4 +-- .../scripts/sd_forge_controlnet_example.py | 4 +-- modules_forge/controlnet.py | 36 ++++++++++++------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7d240720..79ba167c 100644 --- a/README.md +++ b/README.md @@ -452,12 +452,12 @@ class ControlNetExampleForge(scripts.Script): positive_advanced_weighting = { 'input': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2], 'middle': [1.0], - 'output': [1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1] + 'output': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2] } negative_advanced_weighting = { 'input': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2], 'middle': [1.0], - 'output': [1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1] + 'output': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2] } # The advanced_frame_weighting is a weight applied to each image in a batch. diff --git a/extensions-builtin/sd_forge_controlnet_example/scripts/sd_forge_controlnet_example.py b/extensions-builtin/sd_forge_controlnet_example/scripts/sd_forge_controlnet_example.py index 6249d066..56c61c57 100644 --- a/extensions-builtin/sd_forge_controlnet_example/scripts/sd_forge_controlnet_example.py +++ b/extensions-builtin/sd_forge_controlnet_example/scripts/sd_forge_controlnet_example.py @@ -102,12 +102,12 @@ class ControlNetExampleForge(scripts.Script): positive_advanced_weighting = { 'input': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2], 'middle': [1.0], - 'output': [1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1] + 'output': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2] } negative_advanced_weighting = { 'input': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2], 'middle': [1.0], - 'output': [1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1] + 'output': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2] } # The advanced_frame_weighting is a weight applied to each image in a batch. diff --git a/modules_forge/controlnet.py b/modules_forge/controlnet.py index f88d76f3..d6e73423 100644 --- a/modules_forge/controlnet.py +++ b/modules_forge/controlnet.py @@ -18,16 +18,16 @@ def apply_controlnet_advanced( Below is an example for stronger control in middle block. This is helpful for some high-res fix passes. - positive_advanced_weighting = { - 'input': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2], - 'middle': [1.0], - 'output': [1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1] - } - negative_advanced_weighting = { - 'input': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2], - 'middle': [1.0], - 'output': [1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1] - } + positive_advanced_weighting = { + 'input': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2], + 'middle': [1.0], + 'output': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2] + } + negative_advanced_weighting = { + 'input': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2], + 'middle': [1.0], + 'output': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2] + } # advanced_frame_weighting @@ -42,9 +42,9 @@ def apply_controlnet_advanced( weights given diffusion timestep (sigma). For example below code can softly make beginning steps stronger than ending steps. - sigma_max = unet.model.model_sampling.percent_to_sigma(0.0) - sigma_min = unet.model.model_sampling.percent_to_sigma(1.0) - advanced_sigma_weighting = lambda s: (s - sigma_min) / (sigma_max - sigma_min) + sigma_max = unet.model.model_sampling.percent_to_sigma(0.0) + sigma_min = unet.model.model_sampling.percent_to_sigma(1.0) + advanced_sigma_weighting = lambda s: (s - sigma_min) / (sigma_max - sigma_min) """ @@ -67,4 +67,14 @@ def compute_controlnet_weighting( advanced_sigma_weighting, transformer_options ): + if positive_advanced_weighting is None and negative_advanced_weighting is None \ + and advanced_frame_weighting is None and advanced_sigma_weighting is None: + return control + + cond_or_uncond = transformer_options['cond_or_uncond'] + sigmas = transformer_options['sigmas'] + + if advanced_sigma_weighting is not None: + advanced_sigma_weighting = advanced_sigma_weighting(sigmas) + return control