From a6fc0f44b4c1ec7dc1eae65a9deaca80603297db Mon Sep 17 00:00:00 2001 From: andyxr Date: Fri, 8 Sep 2023 10:49:23 +0100 Subject: [PATCH] Fixed a defect in multi-CN support Found another location where number of CNs was hardcoded as 5. Now addressed. --- scripts/deforum_helpers/animation_key_frames.py | 4 ++-- scripts/deforum_helpers/deforum_controlnet.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/deforum_helpers/animation_key_frames.py b/scripts/deforum_helpers/animation_key_frames.py index bd4a4d163..0c28fffd5 100644 --- a/scripts/deforum_helpers/animation_key_frames.py +++ b/scripts/deforum_helpers/animation_key_frames.py @@ -76,10 +76,10 @@ class ControlNetKeys(): def __init__(self, anim_args, controlnet_args): self.fi = FrameInterpolater(max_frames=anim_args.max_frames) self.schedules = {} - max_models = shared.opts.data.get("control_net_max_models_num", 1) + max_models = shared.opts.data.get("control_net_unit_count", 1) if shared.opts.data.get("control_net_unit_count", 1) is not None else shared.opts.data.get("control_net_max_models_num", 1) num_of_models = 5 if (max_models is not None): - num_of_models = 5 if max_models <= 5 else max_models + num_of_models = num_of_models if max_models <= 5 else max_models for i in range(1, num_of_models + 1): for suffix in ['weight', 'guidance_start', 'guidance_end']: prefix = f"cn_{i}" diff --git a/scripts/deforum_helpers/deforum_controlnet.py b/scripts/deforum_helpers/deforum_controlnet.py index e884088d9..015638334 100644 --- a/scripts/deforum_helpers/deforum_controlnet.py +++ b/scripts/deforum_helpers/deforum_controlnet.py @@ -35,8 +35,7 @@ cnet = None # number of CN model tabs to show in the deforum gui. If the user has set it in the A1111 UI to a value less than 5 # then we set it to 5. Else, we respect the value they specified -max_models = shared.opts.data.get("control_net_max_models_num", 1) -num_of_models = 5 +max_models = shared.opts.data.get("control_net_unit_count", 1) if shared.opts.data.get("control_net_unit_count", 1) is not None else shared.opts.data.get("control_net_max_models_num", 1) if (max_models is not None): num_of_models = 5 if max_models <= 5 else max_models @@ -299,7 +298,7 @@ def create_cnu_dict(cn_args, prefix, img_np, mask_np, frame_idx, CnSchKeys): ] cnu = {k: getattr(cn_args, f"{prefix}_{k}") for k in keys} model_num = int(prefix.split('_')[-1]) # Extract model number from prefix (e.g., "cn_1" -> 1) - if 1 <= model_num <= 5: + if 1 <= model_num <= num_of_models: # if in loopmode and no init image (img_np, after processing in this case) provided, disable CN unit for the very first frame. Will be enabled in the next frame automatically if getattr(cn_args, f"cn_{model_num}_loopback_mode") and frame_idx == 0 and img_np is None: cnu['enabled'] = False