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) diff --git a/IPAdapterPlus.py b/IPAdapterPlus.py index 905d187..92c39f6 100644 --- a/IPAdapterPlus.py +++ b/IPAdapterPlus.py @@ -310,9 +310,9 @@ def ipadapter_execute(model, 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 } + weight = { 4:weight*0.3, 5:weight*0.5, 8:weight*1.2, 9:weight*1.2, 10:weight*1.2 } 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 } + 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 }