From e8d899f3006c57449fbbf5de9f958cfd61a3d262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E7=95=8C=E7=9A=84=E5=B0=8F=E5=AD=A6?= =?UTF-8?q?=E7=94=9F?= <15620646321@163.com> Date: Tue, 4 Mar 2025 16:09:04 +0800 Subject: [PATCH 1/3] strong_style_subject_leak --- IPAdapterPlus.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/IPAdapterPlus.py b/IPAdapterPlus.py index 905d187..83358cb 100644 --- a/IPAdapterPlus.py +++ b/IPAdapterPlus.py @@ -309,10 +309,10 @@ def ipadapter_execute(model, elif weight_type == "composition": weight = { 3:weight } if is_sdxl else { 4:weight*0.25, 5:weight } elif weight_type == "strong style transfer": - if is_sdxl: - weight = { 0:weight, 1:weight, 2:weight, 4:weight, 5:weight, 6:weight, 7:weight, 8:weight, 9:weight, 10:weight } - else: - weight = { 0:weight, 1:weight, 2:weight, 3:weight, 6:weight, 7:weight, 8:weight, 9:weight, 10:weight, 11:weight, 12:weight, 13:weight, 14:weight, 15:weight } + if is_sdxl: + weight = { 4: weight*0.3, 5: weight*0.5, 8: weight*1.2, 9: weight*1.2, 10: weight*1.2 } + else: + weight = { 4: weight*0.2, 5: weight*0.4, 9: weight*1.1, 10: weight*1.1, 11: weight*1.1 } elif weight_type == "style and composition": if is_sdxl: weight = { 3:weight_composition, 6:weight } From debc6a55fb8dc3ab306b869fcfae02cba9f6c656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E7=95=8C=E7=9A=84=E5=B0=8F=E5=AD=A6?= =?UTF-8?q?=E7=94=9F?= <15620646321@163.com> Date: Tue, 4 Mar 2025 16:16:20 +0800 Subject: [PATCH 2/3] Optimize style transfer weight hierarchy --- IPAdapterPlus.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/IPAdapterPlus.py b/IPAdapterPlus.py index 83358cb..92c39f6 100644 --- a/IPAdapterPlus.py +++ b/IPAdapterPlus.py @@ -309,10 +309,10 @@ def ipadapter_execute(model, elif weight_type == "composition": weight = { 3:weight } if is_sdxl else { 4:weight*0.25, 5:weight } elif weight_type == "strong style transfer": - if is_sdxl: - weight = { 4: weight*0.3, 5: weight*0.5, 8: weight*1.2, 9: weight*1.2, 10: weight*1.2 } - else: - weight = { 4: weight*0.2, 5: weight*0.4, 9: weight*1.1, 10: weight*1.1, 11: weight*1.1 } + if is_sdxl: + weight = { 4:weight*0.3, 5:weight*0.5, 8:weight*1.2, 9:weight*1.2, 10:weight*1.2 } + else: + weight = { 4:weight*0.2, 5:weight*0.4, 9:weight*1.1, 10:weight*1.1, 11:weight*1.1 } elif weight_type == "style and composition": if is_sdxl: weight = { 3:weight_composition, 6:weight } From 2eca1f9075ae5cf3fc9d45409adc27952a160eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E7=95=8C=E7=9A=84=E5=B0=8F=E5=AD=A6?= =?UTF-8?q?=E7=94=9F?= <15620646321@163.com> Date: Tue, 4 Mar 2025 17:38:38 +0800 Subject: [PATCH 3/3] Update CrossAttentionPatch.py --- CrossAttentionPatch.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CrossAttentionPatch.py b/CrossAttentionPatch.py index adb2079..eafdae8 100644 --- a/CrossAttentionPatch.py +++ b/CrossAttentionPatch.py @@ -204,7 +204,25 @@ def ipadapter_attention(out, q, k, v, extra_options, module_key='', ipadapter=No else: #ip_v = ip_v * weight out_ip = optimized_attention(q, ip_k, ip_v, extra_options["n_heads"]) - out_ip = out_ip * weight # I'm doing this to get the same results as before + if weight_type == "composition precise": + # ====== Adaptive Gamma Correction ====== + # Dynamic gamma range: [0.5, 1.5] based on image brightness + gamma = torch.linspace(0.5, 1.5, out_ip.shape[0], device=out_ip.device).view(-1,1,1,1) + out_ip = torch.pow(out_ip, gamma) + + # ====== Highlight Suppression ====== + highlights = (out_ip > 0.85).float() + out_ip = out_ip * (1 - highlights * 0.3) # Reduce highlights by 30% + + # ====== Midtone Boost ====== + midtones_mask = (out_ip >= 0.3) & (out_ip <= 0.7) + out_ip = torch.where(midtones_mask, out_ip * 1.4, out_ip) + + # ====== Noise Injection ====== + out_ip += torch.randn_like(out_ip) * 0.005 # Prevent color banding + out_ip = torch.clamp(out_ip, 0, 1) + else: + out_ip = out_ip * weight # I'm doing this to get the same results as before if mask is not None: mask_h = oh / math.sqrt(oh * ow / seq_len)