MCPcopy Create free account
hub / github.com/cubiq/ComfyUI_IPAdapter_plus / weights

Method weights

IPAdapterPlus.py:1655–1780  ·  view source on GitHub ↗
(self, weights='', timing='custom', frames=0, start_frame=0, end_frame=9999, add_starting_frames=0, add_ending_frames=0, method='full batch', weights_strategy=None, image=None)

Source from the content-addressed store, hash-verified

1653 CATEGORY = "ipadapter/weights"
1654
1655 def weights(self, weights='', timing='custom', frames=0, start_frame=0, end_frame=9999, add_starting_frames=0, add_ending_frames=0, method='full batch', weights_strategy=None, image=None):
1656 import random
1657
1658 frame_count = image.shape[0] if image is not None else 0
1659 if weights_strategy is not None:
1660 weights = weights_strategy["weights"]
1661 timing = weights_strategy["timing"]
1662 frames = weights_strategy["frames"]
1663 start_frame = weights_strategy["start_frame"]
1664 end_frame = weights_strategy["end_frame"]
1665 add_starting_frames = weights_strategy["add_starting_frames"]
1666 add_ending_frames = weights_strategy["add_ending_frames"]
1667 method = weights_strategy["method"]
1668 frame_count = weights_strategy["frame_count"]
1669 else:
1670 weights_strategy = {
1671 "weights": weights,
1672 "timing": timing,
1673 "frames": frames,
1674 "start_frame": start_frame,
1675 "end_frame": end_frame,
1676 "add_starting_frames": add_starting_frames,
1677 "add_ending_frames": add_ending_frames,
1678 "method": method,
1679 "frame_count": frame_count,
1680 }
1681
1682 # convert the string to a list of floats separated by commas or newlines
1683 weights = weights.replace("\n", ",")
1684 weights = [float(weight) for weight in weights.split(",") if weight.strip() != ""]
1685
1686 if timing != "custom":
1687 frames = max(frames, 2)
1688 start = 0.0
1689 end = 1.0
1690
1691 if len(weights) > 0:
1692 start = weights[0]
1693 end = weights[-1]
1694
1695 weights = []
1696
1697 end_frame = min(end_frame, frames)
1698 duration = end_frame - start_frame
1699 if start_frame > 0:
1700 weights.extend([start] * start_frame)
1701
1702 for i in range(duration):
1703 n = duration - 1
1704 if timing == "linear":
1705 weights.append(start + (end - start) * i / n)
1706 elif timing == "ease_in_out":
1707 weights.append(start + (end - start) * (1 - math.cos(i / n * math.pi)) / 2)
1708 elif timing == "ease_in":
1709 weights.append(start + (end - start) * math.sin(i / n * math.pi / 2))
1710 elif timing == "ease_out":
1711 weights.append(start + (end - start) * (1 - math.cos(i / n * math.pi / 2)))
1712 elif timing == "random":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected