mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-13 23:12:35 +08:00
Added nodes to save and load latent data. Also started adding an incrementing frame counter node
This commit is contained in:
parent
e958dfdd4d
commit
3adb344fe3
@ -1,4 +1,8 @@
|
|||||||
|
import os
|
||||||
import torch
|
import torch
|
||||||
|
import folder_paths
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
def load_torch_file(ckpt, safe_load=False):
|
def load_torch_file(ckpt, safe_load=False):
|
||||||
if ckpt.lower().endswith(".safetensors"):
|
if ckpt.lower().endswith(".safetensors"):
|
||||||
@ -17,6 +21,16 @@ def load_torch_file(ckpt, safe_load=False):
|
|||||||
sd = pl_sd
|
sd = pl_sd
|
||||||
return sd
|
return sd
|
||||||
|
|
||||||
|
|
||||||
|
def save_latent(samples, filename_prefix):
|
||||||
|
filename = os.path.join(folder_paths.get_output_directory(), (filename_prefix + "_latent.npy"))
|
||||||
|
np.save(filename, samples)
|
||||||
|
|
||||||
|
|
||||||
|
def load_latent(filename):
|
||||||
|
filename = os.path.join(folder_paths.get_output_directory(), filename)
|
||||||
|
return torch.from_numpy(np.load(filename))
|
||||||
|
|
||||||
def transformers_convert(sd, prefix_from, prefix_to, number):
|
def transformers_convert(sd, prefix_from, prefix_to, number):
|
||||||
resblock_to_replace = {
|
resblock_to_replace = {
|
||||||
"ln_1": "layer_norm1",
|
"ln_1": "layer_norm1",
|
||||||
|
|||||||
48
nodes.py
48
nodes.py
@ -595,6 +595,35 @@ class LatentUpscale:
|
|||||||
s["samples"] = comfy.utils.common_upscale(samples["samples"], width // 8, height // 8, upscale_method, crop)
|
s["samples"] = comfy.utils.common_upscale(samples["samples"], width // 8, height // 8, upscale_method, crop)
|
||||||
return (s,)
|
return (s,)
|
||||||
|
|
||||||
|
class SaveLatent:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {"required": { "samples": ("LATENT",),
|
||||||
|
"filename_prefix": ("STRING", {"default": "ComfyUI"})}}
|
||||||
|
RETURN_TYPES = ("LATENT",)
|
||||||
|
FUNCTION = "save"
|
||||||
|
|
||||||
|
CATEGORY = "latent"
|
||||||
|
|
||||||
|
def save(self, samples, filename_prefix):
|
||||||
|
s = samples.copy()
|
||||||
|
comfy.utils.save_latent(samples["samples"], filename_prefix)
|
||||||
|
return (samples,)
|
||||||
|
|
||||||
|
class LoadLatent:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {"required": { "filename": ("STRING", {"default": "ComfyUI_latent.npy"})}}
|
||||||
|
|
||||||
|
RETURN_TYPES = ("LATENT",)
|
||||||
|
FUNCTION = "load"
|
||||||
|
|
||||||
|
CATEGORY = "latent"
|
||||||
|
|
||||||
|
def load(self, filename):
|
||||||
|
derp = ({"samples": comfy.utils.load_latent(filename)},)
|
||||||
|
return derp
|
||||||
|
|
||||||
class LatentRotate:
|
class LatentRotate:
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(s):
|
||||||
@ -1093,6 +1122,18 @@ class ImagePadForOutpaint:
|
|||||||
|
|
||||||
return (new_image, mask)
|
return (new_image, mask)
|
||||||
|
|
||||||
|
class FrameCounter:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {"required": { "frame": ("INT", {"default": 0})}}
|
||||||
|
|
||||||
|
RETURN_TYPES = ("INT",)
|
||||||
|
FUNCTION = "frame_counter"
|
||||||
|
|
||||||
|
CATEGORY = "operations"
|
||||||
|
|
||||||
|
def frame_counter(self, frame):
|
||||||
|
return (frame,)
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
"KSampler": KSampler,
|
"KSampler": KSampler,
|
||||||
@ -1121,6 +1162,8 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
"LatentRotate": LatentRotate,
|
"LatentRotate": LatentRotate,
|
||||||
"LatentFlip": LatentFlip,
|
"LatentFlip": LatentFlip,
|
||||||
"LatentCrop": LatentCrop,
|
"LatentCrop": LatentCrop,
|
||||||
|
"SaveLatent": SaveLatent,
|
||||||
|
"LoadLatent": LoadLatent,
|
||||||
"LoraLoader": LoraLoader,
|
"LoraLoader": LoraLoader,
|
||||||
"CLIPLoader": CLIPLoader,
|
"CLIPLoader": CLIPLoader,
|
||||||
"CLIPVisionEncode": CLIPVisionEncode,
|
"CLIPVisionEncode": CLIPVisionEncode,
|
||||||
@ -1140,6 +1183,7 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
|
|
||||||
"CheckpointLoader": CheckpointLoader,
|
"CheckpointLoader": CheckpointLoader,
|
||||||
"DiffusersLoader": DiffusersLoader,
|
"DiffusersLoader": DiffusersLoader,
|
||||||
|
"FrameCounter": FrameCounter,
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||||
@ -1176,6 +1220,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
|||||||
"EmptyLatentImage": "Empty Latent Image",
|
"EmptyLatentImage": "Empty Latent Image",
|
||||||
"LatentUpscale": "Upscale Latent",
|
"LatentUpscale": "Upscale Latent",
|
||||||
"LatentComposite": "Latent Composite",
|
"LatentComposite": "Latent Composite",
|
||||||
|
"SaveLatent": "Save Latent",
|
||||||
|
"LoadLatent": "Load Latent",
|
||||||
# Image
|
# Image
|
||||||
"SaveImage": "Save Image",
|
"SaveImage": "Save Image",
|
||||||
"PreviewImage": "Preview Image",
|
"PreviewImage": "Preview Image",
|
||||||
@ -1188,6 +1234,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
|||||||
# _for_testing
|
# _for_testing
|
||||||
"VAEDecodeTiled": "VAE Decode (Tiled)",
|
"VAEDecodeTiled": "VAE Decode (Tiled)",
|
||||||
"VAEEncodeTiled": "VAE Encode (Tiled)",
|
"VAEEncodeTiled": "VAE Encode (Tiled)",
|
||||||
|
# operations
|
||||||
|
"FrameCounter": "Frame Counter",
|
||||||
}
|
}
|
||||||
|
|
||||||
def load_custom_node(module_path):
|
def load_custom_node(module_path):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user