Skip to content

Commit 4dd592e

Browse files
authored
Merge PR #427 from Kosinkadink/develop - node autosizing + maintenance
Node Autosizing + Small Maintenance
2 parents 1b660e5 + b10c6fd commit 4dd592e

16 files changed

+383
-37
lines changed

animatediff/cfg_extras.py

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def set_model_options_sampler_cfg_function(model_options: dict[str], sampler_cfg
2121
if disable_cfg1_optimization:
2222
model_options["disable_cfg1_optimization"] = True
2323
return model_options
24+
25+
def set_model_options_post_cfg_function(model_options, post_cfg_function, disable_cfg1_optimization=False):
26+
model_options["sampler_post_cfg_function"] = model_options.get("sampler_post_cfg_function", []) + [post_cfg_function]
27+
if disable_cfg1_optimization:
28+
model_options["disable_cfg1_optimization"] = True
29+
return model_options
2430
#-------------------------------------------------------------------------------
2531

2632

animatediff/conditioning.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def set_mask_conds(conds: list, strength: float, set_cond_area: str,
274274
masked_conds.append(c)
275275
return masked_conds
276276

277-
def set_mask_and_combine_conds(conds: list, new_conds: list, strength: float, set_cond_area: str,
277+
def set_mask_and_combine_conds(conds: list, new_conds: list, strength: float=1.0, set_cond_area: str="default",
278278
opt_mask: Tensor=None, opt_lora_hook: LoraHookGroup=None, opt_timesteps: TimestepsCond=None):
279279
combined_conds = []
280280
for c, masked_c in zip(conds, new_conds):

animatediff/nodes.py

+27-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from .nodes_gen2 import (UseEvolvedSamplingNode, ApplyAnimateDiffModelNode, ApplyAnimateDiffModelBasicNode, ADKeyframeNode,
77
LoadAnimateDiffModelNode)
88
from .nodes_animatelcmi2v import (ApplyAnimateLCMI2VModel, LoadAnimateLCMI2VModelNode, LoadAnimateDiffAndInjectI2VNode, UpscaleAndVaeEncode)
9-
from .nodes_cameractrl import (LoadAnimateDiffModelWithCameraCtrl, ApplyAnimateDiffWithCameraCtrl, CameraCtrlADKeyframeNode, LoadCameraPoses,
9+
from .nodes_cameractrl import (LoadAnimateDiffModelWithCameraCtrl, ApplyAnimateDiffWithCameraCtrl, CameraCtrlADKeyframeNode,
10+
LoadCameraPosesFromFile, LoadCameraPosesFromPath,
1011
CameraCtrlPoseBasic, CameraCtrlPoseCombo, CameraCtrlPoseAdvanced, CameraCtrlManualAppendPose,
1112
CameraCtrlReplaceCameraParameters, CameraCtrlSetOriginalAspectRatio)
1213
from .nodes_pia import (ApplyAnimateDiffPIAModel, LoadAnimateDiffAndInjectPIANode, InputPIA_MultivalNode, InputPIA_PaperPresetsNode, PIA_ADKeyframeNode)
@@ -17,13 +18,14 @@
1718
PairedConditioningSetMaskHooked, ConditioningSetMaskHooked,
1819
PairedConditioningSetMaskAndCombineHooked, ConditioningSetMaskAndCombineHooked,
1920
PairedConditioningSetUnmaskedAndCombineHooked, ConditioningSetUnmaskedAndCombineHooked,
21+
PairedConditioningCombine, ConditioningCombine,
2022
ConditioningTimestepsNode, SetLoraHookKeyframes,
2123
CreateLoraHookKeyframe, CreateLoraHookKeyframeInterpolation, CreateLoraHookKeyframeFromStrengthList)
2224
from .nodes_sample import (FreeInitOptionsNode, NoiseLayerAddWeightedNode, SampleSettingsNode, NoiseLayerAddNode, NoiseLayerReplaceNode, IterationOptionsNode,
23-
CustomCFGNode, CustomCFGSimpleNode, CustomCFGKeyframeNode, CustomCFGKeyframeSimpleNode,
25+
CustomCFGNode, CustomCFGSimpleNode, CustomCFGKeyframeNode, CustomCFGKeyframeSimpleNode, CustomCFGKeyframeInterpolationNode, CustomCFGKeyframeFromListNode,
2426
CFGExtrasPAGNode, CFGExtrasPAGSimpleNode, CFGExtrasRescaleCFGNode, CFGExtrasRescaleCFGSimpleNode,
2527
NoisedImageInjectionNode, NoisedImageInjectOptionsNode)
26-
from .nodes_sigma_schedule import (SigmaScheduleNode, RawSigmaScheduleNode, WeightedAverageSigmaScheduleNode, InterpolatedWeightedAverageSigmaScheduleNode, SplitAndCombineSigmaScheduleNode)
28+
from .nodes_sigma_schedule import (SigmaScheduleNode, RawSigmaScheduleNode, WeightedAverageSigmaScheduleNode, InterpolatedWeightedAverageSigmaScheduleNode, SplitAndCombineSigmaScheduleNode, SigmaScheduleToSigmasNode)
2729
from .nodes_context import (LegacyLoopedUniformContextOptionsNode, LoopedUniformContextOptionsNode, LoopedUniformViewOptionsNode, StandardUniformContextOptionsNode, StandardStaticContextOptionsNode, BatchedContextOptionsNode,
2830
StandardStaticViewOptionsNode, StandardUniformViewOptionsNode, ViewAsContextOptionsNode,
2931
VisualizeContextOptionsK, VisualizeContextOptionsKAdv, VisualizeContextOptionsSCustom)
@@ -89,6 +91,8 @@
8991
"ADE_ConditioningSetMaskAndCombine": ConditioningSetMaskAndCombineHooked,
9092
"ADE_PairedConditioningSetUnmaskedAndCombine": PairedConditioningSetUnmaskedAndCombineHooked,
9193
"ADE_ConditioningSetUnmaskedAndCombine": ConditioningSetUnmaskedAndCombineHooked,
94+
"ADE_PairedConditioningCombine": PairedConditioningCombine,
95+
"ADE_ConditioningCombine": ConditioningCombine,
9296
"ADE_TimestepsConditioning": ConditioningTimestepsNode,
9397
# Noise Layer Nodes
9498
"ADE_NoiseLayerAdd": NoiseLayerAddNode,
@@ -110,17 +114,20 @@
110114
"ADE_CustomCFG": CustomCFGNode,
111115
"ADE_CustomCFGKeyframeSimple": CustomCFGKeyframeSimpleNode,
112116
"ADE_CustomCFGKeyframe": CustomCFGKeyframeNode,
117+
"ADE_CustomCFGKeyframeInterpolation": CustomCFGKeyframeInterpolationNode,
118+
"ADE_CustomCFGKeyframeFromList": CustomCFGKeyframeFromListNode,
119+
"ADE_CFGExtrasPAGSimple": CFGExtrasPAGSimpleNode,
120+
"ADE_CFGExtrasPAG": CFGExtrasPAGNode,
121+
"ADE_CFGExtrasRescaleCFGSimple": CFGExtrasRescaleCFGSimpleNode,
122+
"ADE_CFGExtrasRescaleCFG": CFGExtrasRescaleCFGNode,
113123
"ADE_SigmaSchedule": SigmaScheduleNode,
114124
"ADE_RawSigmaSchedule": RawSigmaScheduleNode,
115125
"ADE_SigmaScheduleWeightedAverage": WeightedAverageSigmaScheduleNode,
116126
"ADE_SigmaScheduleWeightedAverageInterp": InterpolatedWeightedAverageSigmaScheduleNode,
117127
"ADE_SigmaScheduleSplitAndCombine": SplitAndCombineSigmaScheduleNode,
128+
"ADE_SigmaScheduleToSigmas": SigmaScheduleToSigmasNode,
118129
"ADE_NoisedImageInjection": NoisedImageInjectionNode,
119130
"ADE_NoisedImageInjectOptions": NoisedImageInjectOptionsNode,
120-
"ADE_CFGExtrasPAGSimple": CFGExtrasPAGSimpleNode,
121-
"ADE_CFGExtrasPAG": CFGExtrasPAGNode,
122-
"ADE_CFGExtrasRescaleCFGSimple": CFGExtrasRescaleCFGSimpleNode,
123-
"ADE_CFGExtrasRescaleCFG": CFGExtrasRescaleCFGNode,
124131
# Extras Nodes
125132
"ADE_AnimateDiffUnload": AnimateDiffUnload,
126133
"ADE_EmptyLatentImageLarge": EmptyLatentImageLarge,
@@ -144,7 +151,8 @@
144151
"ADE_ApplyAnimateDiffModelWithCameraCtrl": ApplyAnimateDiffWithCameraCtrl,
145152
"ADE_LoadAnimateDiffModelWithCameraCtrl": LoadAnimateDiffModelWithCameraCtrl,
146153
"ADE_CameraCtrlAnimateDiffKeyframe": CameraCtrlADKeyframeNode,
147-
"ADE_LoadCameraPoses": LoadCameraPoses,
154+
"ADE_LoadCameraPoses": LoadCameraPosesFromFile,
155+
"ADE_LoadCameraPosesFromPath": LoadCameraPosesFromPath,
148156
"ADE_CameraPoseBasic": CameraCtrlPoseBasic,
149157
"ADE_CameraPoseCombo": CameraCtrlPoseCombo,
150158
"ADE_CameraPoseAdvanced": CameraCtrlPoseAdvanced,
@@ -213,14 +221,16 @@
213221
"ADE_ConditioningSetMaskAndCombine": "Set Props and Combine Cond 🎭🅐🅓",
214222
"ADE_PairedConditioningSetUnmaskedAndCombine": "Set Unmasked Conds 🎭🅐🅓",
215223
"ADE_ConditioningSetUnmaskedAndCombine": "Set Unmasked Cond 🎭🅐🅓",
224+
"ADE_PairedConditioningCombine": "Manual Combine Conds 🎭🅐🅓",
225+
"ADE_ConditioningCombine": "Manual Combine Cond 🎭🅐🅓",
216226
"ADE_TimestepsConditioning": "Timesteps Conditioning 🎭🅐🅓",
217227
# Noise Layer Nodes
218228
"ADE_NoiseLayerAdd": "Noise Layer [Add] 🎭🅐🅓",
219229
"ADE_NoiseLayerAddWeighted": "Noise Layer [Add Weighted] 🎭🅐🅓",
220230
"ADE_NoiseLayerReplace": "Noise Layer [Replace] 🎭🅐🅓",
221231
# AnimateDiff Settings
222232
"ADE_AnimateDiffSettings": "AnimateDiff Settings 🎭🅐🅓",
223-
"ADE_AdjustPESweetspotStretch": "Adjust PE [Sweetspot Stretch] 🎭🅐🅓",
233+
"ADE_AdjustPESweetspotStretch": "Adjust PE [Sweetspot] 🎭🅐🅓",
224234
"ADE_AdjustPEFullStretch": "Adjust PE [Full Stretch] 🎭🅐🅓",
225235
"ADE_AdjustPEManual": "Adjust PE [Manual] 🎭🅐🅓",
226236
"ADE_AdjustWeightAllAdd": "Adjust Weight [All◆Add] 🎭🅐🅓",
@@ -234,17 +244,20 @@
234244
"ADE_CustomCFG": "Custom CFG [Multival] 🎭🅐🅓",
235245
"ADE_CustomCFGKeyframeSimple": "Custom CFG Keyframe 🎭🅐🅓",
236246
"ADE_CustomCFGKeyframe": "Custom CFG Keyframe [Multival] 🎭🅐🅓",
247+
"ADE_CustomCFGKeyframeInterpolation": "Custom CFG Keyframes Interpolation 🎭🅐🅓",
248+
"ADE_CustomCFGKeyframeFromList": "Custom CFG Keyframes From List 🎭🅐🅓",
249+
"ADE_CFGExtrasPAGSimple": "CFG Extras◆PAG 🎭🅐🅓",
250+
"ADE_CFGExtrasPAG": "CFG Extras◆PAG [Multival] 🎭🅐🅓",
251+
"ADE_CFGExtrasRescaleCFGSimple": "CFG Extras◆RescaleCFG 🎭🅐🅓",
252+
"ADE_CFGExtrasRescaleCFG": "CFG Extras◆RescaleCFG [Multival] 🎭🅐🅓",
237253
"ADE_SigmaSchedule": "Create Sigma Schedule 🎭🅐🅓",
238254
"ADE_RawSigmaSchedule": "Create Raw Sigma Schedule 🎭🅐🅓",
239255
"ADE_SigmaScheduleWeightedAverage": "Sigma Schedule Weighted Mean 🎭🅐🅓",
240256
"ADE_SigmaScheduleWeightedAverageInterp": "Sigma Schedule Interpolated Mean 🎭🅐🅓",
241257
"ADE_SigmaScheduleSplitAndCombine": "Sigma Schedule Split Combine 🎭🅐🅓",
258+
"ADE_SigmaScheduleToSigmas": "Sigma Schedule To Sigmas 🎭🅐🅓",
242259
"ADE_NoisedImageInjection": "Image Injection 🎭🅐🅓",
243260
"ADE_NoisedImageInjectOptions": "Image Injection Options 🎭🅐🅓",
244-
"ADE_CFGExtrasPAGSimple": "CFG Extras◆PAG 🎭🅐🅓",
245-
"ADE_CFGExtrasPAG": "CFG Extras◆PAG [Multival] 🎭🅐🅓",
246-
"ADE_CFGExtrasRescaleCFGSimple": "CFG Extras◆RescaleCFG 🎭🅐🅓",
247-
"ADE_CFGExtrasRescaleCFG": "CFG Extras◆RescaleCFG [Multival] 🎭🅐🅓",
248261
# Extras Nodes
249262
"ADE_AnimateDiffUnload": "AnimateDiff Unload 🎭🅐🅓",
250263
"ADE_EmptyLatentImageLarge": "Empty Latent Image (Big Batch) 🎭🅐🅓",
@@ -269,6 +282,7 @@
269282
"ADE_LoadAnimateDiffModelWithCameraCtrl": "Load AnimateDiff+CameraCtrl Model 🎭🅐🅓②",
270283
"ADE_CameraCtrlAnimateDiffKeyframe": "AnimateDiff+CameraCtrl Keyframe 🎭🅐🅓",
271284
"ADE_LoadCameraPoses": "Load CameraCtrl Poses (File) 🎭🅐🅓②",
285+
"ADE_LoadCameraPosesFromPath": "Load CameraCtrl Poses (Path) 🎭🅐🅓②",
272286
"ADE_CameraPoseBasic": "Create CameraCtrl Poses 🎭🅐🅓②",
273287
"ADE_CameraPoseCombo": "Create CameraCtrl Poses (Combo) 🎭🅐🅓②",
274288
"ADE_CameraPoseAdvanced": "Create CameraCtrl Poses (Adv.) 🎭🅐🅓②",

animatediff/nodes_ad_settings.py

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def INPUT_TYPES(s):
99
"optional": {
1010
"pe_adjust": ("PE_ADJUST",),
1111
"weight_adjust": ("WEIGHT_ADJUST",),
12+
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
1213
}
1314
}
1415

@@ -30,9 +31,11 @@ def INPUT_TYPES(s):
3031
"initial_pe_idx_offset": ("INT", {"default": 0, "min": 0, "step": 1}),
3132
"final_pe_idx_offset": ("INT", {"default": 0, "min": 0, "step": 1}),
3233
"print_adjustment": ("BOOLEAN", {"default": False}),
34+
3335
},
3436
"optional": {
3537
"prev_pe_adjust": ("PE_ADJUST",),
38+
"autosize": ("ADEAUTOSIZE", {"padding": 30}),
3639
}
3740
}
3841

@@ -64,6 +67,7 @@ def INPUT_TYPES(s):
6467
},
6568
"optional": {
6669
"prev_pe_adjust": ("PE_ADJUST",),
70+
"autosize": ("ADEAUTOSIZE", {"padding": 20}),
6771
}
6872
}
6973

@@ -91,6 +95,7 @@ def INPUT_TYPES(s):
9195
},
9296
"optional": {
9397
"prev_pe_adjust": ("PE_ADJUST",),
98+
"autosize": ("ADEAUTOSIZE", {"padding": 30}),
9499
}
95100
}
96101

@@ -118,6 +123,7 @@ def INPUT_TYPES(s):
118123
},
119124
"optional": {
120125
"prev_weight_adjust": ("WEIGHT_ADJUST",),
126+
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
121127
}
122128
}
123129

@@ -147,6 +153,7 @@ def INPUT_TYPES(s):
147153
},
148154
"optional": {
149155
"prev_weight_adjust": ("WEIGHT_ADJUST",),
156+
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
150157
}
151158
}
152159

@@ -178,6 +185,7 @@ def INPUT_TYPES(s):
178185
},
179186
"optional": {
180187
"prev_weight_adjust": ("WEIGHT_ADJUST",),
188+
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
181189
}
182190
}
183191

@@ -211,6 +219,7 @@ def INPUT_TYPES(s):
211219
},
212220
"optional": {
213221
"prev_weight_adjust": ("WEIGHT_ADJUST",),
222+
"autosize": ("ADEAUTOSIZE", {"padding": 0}),
214223
}
215224
}
216225

