Skip to content

Commit

Permalink
Merge pull request #18 from spinagon/main
Browse files Browse the repository at this point in the history
feat: image_is_control support
  • Loading branch information
tazlin committed Jun 21, 2023
2 parents 0d039db + 431b85f commit aef4624
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions hordelib/horde.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ def _final_pipeline_adjustments(self, payload, pipeline_data):
"output_image.images",
payload["control_type"],
)
elif payload.get("image_is_control"):
# Connect source image directly to controlnet apply node
self.generator.reconnect_input(
pipeline_data,
"controlnet_apply.image",
"image_loader.image",
)
else:
# Connect annotator to controlnet apply node
self.generator.reconnect_input(
Expand Down
Binary file added images/test_image_is_control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images_expected/controlnet_image_is_control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions tests/test_horde_inference_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,42 @@ def test_controlnet_hires_fix(
pil_image.save(f"images/{img_filename}", quality=100)
images_to_compare.append((f"images_expected/{img_filename}", pil_image))

def test_controlnet_image_is_control(
self,
hordelib_instance: HordeLib,
stable_diffusion_modelname_for_testing: str,
):
data = {
"sampler_name": "k_dpmpp_2m",
"cfg_scale": 7.5,
"denoising_strength": 1.0,
"seed": 123456789,
"height": 512,
"width": 512,
"karras": False,
"tiling": False,
"hires_fix": False,
"clip_skip": 1,
"control_type": "openpose",
"image_is_control": True,
"return_control_map": False,
"prompt": "a woman standing in the snow",
"ddim_steps": 25,
"n_iter": 1,
"model": stable_diffusion_modelname_for_testing,
"source_image": Image.open("images/test_image_is_control.png"),
"source_processing": "img2img",
}
images_to_compare: list[tuple[str, Image.Image]] = []

pil_image = hordelib_instance.basic_inference(data)
assert pil_image is not None

img_filename = f"controlnet_image_is_control.png"

pil_image.save(f"images/{img_filename}", quality=100)
images_to_compare.append((f"images_expected/{img_filename}", pil_image))

for img_filename, pil_image in images_to_compare:
assert check_single_inference_image_similarity(
img_filename,
Expand Down

0 comments on commit aef4624

Please sign in to comment.