Skip to content

Commit

Permalink
Fixed a defect in multi-CN support
Browse files Browse the repository at this point in the history
Found another location where number of CNs was hardcoded as 5. Now addressed.
  • Loading branch information
andyxr committed Sep 8, 2023
1 parent f0f3e17 commit a6fc0f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions scripts/deforum_helpers/animation_key_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
5 changes: 2 additions & 3 deletions scripts/deforum_helpers/deforum_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a6fc0f4

Please sign in to comment.