@@ -249,6 +258,7 @@ def INPUT_TYPES(s):
249258
},
250259
"optional": {
251260
"prev_weight_adjust": ("WEIGHT_ADJUST",),
261+
"autosize": ("ADEAUTOSIZE", {"padding": 20}),
252262
}
253263
}
254264

@@ -295,6 +305,7 @@ def INPUT_TYPES(s):
295305
},
296306
"optional": {
297307
"prev_weight_adjust": ("WEIGHT_ADJUST",),
308+
"autosize": ("ADEAUTOSIZE", {"padding": 20}),
298309
}
299310
}
300311

animatediff/nodes_animatelcmi2v.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def INPUT_TYPES(s):
3434
"effect_multival": ("MULTIVAL",),
3535
"ad_keyframes": ("AD_KEYFRAMES",),
3636
"prev_m_models": ("M_MODELS",),
37+
"autosize": ("ADEAUTOSIZE", {"padding": 70}),
3738
}
3839
}
3940

animatediff/nodes_cameractrl.py

+45-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import copy
88
import json
99
import numpy as np
10+
from pathlib import Path
1011
from collections import OrderedDict
1112

1213
from .ad_settings import AnimateDiffSettings
1314
from .adapter_cameractrl import CameraEntry
1415
from .logger import logger
15-
from .utils_model import get_available_motion_models, BIGMAX
16+
from .utils_model import get_available_motion_models, calculate_file_hash, strip_path, BIGMAX
1617
from .utils_motion import ADKeyframeGroup
1718
from .motion_lora import MotionLoraList
1819
from .model_injection import (MotionModelGroup, MotionModelPatcher, load_motion_module_gen2, inject_camera_encoder_into_model)
@@ -271,6 +272,7 @@ def INPUT_TYPES(s):
271272
"cameractrl_multival": ("MULTIVAL",),
272273
"inherit_missing": ("BOOLEAN", {"default": True}, ),
273274
"guarantee_steps": ("INT", {"default": 1, "min": 0, "max": BIGMAX}),
275+
"autosize": ("ADEAUTOSIZE", {"padding": 30}),
274276
}
275277
}
276278

