Skip to content

Commit

Permalink
Merge PR #427 from Kosinkadink/develop - node autosizing + maintenance
Browse files Browse the repository at this point in the history
Node Autosizing + Small Maintenance
  • Loading branch information
Kosinkadink authored Jul 16, 2024
2 parents 1b660e5 + b10c6fd commit 4dd592e
Show file tree
Hide file tree
Showing 16 changed files with 383 additions and 37 deletions.
6 changes: 6 additions & 0 deletions animatediff/cfg_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def set_model_options_sampler_cfg_function(model_options: dict[str], sampler_cfg
if disable_cfg1_optimization:
model_options["disable_cfg1_optimization"] = True
return model_options

def set_model_options_post_cfg_function(model_options, post_cfg_function, disable_cfg1_optimization=False):
model_options["sampler_post_cfg_function"] = model_options.get("sampler_post_cfg_function", []) + [post_cfg_function]
if disable_cfg1_optimization:
model_options["disable_cfg1_optimization"] = True
return model_options
#-------------------------------------------------------------------------------


Expand Down
2 changes: 1 addition & 1 deletion animatediff/conditioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def set_mask_conds(conds: list, strength: float, set_cond_area: str,
masked_conds.append(c)
return masked_conds

def set_mask_and_combine_conds(conds: list, new_conds: list, strength: float, set_cond_area: str,
def set_mask_and_combine_conds(conds: list, new_conds: list, strength: float=1.0, set_cond_area: str="default",
opt_mask: Tensor=None, opt_lora_hook: LoraHookGroup=None, opt_timesteps: TimestepsCond=None):
combined_conds = []
for c, masked_c in zip(conds, new_conds):
Expand Down
40 changes: 27 additions & 13 deletions animatediff/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from .nodes_gen2 import (UseEvolvedSamplingNode, ApplyAnimateDiffModelNode, ApplyAnimateDiffModelBasicNode, ADKeyframeNode,
LoadAnimateDiffModelNode)
from .nodes_animatelcmi2v import (ApplyAnimateLCMI2VModel, LoadAnimateLCMI2VModelNode, LoadAnimateDiffAndInjectI2VNode, UpscaleAndVaeEncode)
from .nodes_cameractrl import (LoadAnimateDiffModelWithCameraCtrl, ApplyAnimateDiffWithCameraCtrl, CameraCtrlADKeyframeNode, LoadCameraPoses,
from .nodes_cameractrl import (LoadAnimateDiffModelWithCameraCtrl, ApplyAnimateDiffWithCameraCtrl, CameraCtrlADKeyframeNode,
LoadCameraPosesFromFile, LoadCameraPosesFromPath,
CameraCtrlPoseBasic, CameraCtrlPoseCombo, CameraCtrlPoseAdvanced, CameraCtrlManualAppendPose,
CameraCtrlReplaceCameraParameters, CameraCtrlSetOriginalAspectRatio)
from .nodes_pia import (ApplyAnimateDiffPIAModel, LoadAnimateDiffAndInjectPIANode, InputPIA_MultivalNode, InputPIA_PaperPresetsNode, PIA_ADKeyframeNode)
Expand All @@ -17,13 +18,14 @@
PairedConditioningSetMaskHooked, ConditioningSetMaskHooked,
PairedConditioningSetMaskAndCombineHooked, ConditioningSetMaskAndCombineHooked,
PairedConditioningSetUnmaskedAndCombineHooked, ConditioningSetUnmaskedAndCombineHooked,
PairedConditioningCombine, ConditioningCombine,
ConditioningTimestepsNode, SetLoraHookKeyframes,
CreateLoraHookKeyframe, CreateLoraHookKeyframeInterpolation, CreateLoraHookKeyframeFromStrengthList)
from .nodes_sample import (FreeInitOptionsNode, NoiseLayerAddWeightedNode, SampleSettingsNode, NoiseLayerAddNode, NoiseLayerReplaceNode, IterationOptionsNode,
CustomCFGNode, CustomCFGSimpleNode, CustomCFGKeyframeNode, CustomCFGKeyframeSimpleNode,
CustomCFGNode, CustomCFGSimpleNode, CustomCFGKeyframeNode, CustomCFGKeyframeSimpleNode, CustomCFGKeyframeInterpolationNode, CustomCFGKeyframeFromListNode,
CFGExtrasPAGNode, CFGExtrasPAGSimpleNode, CFGExtrasRescaleCFGNode, CFGExtrasRescaleCFGSimpleNode,
NoisedImageInjectionNode, NoisedImageInjectOptionsNode)
from .nodes_sigma_schedule import (SigmaScheduleNode, RawSigmaScheduleNode, WeightedAverageSigmaScheduleNode, InterpolatedWeightedAverageSigmaScheduleNode, SplitAndCombineSigmaScheduleNode)
from .nodes_sigma_schedule import (SigmaScheduleNode, RawSigmaScheduleNode, WeightedAverageSigmaScheduleNode, InterpolatedWeightedAverageSigmaScheduleNode, SplitAndCombineSigmaScheduleNode, SigmaScheduleToSigmasNode)
from .nodes_context import (LegacyLoopedUniformContextOptionsNode, LoopedUniformContextOptionsNode, LoopedUniformViewOptionsNode, StandardUniformContextOptionsNode, StandardStaticContextOptionsNode, BatchedContextOptionsNode,
StandardStaticViewOptionsNode, StandardUniformViewOptionsNode, ViewAsContextOptionsNode,
VisualizeContextOptionsK, VisualizeContextOptionsKAdv, VisualizeContextOptionsSCustom)
Expand Down Expand Up @@ -89,6 +91,8 @@
"ADE_ConditioningSetMaskAndCombine": ConditioningSetMaskAndCombineHooked,
"ADE_PairedConditioningSetUnmaskedAndCombine": PairedConditioningSetUnmaskedAndCombineHooked,
"ADE_ConditioningSetUnmaskedAndCombine": ConditioningSetUnmaskedAndCombineHooked,
"ADE_PairedConditioningCombine": PairedConditioningCombine,
"ADE_ConditioningCombine": ConditioningCombine,
"ADE_TimestepsConditioning": ConditioningTimestepsNode,
# Noise Layer Nodes
"ADE_NoiseLayerAdd": NoiseLayerAddNode,
Expand All @@ -110,17 +114,20 @@
"ADE_CustomCFG": CustomCFGNode,
"ADE_CustomCFGKeyframeSimple": CustomCFGKeyframeSimpleNode,
"ADE_CustomCFGKeyframe": CustomCFGKeyframeNode,
"ADE_CustomCFGKeyframeInterpolation": CustomCFGKeyframeInterpolationNode,
"ADE_CustomCFGKeyframeFromList": CustomCFGKeyframeFromListNode,
"ADE_CFGExtrasPAGSimple": CFGExtrasPAGSimpleNode,
"ADE_CFGExtrasPAG": CFGExtrasPAGNode,
"ADE_CFGExtrasRescaleCFGSimple": CFGExtrasRescaleCFGSimpleNode,
"ADE_CFGExtrasRescaleCFG": CFGExtrasRescaleCFGNode,
"ADE_SigmaSchedule": SigmaScheduleNode,
"ADE_RawSigmaSchedule": RawSigmaScheduleNode,
"ADE_SigmaScheduleWeightedAverage": WeightedAverageSigmaScheduleNode,
"ADE_SigmaScheduleWeightedAverageInterp": InterpolatedWeightedAverageSigmaScheduleNode,
"ADE_SigmaScheduleSplitAndCombine": SplitAndCombineSigmaScheduleNode,
"ADE_SigmaScheduleToSigmas": SigmaScheduleToSigmasNode,
"ADE_NoisedImageInjection": NoisedImageInjectionNode,
"ADE_NoisedImageInjectOptions": NoisedImageInjectOptionsNode,
"ADE_CFGExtrasPAGSimple": CFGExtrasPAGSimpleNode,
"ADE_CFGExtrasPAG": CFGExtrasPAGNode,
"ADE_CFGExtrasRescaleCFGSimple": CFGExtrasRescaleCFGSimpleNode,
"ADE_CFGExtrasRescaleCFG": CFGExtrasRescaleCFGNode,
# Extras Nodes
"ADE_AnimateDiffUnload": AnimateDiffUnload,
"ADE_EmptyLatentImageLarge": EmptyLatentImageLarge,
Expand All @@ -144,7 +151,8 @@
"ADE_ApplyAnimateDiffModelWithCameraCtrl": ApplyAnimateDiffWithCameraCtrl,
"ADE_LoadAnimateDiffModelWithCameraCtrl": LoadAnimateDiffModelWithCameraCtrl,
"ADE_CameraCtrlAnimateDiffKeyframe": CameraCtrlADKeyframeNode,
"ADE_LoadCameraPoses": LoadCameraPoses,
"ADE_LoadCameraPoses": LoadCameraPosesFromFile,
"ADE_LoadCameraPosesFromPath": LoadCameraPosesFromPath,
"ADE_CameraPoseBasic": CameraCtrlPoseBasic,
"ADE_CameraPoseCombo": CameraCtrlPoseCombo,
"ADE_CameraPoseAdvanced": CameraCtrlPoseAdvanced,
Expand Down Expand Up @@ -213,14 +221,16 @@
"ADE_ConditioningSetMaskAndCombine": "Set Props and Combine Cond 🎭🅐🅓",
"ADE_PairedConditioningSetUnmaskedAndCombine": "Set Unmasked Conds 🎭🅐🅓",
"ADE_ConditioningSetUnmaskedAndCombine": "Set Unmasked Cond 🎭🅐🅓",
"ADE_PairedConditioningCombine": "Manual Combine Conds 🎭🅐🅓",
"ADE_ConditioningCombine": "Manual Combine Cond 🎭🅐🅓",
"ADE_TimestepsConditioning": "Timesteps Conditioning 🎭🅐🅓",
# Noise Layer Nodes
"ADE_NoiseLayerAdd": "Noise Layer [Add] 🎭🅐🅓",
"ADE_NoiseLayerAddWeighted": "Noise Layer [Add Weighted] 🎭🅐🅓",
"ADE_NoiseLayerReplace": "Noise Layer [Replace] 🎭🅐🅓",
# AnimateDiff Settings
"ADE_AnimateDiffSettings": "AnimateDiff Settings 🎭🅐🅓",
"ADE_AdjustPESweetspotStretch": "Adjust PE [Sweetspot Stretch] 🎭🅐🅓",
"ADE_AdjustPESweetspotStretch": "Adjust PE [Sweetspot] 🎭🅐🅓",
"ADE_AdjustPEFullStretch": "Adjust PE [Full Stretch] 🎭🅐🅓",
"ADE_AdjustPEManual": "Adjust PE [Manual] 🎭🅐🅓",
"ADE_AdjustWeightAllAdd": "Adjust Weight [All◆Add] 🎭🅐🅓",
Expand All @@ -234,17 +244,20 @@
"ADE_CustomCFG": "Custom CFG [Multival] 🎭🅐🅓",
"ADE_CustomCFGKeyframeSimple": "Custom CFG Keyframe 🎭🅐🅓",
"ADE_CustomCFGKeyframe": "Custom CFG Keyframe [Multival] 🎭🅐🅓",
"ADE_CustomCFGKeyframeInterpolation": "Custom CFG Keyframes Interpolation 🎭🅐🅓",
"ADE_CustomCFGKeyframeFromList": "Custom CFG Keyframes From List 🎭🅐🅓",
"ADE_CFGExtrasPAGSimple": "CFG Extras◆PAG 🎭🅐🅓",
"ADE_CFGExtrasPAG": "CFG Extras◆PAG [Multival] 🎭🅐🅓",
"ADE_CFGExtrasRescaleCFGSimple": "CFG Extras◆RescaleCFG 🎭🅐🅓",
"ADE_CFGExtrasRescaleCFG": "CFG Extras◆RescaleCFG [Multival] 🎭🅐🅓",
"ADE_SigmaSchedule": "Create Sigma Schedule 🎭🅐🅓",
"ADE_RawSigmaSchedule": "Create Raw Sigma Schedule 🎭🅐🅓",
"ADE_SigmaScheduleWeightedAverage": "Sigma Schedule Weighted Mean 🎭🅐🅓",
"ADE_SigmaScheduleWeightedAverageInterp": "Sigma Schedule Interpolated Mean 🎭🅐🅓",
"ADE_SigmaScheduleSplitAndCombine": "Sigma Schedule Split Combine 🎭🅐🅓",
"ADE_SigmaScheduleToSigmas": "Sigma Schedule To Sigmas 🎭🅐🅓",
"ADE_NoisedImageInjection": "Image Injection 🎭🅐🅓",
"ADE_NoisedImageInjectOptions": "Image Injection Options 🎭🅐🅓",
"ADE_CFGExtrasPAGSimple": "CFG Extras◆PAG 🎭🅐🅓",
"ADE_CFGExtrasPAG": "CFG Extras◆PAG [Multival] 🎭🅐🅓",
"ADE_CFGExtrasRescaleCFGSimple": "CFG Extras◆RescaleCFG 🎭🅐🅓",
"ADE_CFGExtrasRescaleCFG": "CFG Extras◆RescaleCFG [Multival] 🎭🅐🅓",
# Extras Nodes
"ADE_AnimateDiffUnload": "AnimateDiff Unload 🎭🅐🅓",
"ADE_EmptyLatentImageLarge": "Empty Latent Image (Big Batch) 🎭🅐🅓",
Expand All @@ -269,6 +282,7 @@
"ADE_LoadAnimateDiffModelWithCameraCtrl": "Load AnimateDiff+CameraCtrl Model 🎭🅐🅓②",
"ADE_CameraCtrlAnimateDiffKeyframe": "AnimateDiff+CameraCtrl Keyframe 🎭🅐🅓",
"ADE_LoadCameraPoses": "Load CameraCtrl Poses (File) 🎭🅐🅓②",
"ADE_LoadCameraPosesFromPath": "Load CameraCtrl Poses (Path) 🎭🅐🅓②",
"ADE_CameraPoseBasic": "Create CameraCtrl Poses 🎭🅐🅓②",
"ADE_CameraPoseCombo": "Create CameraCtrl Poses (Combo) 🎭🅐🅓②",
"ADE_CameraPoseAdvanced": "Create CameraCtrl Poses (Adv.) 🎭🅐🅓②",
Expand Down
11 changes: 11 additions & 0 deletions animatediff/nodes_ad_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def INPUT_TYPES(s):
"optional": {
"pe_adjust": ("PE_ADJUST",),
"weight_adjust": ("WEIGHT_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}

Expand All @@ -30,9 +31,11 @@ def INPUT_TYPES(s):
"initial_pe_idx_offset": ("INT", {"default": 0, "min": 0, "step": 1}),
"final_pe_idx_offset": ("INT", {"default": 0, "min": 0, "step": 1}),
"print_adjustment": ("BOOLEAN", {"default": False}),

},
"optional": {
"prev_pe_adjust": ("PE_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 30}),
}
}

Expand Down Expand Up @@ -64,6 +67,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_pe_adjust": ("PE_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 20}),
}
}

