Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion CrossAttentionPatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions IPAdapterPlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down