Added nodes to save and load latent data. Also started adding an incrementing frame counter node

This commit is contained in:
InconsolableCellist 2023-04-28 00:00:38 -06:00
parent e958dfdd4d
commit 3adb344fe3
2 changed files with 62 additions and 0 deletions

View File

@ -1,4 +1,8 @@
import os
import torch
import folder_paths
import numpy as np
def load_torch_file(ckpt, safe_load=False):
if ckpt.lower().endswith(".safetensors"):
@ -17,6 +21,16 @@ def load_torch_file(ckpt, safe_load=False):
sd = pl_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):
resblock_to_replace = {
"ln_1": "layer_norm1",

View File

@ -595,6 +595,35 @@ class LatentUpscale:
s["samples"] = comfy.utils.common_upscale(samples["samples"], width // 8, height // 8, upscale_method, crop)
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:
@classmethod
def INPUT_TYPES(s):
@ -1093,6 +1122,18 @@ class ImagePadForOutpaint:
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 = {
"KSampler": KSampler,
@ -1121,6 +1162,8 @@ NODE_CLASS_MAPPINGS = {
"LatentRotate": LatentRotate,
"LatentFlip": LatentFlip,
"LatentCrop": LatentCrop,
"SaveLatent": SaveLatent,
"LoadLatent": LoadLatent,
"LoraLoader": LoraLoader,
"CLIPLoader": CLIPLoader,
"CLIPVisionEncode": CLIPVisionEncode,
@ -1140,6 +1183,7 @@ NODE_CLASS_MAPPINGS = {
"CheckpointLoader": CheckpointLoader,
"DiffusersLoader": DiffusersLoader,
"FrameCounter": FrameCounter,
}
NODE_DISPLAY_NAME_MAPPINGS = {
@ -1176,6 +1220,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"EmptyLatentImage": "Empty Latent Image",
"LatentUpscale": "Upscale Latent",
"LatentComposite": "Latent Composite",
"SaveLatent": "Save Latent",
"LoadLatent": "Load Latent",
# Image
"SaveImage": "Save Image",
"PreviewImage": "Preview Image",
@ -1188,6 +1234,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
# _for_testing
"VAEDecodeTiled": "VAE Decode (Tiled)",
"VAEEncodeTiled": "VAE Encode (Tiled)",
# operations
"FrameCounter": "Frame Counter",
}
def load_custom_node(module_path):