Expand Down Expand Up @@ -91,6 +95,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_pe_adjust": ("PE_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 30}),
}
}

Expand Down Expand Up @@ -118,6 +123,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_weight_adjust": ("WEIGHT_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}

Expand Down Expand Up @@ -147,6 +153,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_weight_adjust": ("WEIGHT_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}

Expand Down Expand Up @@ -178,6 +185,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_weight_adjust": ("WEIGHT_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}

Expand Down Expand Up @@ -211,6 +219,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_weight_adjust": ("WEIGHT_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
}
}

Expand Down Expand Up @@ -249,6 +258,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_weight_adjust": ("WEIGHT_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 20}),
}
}

Expand Down Expand Up @@ -295,6 +305,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_weight_adjust": ("WEIGHT_ADJUST",),
"autosize": ("ADEAUTOSIZE", {"padding": 20}),
}
}

Expand Down
1 change: 1 addition & 0 deletions animatediff/nodes_animatelcmi2v.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def INPUT_TYPES(s):
"effect_multival": ("MULTIVAL",),
"ad_keyframes": ("AD_KEYFRAMES",),
"prev_m_models": ("M_MODELS",),
"autosize": ("ADEAUTOSIZE", {"padding": 70}),
}
}

Expand Down
47 changes: 45 additions & 2 deletions animatediff/nodes_cameractrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import copy
import json
import numpy as np
from pathlib import Path
from collections import OrderedDict

from .ad_settings import AnimateDiffSettings
from .adapter_cameractrl import CameraEntry
from .logger import logger
from .utils_model import get_available_motion_models, BIGMAX
from .utils_model import get_available_motion_models, calculate_file_hash, strip_path, BIGMAX
from .utils_motion import ADKeyframeGroup
from .motion_lora import MotionLoraList
from .model_injection import (MotionModelGroup, MotionModelPatcher, load_motion_module_gen2, inject_camera_encoder_into_model)
Expand Down Expand Up @@ -271,6 +272,7 @@ def INPUT_TYPES(s):
"cameractrl_multival": ("MULTIVAL",),
"inherit_missing": ("BOOLEAN", {"default": True}, ),
"guarantee_steps": ("INT", {"default": 1, "min": 0, "max": BIGMAX}),
"autosize": ("ADEAUTOSIZE", {"padding": 30}),
}
}

Expand All @@ -291,7 +293,7 @@ def load_keyframe(self,
)


class LoadCameraPoses:
class LoadCameraPosesFromFile:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
Expand All @@ -317,6 +319,46 @@ def load_camera_poses(self, pose_filename: str):
poses = [[float(x) for x in pose] for pose in poses]
poses = set_original_pose_dims(poses, pose_width=CAM.DEFAULT_POSE_WIDTH, pose_height=CAM.DEFAULT_POSE_HEIGHT)
return (poses,)


