From f5c1cb1bae7a24ad6e76db135bda11bfe197dcfe Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 13 Feb 2024 08:44:52 -0500 Subject: [PATCH] ipadapter merge cleanup and add metadata --- CHANGELOG.md | 3 +++ modules/ipadapter.py | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dc503635..7592cf824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ - support for multiple input images per each ip adapter - support for multiple concurrent ip adapters *note*: you cannot mix & match ip adapters that use different *CLiP* models, for example `Base` and `Base ViT-G` + - add adapter start/end to settings, thanks @AI-Casanova + having adapter start late can help with better control over composition and prompt adherence + having adapter end early can help with overal quality and performance - unified interface in txt2img, img2img and control - enhanced xyz grid support - **FaceID** now also works with multiple input images! diff --git a/modules/ipadapter.py b/modules/ipadapter.py index 9bffa05a7..b417dfaaa 100644 --- a/modules/ipadapter.py +++ b/modules/ipadapter.py @@ -106,6 +106,8 @@ def apply(pipe, p: processing.StableDiffusionProcessing, adapter_names=[], adapt if hasattr(p, 'ip_adapter_images'): adapter_images = p.ip_adapter_images adapter_images = get_images(adapter_images) + if len(adapters) < len(adapter_images): + adapter_images = adapter_images[:len(adapters)] adapter_scales = get_scales(adapter_scales, adapter_images) p.ip_adapter_scales = adapter_scales.copy() adapter_starts = get_scales(adapter_starts, adapter_images) @@ -173,9 +175,11 @@ def apply(pipe, p: processing.StableDiffusionProcessing, adapter_names=[], adapt adapter_scales[i] = 0.00 pipe.set_ip_adapter_scale(adapter_scales) p.task_args['ip_adapter_image'] = adapter_images - p.extra_generation_params["IP Adapter"] = ';'.join([f'{os.path.splitext(adapter)[0]}:{scale}' for adapter, scale in zip(adapter_names, adapter_scales)]) t1 = time.time() - shared.log.info(f'IP adapter: adapters={adapter_names} scale={adapter_scales} image={adapter_images} time={t1-t0:.2f}') + print('HERE', adapter_names, adapter_scales, adapter_starts, adapter_ends, adapter_images) + ip_str = [f'{os.path.splitext(adapter)[0]}:{scale}:{start}:{end}' for adapter, scale, start, end in zip(adapter_names, adapter_scales, adapter_starts, adapter_ends)] + p.extra_generation_params["IP Adapter"] = ';'.join(ip_str) + shared.log.info(f'IP adapter: {ip_str} image={adapter_images} time={t1-t0:.2f}') except Exception as e: - shared.log.error(f'IP adapter failed to load: repo={base_repo} folder={ip_subfolder} weights={adapters} {e}') + shared.log.error(f'IP adapter failed to load: repo={base_repo} folder={ip_subfolder} weights={adapters} names={adapter_names} {e}') return True