mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2025-12-21 02:34:30 +08:00
Update nodes.py
This commit is contained in:
parent
8a8e4db2df
commit
248fcd0cd3
54
nodes.py
54
nodes.py
@ -44,7 +44,7 @@ class FloatConstant:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(s):
|
||||||
return {"required": {
|
return {"required": {
|
||||||
"value": ("FLOAT", {"default": 0.0, "min": -0xffffffffffffffff, "max": 0xffffffffffffffff, "step": 0.01}),
|
"value": ("FLOAT", {"default": 0.0, "min": -0xffffffffffffffff, "max": 0xffffffffffffffff, "step": 0.001}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2487,7 +2487,7 @@ class NormalizeLatent:
|
|||||||
|
|
||||||
RETURN_TYPES = ("LATENT",)
|
RETURN_TYPES = ("LATENT",)
|
||||||
FUNCTION = "normalize"
|
FUNCTION = "normalize"
|
||||||
CATEGORY = "KJNodes"
|
CATEGORY = "KJNodes/noise"
|
||||||
OUTPUT_NODE = True
|
OUTPUT_NODE = True
|
||||||
|
|
||||||
def normalize(self, latent):
|
def normalize(self, latent):
|
||||||
@ -2505,26 +2505,56 @@ class FlipSigmasAdjusted:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SIGMAS",)
|
RETURN_TYPES = ("SIGMAS",)
|
||||||
CATEGORY = "sampling/custom_sampling/sigmas"
|
CATEGORY = "KJNodes/noise"
|
||||||
|
|
||||||
FUNCTION = "get_sigmas_adjusted"
|
FUNCTION = "get_sigmas_adjusted"
|
||||||
|
|
||||||
def get_sigmas_adjusted(self, sigmas):
|
def get_sigmas_adjusted(self, sigmas):
|
||||||
print(sigmas)
|
|
||||||
sigmas = sigmas.flip(0)
|
sigmas = sigmas.flip(0)
|
||||||
if sigmas[0] == 0:
|
if sigmas[0] == 0:
|
||||||
sigmas[0] = 0.0001
|
sigmas[0] = 0.0001
|
||||||
adjusted_sigmas = sigmas.clone() # Create a copy to hold the adjusted values
|
adjusted_sigmas = sigmas.clone()
|
||||||
|
#offset sigma
|
||||||
# Apply the special adjustment: use the current index except for the first element
|
|
||||||
for i in range(1, len(sigmas)):
|
for i in range(1, len(sigmas)):
|
||||||
adjusted_sigmas[i] = sigmas[i - 1]
|
adjusted_sigmas[i] = sigmas[i - 1]
|
||||||
|
|
||||||
if adjusted_sigmas[0] == 0:
|
if adjusted_sigmas[0] == 0:
|
||||||
adjusted_sigmas[0] = 0.0001 # Apply the zero adjustment if necessary
|
adjusted_sigmas[0] = 0.0001
|
||||||
print(adjusted_sigmas)
|
|
||||||
return (adjusted_sigmas,)
|
return (adjusted_sigmas,)
|
||||||
|
|
||||||
|
class InjectNoiseToLatent:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {"required": {
|
||||||
|
"latents":("LATENT",),
|
||||||
|
"strength": ("FLOAT", {"default": 0.1, "min": 0.0, "max": 200.0, "step": 0.001}),
|
||||||
|
"noise": ("LATENT",),
|
||||||
|
"normalize": ("BOOLEAN", {"default": False}),
|
||||||
|
"average": ("BOOLEAN", {"default": False}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_TYPES = ("LATENT",)
|
||||||
|
FUNCTION = "injectnoise"
|
||||||
|
|
||||||
|
CATEGORY = "KJNodes/noise"
|
||||||
|
|
||||||
|
def injectnoise(self, latents, strength, noise, normalize, average):
|
||||||
|
samples = latents.copy()
|
||||||
|
if latents["samples"].shape != noise["samples"].shape:
|
||||||
|
raise ValueError("InjectNoiseToLatent: Latent and noise must have the same shape")
|
||||||
|
if average:
|
||||||
|
noised = (samples["samples"].clone() + noise["samples"].clone()) / 2
|
||||||
|
else:
|
||||||
|
noised = samples["samples"].clone() + noise["samples"].clone() * strength
|
||||||
|
if normalize:
|
||||||
|
noised = noised / noised.std()
|
||||||
|
|
||||||
|
samples["samples"] = noised
|
||||||
|
return (samples,)
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
"INTConstant": INTConstant,
|
"INTConstant": INTConstant,
|
||||||
"FloatConstant": FloatConstant,
|
"FloatConstant": FloatConstant,
|
||||||
@ -2571,7 +2601,8 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
"ImageGrabPIL": ImageGrabPIL,
|
"ImageGrabPIL": ImageGrabPIL,
|
||||||
"DummyLatentOut": DummyLatentOut,
|
"DummyLatentOut": DummyLatentOut,
|
||||||
"NormalizeLatent": NormalizeLatent,
|
"NormalizeLatent": NormalizeLatent,
|
||||||
"FlipSigmasAdjusted": FlipSigmasAdjusted
|
"FlipSigmasAdjusted": FlipSigmasAdjusted,
|
||||||
|
"InjectNoiseToLatent": InjectNoiseToLatent
|
||||||
}
|
}
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||||
"INTConstant": "INT Constant",
|
"INTConstant": "INT Constant",
|
||||||
@ -2618,6 +2649,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
|||||||
"ImageGrabPIL": "ImageGrabPIL",
|
"ImageGrabPIL": "ImageGrabPIL",
|
||||||
"DummyLatentOut": "DummyLatentOut",
|
"DummyLatentOut": "DummyLatentOut",
|
||||||
"NormalizeLatent": "NormalizeLatent",
|
"NormalizeLatent": "NormalizeLatent",
|
||||||
"FlipSigmasAdjusted": "FlipSigmasAdjusted"
|
"FlipSigmasAdjusted": "FlipSigmasAdjusted",
|
||||||
|
"InjectNoiseToLatent": "InjectNoiseToLatent"
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user