From b6fbe11b47c5a86a33ca6e4e7546ec72222d5565 Mon Sep 17 00:00:00 2001 From: s9roll7 Date: Sun, 10 Dec 2023 10:42:58 +0900 Subject: [PATCH] Fixed a bug that json files with controlnet omitted were not available --- src/animatediff/cli.py | 9 +++++---- src/animatediff/pipelines/animation.py | 17 ++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/animatediff/cli.py b/src/animatediff/cli.py index 3b110de2..67751120 100644 --- a/src/animatediff/cli.py +++ b/src/animatediff/cli.py @@ -404,10 +404,11 @@ def generate( is_init_img_exist = img2img_map != None region_condi_list, region_list, ip_adapter_config_map, region2index = region_preprocess(model_config, width, height, length, save_dir, is_init_img_exist, is_sdxl) - for c in controlnet_type_map: - tmp_r = [region2index[r] for r in controlnet_type_map[c]["control_region_list"]] - controlnet_type_map[c]["control_region_list"] = [r for r in tmp_r if r != -1] - logger.info(f"{c=} / {controlnet_type_map[c]['control_region_list']}") + if controlnet_type_map: + for c in controlnet_type_map: + tmp_r = [region2index[r] for r in controlnet_type_map[c]["control_region_list"]] + controlnet_type_map[c]["control_region_list"] = [r for r in tmp_r if r != -1] + logger.info(f"{c=} / {controlnet_type_map[c]['control_region_list']}") # save config to output directory logger.info("Saving prompt config to output directory") diff --git a/src/animatediff/pipelines/animation.py b/src/animatediff/pipelines/animation.py index a477c167..59d4e402 100644 --- a/src/animatediff/pipelines/animation.py +++ b/src/animatediff/pipelines/animation.py @@ -2421,11 +2421,12 @@ def __call__( multi_uncond_mode = self.lora_map is not None controlnet_for_region = False - for c in controlnet_type_map: - reg_list = controlnet_type_map[c]["control_region_list"] - if reg_list: - controlnet_for_region = True - break + if controlnet_type_map: + for c in controlnet_type_map: + reg_list = controlnet_type_map[c]["control_region_list"] + if reg_list: + controlnet_for_region = True + break if controlnet_for_region or multi_uncond_mode: controlnet_for_region = True @@ -2778,8 +2779,10 @@ def resize_tensor(ten, size, do_unsharp_mask=False): shrink_controlnet = True no_shrink_type = ["controlnet_tile"] - for nt in no_shrink_type: - controlnet_type_map[nt] = controlnet_type_map.pop(nt) + if controlnet_type_map: + for nt in no_shrink_type: + if nt in controlnet_type_map: + controlnet_type_map[nt] = controlnet_type_map.pop(nt) def need_region_blend(cur_step, total_steps): if cur_step + 1 == total_steps: