From 4dc36268c295d98b7eb967cab7ebd4b67988cf91 Mon Sep 17 00:00:00 2001 From: Igor Aherne Date: Fri, 23 Aug 2024 06:50:33 +0200 Subject: [PATCH] bugfix: controlnet works in API - image no longer a dictionary (#1425) Generating from browser works with controlnet. Generating via API wasn't. This is because from_dict() was making 'image' and 'mask_image' a dictionary. In 'controlnet.py' function 'get_input_data' this would cause the following check to throw exception because used to be an incorrect type: elif (unit_image < 5).all() and (unit_image_fg > 5).any(): Now, they are never a dictionary and check is fine --- .../lib_controlnet/external_code.py | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/extensions-builtin/sd_forge_controlnet/lib_controlnet/external_code.py b/extensions-builtin/sd_forge_controlnet/lib_controlnet/external_code.py index e7e76963..b3991482 100644 --- a/extensions-builtin/sd_forge_controlnet/lib_controlnet/external_code.py +++ b/extensions-builtin/sd_forge_controlnet/lib_controlnet/external_code.py @@ -211,25 +211,9 @@ class ControlNetUnit: **{k: v for k, v in d.items() if k in vars(ControlNetUnit)} ) if isinstance(unit.image, str): - img = np.array(api.decode_base64_to_image(unit.image)).astype('uint8') - unit.image = { - "image": img, - "mask": np.zeros_like(img), - } + unit.image = np.array(api.decode_base64_to_image(unit.image)).astype('uint8') if isinstance(unit.mask_image, str): - mask = np.array(api.decode_base64_to_image(unit.mask_image)).astype('uint8') - if unit.image is not None: - # Attach mask on image if ControlNet has input image. - assert isinstance(unit.image, dict) - unit.image["mask"] = mask - unit.mask_image = None - else: - # Otherwise, wire to standalone mask. - # This happens in img2img when using A1111 img2img input. - unit.mask_image = { - "image": mask, - "mask": np.zeros_like(mask), - } + unit.mask_image = np.array(api.decode_base64_to_image(unit.mask_image)).astype('uint8') return unit