@@ -291,7 +293,7 @@ def load_keyframe(self,
291293
)
292294

293295

294-
class LoadCameraPoses:
296+
class LoadCameraPosesFromFile:
295297
@classmethod
296298
def INPUT_TYPES(s):
297299
input_dir = folder_paths.get_input_directory()
@@ -317,6 +319,46 @@ def load_camera_poses(self, pose_filename: str):
317319
poses = [[float(x) for x in pose] for pose in poses]
318320
poses = set_original_pose_dims(poses, pose_width=CAM.DEFAULT_POSE_WIDTH, pose_height=CAM.DEFAULT_POSE_HEIGHT)
319321
return (poses,)
322+
323+
324+
class LoadCameraPosesFromPath:
325+
@classmethod
326+
def INPUT_TYPES(s):
327+
return {
328+
"optional": {
329+
"file_path": ("STRING", {"default": "X://path/to/pose_file.txt"}),
330+
}
331+
}
332+
333+
@classmethod
334+
def IS_CHANGED(s, file_path, **kwargs):
335+
if Path(file_path).is_file():
336+
return calculate_file_hash(strip_path(file_path))
337+
return False
338+
339+
@classmethod
340+
def VALIDATE_INPUTS(s, file_path, **kwargs):
341+
# This function never gets ran for some reason, I don't care enough to figure out why right now.
342+
if not Path(strip_path(file_path)).is_file():
343+
return f"Pose file not found: {file_path}"
344+
return True
345+
346+
RETURN_TYPES = ("CAMERACTRL_POSES",)
347+
CATEGORY = "Animate Diff 🎭🅐🅓/② Gen2 nodes ②/CameraCtrl/poses"
348+
FUNCTION = "load_camera_poses"
349+
350+
def load_camera_poses(self, file_path: str):
351+
file_path = strip_path(file_path)
352+
if not Path(file_path).is_file():
353+
raise Exception(f"Pose file not found: {file_path}")
354+
with open(file_path, 'r') as f:
355+
poses = f.readlines()
356+
# first line of file is the link to source, so can be skipped,
357+
# and the rest is a header-less CSV file separated by single spaces
358+
poses = [pose.strip().split(' ') for pose in poses[1:]]
359+
poses = [[float(x) for x in pose] for pose in poses]
360+
poses = set_original_pose_dims(poses, pose_width=CAM.DEFAULT_POSE_WIDTH, pose_height=CAM.DEFAULT_POSE_HEIGHT)
361+
return (poses,)
320362

321363

322364
class CameraCtrlPoseBasic:
@@ -330,6 +372,7 @@ def INPUT_TYPES(cls):
330372
},
331373
"optional": {
332374
"prev_poses": ("CAMERACTRL_POSES",),
375+
"autosize": ("ADEAUTOSIZE", {"padding": 30}),
333376
}
334377
}
335378

0 commit comments

Comments
 (0)