|
|
import numpy as np
|
|
|
from torch import Tensor
|
|
|
|
|
|
import folder_paths
|
|
|
import comfy.sample
|
|
|
from comfy.model_patcher import ModelPatcher
|
|
|
|
|
|
from .control import load_controlnet, convert_to_advanced, is_advanced_controlnet, is_sd3_advanced_controlnet
|
|
|
from .utils import ControlWeights, LatentKeyframeGroup, TimestepKeyframeGroup, AbstractPreprocWrapper, BIGMAX
|
|
|
from .nodes_weight import (DefaultWeights, ScaledSoftMaskedUniversalWeights, ScaledSoftUniversalWeights,
|
|
|
SoftControlNetWeightsSD15, CustomControlNetWeightsSD15, CustomControlNetWeightsFlux,
|
|
|
SoftT2IAdapterWeights, CustomT2IAdapterWeights)
|
|
|
from .nodes_keyframes import (LatentKeyframeGroupNode, LatentKeyframeInterpolationNode, LatentKeyframeBatchedGroupNode, LatentKeyframeNode,
|
|
|
TimestepKeyframeNode, TimestepKeyframeInterpolationNode, TimestepKeyframeFromStrengthListNode)
|
|
|
from .nodes_sparsectrl import SparseCtrlMergedLoaderAdvanced, SparseCtrlLoaderAdvanced, SparseIndexMethodNode, SparseSpreadMethodNode, RgbSparseCtrlPreprocessor, SparseWeightExtras
|
|
|
from .nodes_reference import ReferenceControlNetNode, ReferenceControlFinetune, ReferencePreprocessorNode
|
|
|
from .nodes_plusplus import PlusPlusLoaderAdvanced, PlusPlusLoaderSingle, PlusPlusInputNode
|
|
|
from .nodes_loosecontrol import ControlNetLoaderWithLoraAdvanced
|
|
|
from .nodes_deprecated import (LoadImagesFromDirectory, ScaledSoftUniversalWeightsDeprecated,
|
|
|
SoftControlNetWeightsDeprecated, CustomControlNetWeightsDeprecated,
|
|
|
SoftT2IAdapterWeightsDeprecated, CustomT2IAdapterWeightsDeprecated)
|
|
|
from .logger import logger
|
|
|
|
|
|
from .sampling import acn_sample_factory
|
|
|
|
|
|
comfy.sample.sample = acn_sample_factory(comfy.sample.sample)
|
|
|
comfy.sample.sample_custom = acn_sample_factory(comfy.sample.sample_custom, is_custom=True)
|
|
|
|
|
|
|
|
|
class ControlNetLoaderAdvanced:
|
|
|
@classmethod
|
|
|
def INPUT_TYPES(s):
|
|
|
return {
|
|
|
"required": {
|
|
|
"control_net_name": (folder_paths.get_filename_list("controlnet"), ),
|
|
|
},
|
|
|
"optional": {
|
|
|
"tk_optional": ("TIMESTEP_KEYFRAME", ),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
RETURN_TYPES = ("CONTROL_NET", )
|
|
|
FUNCTION = "load_controlnet"
|
|
|
|
|
|
CATEGORY = "Adv-ControlNet ππ
π
π
"
|
|
|
|
|
|
def load_controlnet(self, control_net_name,
|
|
|
tk_optional: TimestepKeyframeGroup=None,
|
|
|
timestep_keyframe: TimestepKeyframeGroup=None,
|
|
|
):
|
|
|
if timestep_keyframe is not None:
|
|
|
tk_optional = timestep_keyframe
|
|
|
controlnet_path = folder_paths.get_full_path("controlnet", control_net_name)
|
|
|
controlnet = load_controlnet(controlnet_path, tk_optional)
|
|
|
return (controlnet,)
|
|
|
|
|
|
|
|
|
class DiffControlNetLoaderAdvanced:
|
|
|
@classmethod
|
|
|
def INPUT_TYPES(s):
|
|
|
return {
|
|
|
"required": {
|
|
|
"model": ("MODEL",),
|
|
|
"control_net_name": (folder_paths.get_filename_list("controlnet"), )
|
|
|
},
|
|
|
"optional": {
|
|
|
"tk_optional": ("TIMESTEP_KEYFRAME", ),
|
|
|
"autosize": ("ACNAUTOSIZE", {"padding": 160}),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
RETURN_TYPES = ("CONTROL_NET", )
|
|
|
FUNCTION = "load_controlnet"
|
|
|
|
|
|
CATEGORY = "Adv-ControlNet ππ
π
π
"
|
|
|
|
|
|
def load_controlnet(self, control_net_name, model,
|
|
|
tk_optional: TimestepKeyframeGroup=None,
|
|
|
timestep_keyframe: TimestepKeyframeGroup=None
|
|
|
):
|
|
|
if timestep_keyframe is not None:
|
|
|
tk_optional = timestep_keyframe
|
|
|
controlnet_path = folder_paths.get_full_path("controlnet", control_net_name)
|
|
|
controlnet = load_controlnet(controlnet_path, tk_optional, model)
|
|
|
if is_advanced_controlnet(controlnet):
|
|
|
controlnet.verify_all_weights()
|
|
|
return (controlnet,)
|
|
|
|
|
|
|
|
|
class AdvancedControlNetApply:
|
|
|
@classmethod
|
|
|
def INPUT_TYPES(s):
|
|
|
return {
|
|
|
"required": {
|
|
|
"positive": ("CONDITIONING", ),
|
|
|
"negative": ("CONDITIONING", ),
|
|
|
"control_net": ("CONTROL_NET", ),
|
|
|
"image": ("IMAGE", ),
|
|
|
"strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}),
|
|
|
"start_percent": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.001}),
|
|
|
"end_percent": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.001})
|
|
|
},
|
|
|
"optional": {
|
|
|
"mask_optional": ("MASK", ),
|
|
|
"timestep_kf": ("TIMESTEP_KEYFRAME", ),
|
|
|
"latent_kf_override": ("LATENT_KEYFRAME", ),
|
|
|
"weights_override": ("CONTROL_NET_WEIGHTS", ),
|
|
|
"model_optional": ("MODEL",),
|
|
|
"vae_optional": ("VAE",),
|
|
|
"autosize": ("ACNAUTOSIZE", {"padding": 0}),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
RETURN_TYPES = ("CONDITIONING","CONDITIONING","MODEL",)
|
|
|
RETURN_NAMES = ("positive", "negative", "model_opt")
|
|
|
FUNCTION = "apply_controlnet"
|
|
|
|
|
|
CATEGORY = "Adv-ControlNet ππ
π
π
"
|
|
|
|
|
|
def apply_controlnet(self, positive, negative, control_net, image, strength, start_percent, end_percent,
|
|
|
mask_optional: Tensor=None, model_optional: ModelPatcher=None, vae_optional=None,
|
|
|
timestep_kf: TimestepKeyframeGroup=None, latent_kf_override: LatentKeyframeGroup=None,
|
|
|
weights_override: ControlWeights=None, control_apply_to_uncond=False):
|
|
|
if strength == 0:
|
|
|
return (positive, negative, model_optional)
|
|
|
if model_optional:
|
|
|
model_optional = model_optional.clone()
|
|
|
|
|
|
control_hint = image.movedim(-1,1)
|
|
|
cnets = {}
|
|
|
|
|
|
out = []
|
|
|
for conditioning in [positive, negative]:
|
|
|
c = []
|
|
|
if conditioning is not None:
|
|
|
for t in conditioning:
|
|
|
d = t[1].copy()
|
|
|
|
|
|
prev_cnet = d.get('control', None)
|
|
|
if prev_cnet in cnets:
|
|
|
c_net = cnets[prev_cnet]
|
|
|
else:
|
|
|
|
|
|
c_net = convert_to_advanced(control_net.copy()).set_cond_hint(control_hint, strength, (start_percent, end_percent), vae_optional)
|
|
|
if is_advanced_controlnet(c_net):
|
|
|
|
|
|
c_net.disarm()
|
|
|
|
|
|
if c_net.require_model:
|
|
|
if not model_optional:
|
|
|
raise Exception(f"Type '{type(c_net).__name__}' requires model_optional input, but got None.")
|
|
|
c_net.patch_model(model=model_optional)
|
|
|
|
|
|
if c_net.require_vae:
|
|
|
|
|
|
if c_net.allow_condhint_latents and isinstance(control_hint, AbstractPreprocWrapper):
|
|
|
pass
|
|
|
elif not vae_optional:
|
|
|
|
|
|
if is_sd3_advanced_controlnet:
|
|
|
raise Exception(f"SD3 ControlNet requires vae_optional input, but got None.")
|
|
|
else:
|
|
|
raise Exception(f"Type '{type(c_net).__name__}' requires vae_optional input, but got None.")
|
|
|
|
|
|
if timestep_kf is not None:
|
|
|
c_net.set_timestep_keyframes(timestep_kf)
|
|
|
if latent_kf_override is not None:
|
|
|
c_net.latent_keyframe_override = latent_kf_override
|
|
|
if weights_override is not None:
|
|
|
c_net.weights_override = weights_override
|
|
|
|
|
|
c_net.verify_all_weights()
|
|
|
|
|
|
if mask_optional is not None:
|
|
|
mask_optional = mask_optional.clone()
|
|
|
|
|
|
if len(mask_optional.shape) < 3:
|
|
|
mask_optional = mask_optional.unsqueeze(0)
|
|
|
c_net.set_cond_hint_mask(mask_optional)
|
|
|
c_net.set_previous_controlnet(prev_cnet)
|
|
|
cnets[prev_cnet] = c_net
|
|
|
|
|
|
d['control'] = c_net
|
|
|
d['control_apply_to_uncond'] = control_apply_to_uncond
|
|
|
n = [t[0], d]
|
|
|
c.append(n)
|
|
|
out.append(c)
|
|
|
return (out[0], out[1], model_optional)
|
|
|
|
|
|
|
|
|
class AdvancedControlNetApplySingle:
|
|
|
@classmethod
|
|
|
def INPUT_TYPES(s):
|
|
|
return {
|
|
|
"required": {
|
|
|
"conditioning": ("CONDITIONING", ),
|
|
|
"control_net": ("CONTROL_NET", ),
|
|
|
"image": ("IMAGE", ),
|
|
|
"strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}),
|
|
|
"start_percent": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.001}),
|
|
|
"end_percent": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.001})
|
|
|
},
|
|
|
"optional": {
|
|
|
"mask_optional": ("MASK", ),
|
|
|
"timestep_kf": ("TIMESTEP_KEYFRAME", ),
|
|
|
"latent_kf_override": ("LATENT_KEYFRAME", ),
|
|
|
"weights_override": ("CONTROL_NET_WEIGHTS", ),
|
|
|
"model_optional": ("MODEL",),
|
|
|
"vae_optional": ("VAE",),
|
|
|
"autosize": ("ACNAUTOSIZE", {"padding": 0}),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
RETURN_TYPES = ("CONDITIONING","MODEL",)
|
|
|
RETURN_NAMES = ("CONDITIONING", "model_opt")
|
|
|
FUNCTION = "apply_controlnet"
|
|
|
|
|
|
CATEGORY = "Adv-ControlNet ππ
π
π
"
|
|
|
|
|
|
def apply_controlnet(self, conditioning, control_net, image, strength, start_percent, end_percent,
|
|
|
mask_optional: Tensor=None, model_optional: ModelPatcher=None, vae_optional=None,
|
|
|
timestep_kf: TimestepKeyframeGroup=None, latent_kf_override: LatentKeyframeGroup=None,
|
|
|
weights_override: ControlWeights=None):
|
|
|
values = AdvancedControlNetApply.apply_controlnet(self, positive=conditioning, negative=None, control_net=control_net, image=image,
|
|
|
strength=strength, start_percent=start_percent, end_percent=end_percent,
|
|
|
mask_optional=mask_optional, model_optional=model_optional, vae_optional=vae_optional,
|
|
|
timestep_kf=timestep_kf, latent_kf_override=latent_kf_override, weights_override=weights_override,
|
|
|
control_apply_to_uncond=True)
|
|
|
return (values[0], values[2])
|
|
|
|
|
|
|
|
|
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
|
|
|
|
"TimestepKeyframe": TimestepKeyframeNode,
|
|
|
"ACN_TimestepKeyframeInterpolation": TimestepKeyframeInterpolationNode,
|
|
|
"ACN_TimestepKeyframeFromStrengthList": TimestepKeyframeFromStrengthListNode,
|
|
|
"LatentKeyframe": LatentKeyframeNode,
|
|
|
"LatentKeyframeTiming": LatentKeyframeInterpolationNode,
|
|
|
"LatentKeyframeBatchedGroup": LatentKeyframeBatchedGroupNode,
|
|
|
"LatentKeyframeGroup": LatentKeyframeGroupNode,
|
|
|
|
|
|
"ACN_AdvancedControlNetApply": AdvancedControlNetApply,
|
|
|
"ACN_AdvancedControlNetApplySingle": AdvancedControlNetApplySingle,
|
|
|
|
|
|
"ControlNetLoaderAdvanced": ControlNetLoaderAdvanced,
|
|
|
"DiffControlNetLoaderAdvanced": DiffControlNetLoaderAdvanced,
|
|
|
|
|
|
"ACN_ScaledSoftControlNetWeights": ScaledSoftUniversalWeights,
|
|
|
"ScaledSoftMaskedUniversalWeights": ScaledSoftMaskedUniversalWeights,
|
|
|
"ACN_SoftControlNetWeightsSD15": SoftControlNetWeightsSD15,
|
|
|
"ACN_CustomControlNetWeightsSD15": CustomControlNetWeightsSD15,
|
|
|
"ACN_CustomControlNetWeightsFlux": CustomControlNetWeightsFlux,
|
|
|
"ACN_SoftT2IAdapterWeights": SoftT2IAdapterWeights,
|
|
|
"ACN_CustomT2IAdapterWeights": CustomT2IAdapterWeights,
|
|
|
"ACN_DefaultUniversalWeights": DefaultWeights,
|
|
|
|
|
|
"ACN_SparseCtrlRGBPreprocessor": RgbSparseCtrlPreprocessor,
|
|
|
"ACN_SparseCtrlLoaderAdvanced": SparseCtrlLoaderAdvanced,
|
|
|
"ACN_SparseCtrlMergedLoaderAdvanced": SparseCtrlMergedLoaderAdvanced,
|
|
|
"ACN_SparseCtrlIndexMethodNode": SparseIndexMethodNode,
|
|
|
"ACN_SparseCtrlSpreadMethodNode": SparseSpreadMethodNode,
|
|
|
"ACN_SparseCtrlWeightExtras": SparseWeightExtras,
|
|
|
|
|
|
"ACN_ControlNet++LoaderSingle": PlusPlusLoaderSingle,
|
|
|
"ACN_ControlNet++LoaderAdvanced": PlusPlusLoaderAdvanced,
|
|
|
"ACN_ControlNet++InputNode": PlusPlusInputNode,
|
|
|
|
|
|
"ACN_ReferencePreprocessor": ReferencePreprocessorNode,
|
|
|
"ACN_ReferenceControlNet": ReferenceControlNetNode,
|
|
|
"ACN_ReferenceControlNetFinetune": ReferenceControlFinetune,
|
|
|
|
|
|
|
|
|
|
|
|
"LoadImagesFromDirectory": LoadImagesFromDirectory,
|
|
|
"ScaledSoftControlNetWeights": ScaledSoftUniversalWeightsDeprecated,
|
|
|
"SoftControlNetWeights": SoftControlNetWeightsDeprecated,
|
|
|
"CustomControlNetWeights": CustomControlNetWeightsDeprecated,
|
|
|
"SoftT2IAdapterWeights": SoftT2IAdapterWeightsDeprecated,
|
|
|
"CustomT2IAdapterWeights": CustomT2IAdapterWeightsDeprecated,
|
|
|
}
|
|
|
|
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
|
|
|
|
"TimestepKeyframe": "Timestep Keyframe ππ
π
π
",
|
|
|
"ACN_TimestepKeyframeInterpolation": "Timestep Keyframe Interp. ππ
π
π
",
|
|
|
"ACN_TimestepKeyframeFromStrengthList": "Timestep Keyframe From List ππ
π
π
",
|
|
|
"LatentKeyframe": "Latent Keyframe ππ
π
π
",
|
|
|
"LatentKeyframeTiming": "Latent Keyframe Interp. ππ
π
π
",
|
|
|
"LatentKeyframeBatchedGroup": "Latent Keyframe From List ππ
π
π
",
|
|
|
"LatentKeyframeGroup": "Latent Keyframe Group ππ
π
π
",
|
|
|
|
|
|
"ACN_AdvancedControlNetApply": "Apply Advanced ControlNet ππ
π
π
",
|
|
|
"ACN_AdvancedControlNetApplySingle": "Apply Advanced ControlNet(1) ππ
π
π
",
|
|
|
|
|
|
"ControlNetLoaderAdvanced": "Load Advanced ControlNet Model ππ
π
π
",
|
|
|
"DiffControlNetLoaderAdvanced": "Load Advanced ControlNet Model (diff) ππ
π
π
",
|
|
|
|
|
|
"ACN_ScaledSoftControlNetWeights": "Scaled Soft Weights ππ
π
π
",
|
|
|
"ScaledSoftMaskedUniversalWeights": "Scaled Soft Masked Weights ππ
π
π
",
|
|
|
"ACN_SoftControlNetWeightsSD15": "ControlNet Soft Weights [SD1.5] ππ
π
π
",
|
|
|
"ACN_CustomControlNetWeightsSD15": "ControlNet Custom Weights [SD1.5] ππ
π
π
",
|
|
|
"ACN_CustomControlNetWeightsFlux": "ControlNet Custom Weights [Flux] ππ
π
π
",
|
|
|
"ACN_SoftT2IAdapterWeights": "T2IAdapter Soft Weights ππ
π
π
",
|
|
|
"ACN_CustomT2IAdapterWeights": "T2IAdapter Custom Weights ππ
π
π
",
|
|
|
"ACN_DefaultUniversalWeights": "Default Weights ππ
π
π
",
|
|
|
|
|
|
"ACN_SparseCtrlRGBPreprocessor": "RGB SparseCtrl ππ
π
π
",
|
|
|
"ACN_SparseCtrlLoaderAdvanced": "Load SparseCtrl Model ππ
π
π
",
|
|
|
"ACN_SparseCtrlMergedLoaderAdvanced": "π§ͺLoad Merged SparseCtrl Model ππ
π
π
",
|
|
|
"ACN_SparseCtrlIndexMethodNode": "SparseCtrl Index Method ππ
π
π
",
|
|
|
"ACN_SparseCtrlSpreadMethodNode": "SparseCtrl Spread Method ππ
π
π
",
|
|
|
"ACN_SparseCtrlWeightExtras": "SparseCtrl Weight Extras ππ
π
π
",
|
|
|
|
|
|
"ACN_ControlNet++LoaderSingle": "Load ControlNet++ Model (Single) ππ
π
π
",
|
|
|
"ACN_ControlNet++LoaderAdvanced": "Load ControlNet++ Model (Multi) ππ
π
π
",
|
|
|
"ACN_ControlNet++InputNode": "ControlNet++ Input ππ
π
π
",
|
|
|
|
|
|
"ACN_ReferencePreprocessor": "Reference Preproccessor ππ
π
π
",
|
|
|
"ACN_ReferenceControlNet": "Reference ControlNet ππ
π
π
",
|
|
|
"ACN_ReferenceControlNetFinetune": "Reference ControlNet (Finetune) ππ
π
π
",
|
|
|
|
|
|
|
|
|
|
|
|
"LoadImagesFromDirectory": "π«Load Images [DEPRECATED] ππ
π
π
",
|
|
|
"ScaledSoftControlNetWeights": "Scaled Soft Weights ππ
π
π
",
|
|
|
"SoftControlNetWeights": "ControlNet Soft Weights ππ
π
π
",
|
|
|
"CustomControlNetWeights": "ControlNet Custom Weights ππ
π
π
",
|
|
|
"SoftT2IAdapterWeights": "T2IAdapter Soft Weights ππ
π
π
",
|
|
|
"CustomT2IAdapterWeights": "T2IAdapter Custom Weights ππ
π
π
",
|
|
|
}
|
|
|
|