class LoadCameraPosesFromPath:
@classmethod
def INPUT_TYPES(s):
return {
"optional": {
"file_path": ("STRING", {"default": "X://path/to/pose_file.txt"}),
}
}

@classmethod
def IS_CHANGED(s, file_path, **kwargs):
if Path(file_path).is_file():
return calculate_file_hash(strip_path(file_path))
return False

@classmethod
def VALIDATE_INPUTS(s, file_path, **kwargs):
# This function never gets ran for some reason, I don't care enough to figure out why right now.
if not Path(strip_path(file_path)).is_file():
return f"Pose file not found: {file_path}"
return True

RETURN_TYPES = ("CAMERACTRL_POSES",)
CATEGORY = "Animate Diff 🎭🅐🅓/② Gen2 nodes ②/CameraCtrl/poses"
FUNCTION = "load_camera_poses"

def load_camera_poses(self, file_path: str):
file_path = strip_path(file_path)
if not Path(file_path).is_file():
raise Exception(f"Pose file not found: {file_path}")
with open(file_path, 'r') as f:
poses = f.readlines()
# first line of file is the link to source, so can be skipped,
# and the rest is a header-less CSV file separated by single spaces
poses = [pose.strip().split(' ') for pose in poses[1:]]
poses = [[float(x) for x in pose] for pose in poses]
poses = set_original_pose_dims(poses, pose_width=CAM.DEFAULT_POSE_WIDTH, pose_height=CAM.DEFAULT_POSE_HEIGHT)
return (poses,)


class CameraCtrlPoseBasic:
Expand All @@ -330,6 +372,7 @@ def INPUT_TYPES(cls):
},
"optional": {
"prev_poses": ("CAMERACTRL_POSES",),
"autosize": ("ADEAUTOSIZE", {"padding": 30}),
}
}

Expand Down
Loading

0 comments on commit 4dd592e

Please sign in to comment.