From e64e8f6a34955805cd69e8d4ebbcc0da23e2a111 Mon Sep 17 00:00:00 2001 From: logtd Date: Tue, 10 Sep 2024 20:46:19 -0600 Subject: [PATCH] update --- __init__.py | 3 - .../dilight_example_workflow.json | 1097 +++++++++++++++++ nodes/load_dilight_image_node.py | 72 -- 3 files changed, 1097 insertions(+), 75 deletions(-) create mode 100644 example_workflows/dilight_example_workflow.json delete mode 100644 nodes/load_dilight_image_node.py diff --git a/__init__.py b/__init__.py index 2f0a6ad..01296b9 100644 --- a/__init__.py +++ b/__init__.py @@ -1,16 +1,13 @@ from .nodes.load_dilight_controlnet_node import LoadDiLightControlNetNode from .nodes.prepare_dilight_cond_node import PrepareDiLightCondNode -from .nodes.load_dilight_image_node import LoadDiLightImageNode NODE_CLASS_MAPPINGS = { "LoadDiLightControlNet": LoadDiLightControlNetNode, "PrepareDiLightCond": PrepareDiLightCondNode, - "LoadDiLightImage": LoadDiLightImageNode, } NODE_DISPLAY_NAME_MAPPINGS = { "LoadDiLightControlNet": "Load DiLight ControlNet", "PrepareDiLightCond": "Prepare DiLight CN Image", - "LoadDiLightImage": "Load DiLight Image", } diff --git a/example_workflows/dilight_example_workflow.json b/example_workflows/dilight_example_workflow.json new file mode 100644 index 0000000..9c9f63a --- /dev/null +++ b/example_workflows/dilight_example_workflow.json @@ -0,0 +1,1097 @@ +{ + "last_node_id": 45, + "last_link_id": 51, + "nodes": [ + { + "id": 3, + "type": "KSampler", + "pos": { + "0": 863, + "1": 186 + }, + "size": { + "0": 210, + "1": 262 + }, + "flags": {}, + "order": 20, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 13 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 18 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 19 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 2 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 7 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "KSampler" + }, + "widgets_values": [ + 0, + "fixed", + 20, + 3, + "uni_pc", + "normal", + 1 + ] + }, + { + "id": 10, + "type": "UNETLoader", + "pos": { + "0": 866, + "1": 492 + }, + "size": { + "0": 210, + "1": 82 + }, + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 13 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "UNETLoader" + }, + "widgets_values": [ + "sd2.safetensors", + "default" + ] + }, + { + "id": 5, + "type": "EmptyLatentImage", + "pos": { + "0": 863, + "1": 626 + }, + "size": { + "0": 210, + "1": 106 + }, + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 2 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "EmptyLatentImage" + }, + "widgets_values": [ + 512, + 512, + 1 + ] + }, + { + "id": 30, + "type": "LoadImage", + "pos": { + "0": -600, + "1": 0 + }, + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 38, + 44 + ], + "slot_index": 0, + "shape": 3 + }, + { + "name": "MASK", + "type": "MASK", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "futuristic_soldier.png", + "image" + ] + }, + { + "id": 8, + "type": "VAEDecode", + "pos": { + "0": 1114, + "1": 185 + }, + "size": { + "0": 210, + "1": 46 + }, + "flags": {}, + "order": 21, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 7 + }, + { + "name": "vae", + "type": "VAE", + "link": 10 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 45 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + } + }, + { + "id": 7, + "type": "CLIPTextEncode", + "pos": { + "0": 326, + "1": 318 + }, + "size": { + "0": 210, + "1": 174.67169189453125 + }, + "flags": { + "collapsed": true + }, + "order": 15, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 11 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 16 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "" + ] + }, + { + "id": 29, + "type": "PrepareDiLightCond", + "pos": { + "0": 324, + "1": 375 + }, + "size": { + "0": 201.60000610351562, + "1": 126 + }, + "flags": {}, + "order": 18, + "mode": 0, + "inputs": [ + { + "name": "mask", + "type": "MASK", + "link": 42 + }, + { + "name": "image", + "type": "IMAGE", + "link": 38 + }, + { + "name": "diff_image", + "type": "IMAGE", + "link": 47 + }, + { + "name": "ggx5", + "type": "IMAGE", + "link": 49 + }, + { + "name": "ggx13", + "type": "IMAGE", + "link": 50 + }, + { + "name": "ggx34", + "type": "IMAGE", + "link": 51 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 37 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "PrepareDiLightCond" + } + }, + { + "id": 35, + "type": "ImageConcanate", + "pos": { + "0": 1111, + "1": 27 + }, + "size": { + "0": 210, + "1": 102 + }, + "flags": {}, + "order": 22, + "mode": 0, + "inputs": [ + { + "name": "image1", + "type": "IMAGE", + "link": 44 + }, + { + "name": "image2", + "type": "IMAGE", + "link": 45 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 46 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "ImageConcanate" + }, + "widgets_values": [ + "right", + false + ] + }, + { + "id": 11, + "type": "CLIPLoader", + "pos": { + "0": 62, + "1": 108 + }, + "size": { + "0": 210, + "1": 82 + }, + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 11, + 12 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CLIPLoader" + }, + "widgets_values": [ + "open_clip_pytorch_model.bin", + "stable_diffusion" + ] + }, + { + "id": 37, + "type": "Note", + "pos": { + "0": -572, + "1": -169 + }, + "size": { + "0": 278.365478515625, + "1": 108.98002624511719 + }, + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [], + "outputs": [], + "properties": {}, + "widgets_values": [ + "Images taken from:\nhttps://github.com/iamNCJ/DiLightNet/tree/main/examples/input" + ], + "color": "#432", + "bgcolor": "#653" + }, + { + "id": 34, + "type": "LoadDiLightControlNet", + "pos": { + "0": 593, + "1": 416 + }, + "size": [ + 210, + 58 + ], + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "CONTROL_NET", + "type": "CONTROL_NET", + "links": [ + 43 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "LoadDiLightControlNet" + }, + "widgets_values": [ + "dilight.safetensors" + ] + }, + { + "id": 13, + "type": "PreviewImage", + "pos": { + "0": 1355, + "1": 22 + }, + "size": { + "0": 850.4505615234375, + "1": 461.093505859375 + }, + "flags": {}, + "order": 23, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 46 + } + ], + "outputs": [], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 15, + "type": "ControlNetApplyAdvanced", + "pos": { + "0": 589, + "1": 204 + }, + "size": { + "0": 226.8000030517578, + "1": 166 + }, + "flags": {}, + "order": 19, + "mode": 0, + "inputs": [ + { + "name": "positive", + "type": "CONDITIONING", + "link": 17 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 16 + }, + { + "name": "control_net", + "type": "CONTROL_NET", + "link": 43 + }, + { + "name": "image", + "type": "IMAGE", + "link": 37 + } + ], + "outputs": [ + { + "name": "positive", + "type": "CONDITIONING", + "links": [ + 18 + ], + "slot_index": 0, + "shape": 3 + }, + { + "name": "negative", + "type": "CONDITIONING", + "links": [ + 19 + ], + "slot_index": 1, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "ControlNetApplyAdvanced" + }, + "widgets_values": [ + 1, + 0, + 1 + ] + }, + { + "id": 39, + "type": "LoadImage", + "pos": { + "0": -601, + "1": 359 + }, + "size": [ + 315, + 314 + ], + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 47 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": [ + 48 + ], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "futuristic_soldier_diffuse.png", + "image" + ] + }, + { + "id": 40, + "type": "LoadImage", + "pos": { + "0": -607, + "1": 726 + }, + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 49 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": [], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "futuristic_soldier_ggx0.05.png", + "image" + ] + }, + { + "id": 41, + "type": "LoadImage", + "pos": { + "0": -612, + "1": 1086 + }, + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 50 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": [], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "futuristic_soldier_ggx0.13.png", + "image" + ] + }, + { + "id": 42, + "type": "LoadImage", + "pos": { + "0": -616, + "1": 1448 + }, + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 51 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": [], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "futuristic_soldier_ggx0.34.png", + "image" + ] + }, + { + "id": 32, + "type": "InvertMask", + "pos": { + "0": -203, + "1": 466 + }, + "size": [ + 140, + 26 + ], + "flags": {}, + "order": 17, + "mode": 0, + "inputs": [ + { + "name": "mask", + "type": "MASK", + "link": 48 + } + ], + "outputs": [ + { + "name": "MASK", + "type": "MASK", + "links": [ + 42 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "InvertMask" + } + }, + { + "id": 38, + "type": "Note", + "pos": { + "0": 572, + "1": 545 + }, + "size": { + "0": 241.92127990722656, + "1": 115.61095428466797 + }, + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [], + "outputs": [], + "properties": {}, + "widgets_values": [ + "ControlNet from:\nhttps://huggingface.co/dilightnet/DiLightNet/blob/main/diffusion_pytorch_model.safetensors" + ], + "color": "#432", + "bgcolor": "#653" + }, + { + "id": 12, + "type": "VAELoader", + "pos": { + "0": 1115, + "1": 276 + }, + "size": [ + 210, + 58 + ], + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "VAE", + "type": "VAE", + "links": [ + 10 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "VAELoader" + }, + "widgets_values": [ + "vae-ft-mse-840000-ema-pruned.safetensors" + ] + }, + { + "id": 36, + "type": "Note", + "pos": { + "0": 47, + "1": -125 + }, + "size": { + "0": 210, + "1": 78.14202117919922 + }, + "flags": {}, + "order": 12, + "mode": 0, + "inputs": [], + "outputs": [], + "properties": {}, + "widgets_values": [ + "CLIP: This is the SD2 Clip\n\nhttps://huggingface.co/stabilityai/stable-diffusion-2" + ], + "color": "#432", + "bgcolor": "#653" + }, + { + "id": 45, + "type": "Note", + "pos": { + "0": 864, + "1": 784 + }, + "size": [ + 210, + 78.14202117919922 + ], + "flags": {}, + "order": 13, + "mode": 0, + "inputs": [], + "outputs": [], + "properties": {}, + "widgets_values": [ + "Model: This is SD2\n\nhttps://huggingface.co/stabilityai/stable-diffusion-2" + ], + "color": "#432", + "bgcolor": "#653" + }, + { + "id": 44, + "type": "Note", + "pos": { + "0": 301, + "1": -135 + }, + "size": [ + 237.05928259357813, + 90.14724057834616 + ], + "flags": {}, + "order": 14, + "mode": 0, + "inputs": [], + "outputs": [], + "properties": {}, + "widgets_values": [ + "Prompt: \"specular\" and \"metallic\" are special words" + ], + "color": "#432", + "bgcolor": "#653" + }, + { + "id": 6, + "type": "CLIPTextEncode", + "pos": { + "0": 321, + "1": 107 + }, + "size": { + "0": 210, + "1": 152.078857421875 + }, + "flags": {}, + "order": 16, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 12 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 17 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "futuristic soldier with advanced armor weaponry and helmet " + ] + } + ], + "links": [ + [ + 2, + 5, + 0, + 3, + 3, + "LATENT" + ], + [ + 7, + 3, + 0, + 8, + 0, + "LATENT" + ], + [ + 10, + 12, + 0, + 8, + 1, + "VAE" + ], + [ + 11, + 11, + 0, + 7, + 0, + "CLIP" + ], + [ + 12, + 11, + 0, + 6, + 0, + "CLIP" + ], + [ + 13, + 10, + 0, + 3, + 0, + "MODEL" + ], + [ + 16, + 7, + 0, + 15, + 1, + "CONDITIONING" + ], + [ + 17, + 6, + 0, + 15, + 0, + "CONDITIONING" + ], + [ + 18, + 15, + 0, + 3, + 1, + "CONDITIONING" + ], + [ + 19, + 15, + 1, + 3, + 2, + "CONDITIONING" + ], + [ + 37, + 29, + 0, + 15, + 3, + "IMAGE" + ], + [ + 38, + 30, + 0, + 29, + 1, + "IMAGE" + ], + [ + 42, + 32, + 0, + 29, + 0, + "MASK" + ], + [ + 43, + 34, + 0, + 15, + 2, + "CONTROL_NET" + ], + [ + 44, + 30, + 0, + 35, + 0, + "IMAGE" + ], + [ + 45, + 8, + 0, + 35, + 1, + "IMAGE" + ], + [ + 46, + 35, + 0, + 13, + 0, + "IMAGE" + ], + [ + 47, + 39, + 0, + 29, + 2, + "IMAGE" + ], + [ + 48, + 39, + 1, + 32, + 0, + "MASK" + ], + [ + 49, + 40, + 0, + 29, + 3, + "IMAGE" + ], + [ + 50, + 41, + 0, + 29, + 4, + "IMAGE" + ], + [ + 51, + 42, + 0, + 29, + 5, + "IMAGE" + ] + ], + "groups": [], + "config": {}, + "extra": { + "ds": { + "scale": 0.42409761837248483, + "offset": [ + 624.2141525153642, + 570.4821303384275 + ] + } + }, + "version": 0.4 +} \ No newline at end of file diff --git a/nodes/load_dilight_image_node.py b/nodes/load_dilight_image_node.py deleted file mode 100644 index 1eec180..0000000 --- a/nodes/load_dilight_image_node.py +++ /dev/null @@ -1,72 +0,0 @@ -import os - -import torch -import numpy as np -from PIL import Image, ImageOps, ImageSequence - -import folder_paths -import node_helpers - - -class LoadDiLightImageNode: - @classmethod - def INPUT_TYPES(s): - input_dir = folder_paths.get_input_directory() - files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))] - return {"required": - {"image": (sorted(files), {"image_upload": True})}, - } - - CATEGORY = "image" - - RETURN_TYPES = ("IMAGE", "MASK") - FUNCTION = "load_image" - def load_image(self, image): - image_path = folder_paths.get_annotated_filepath(image) - - img = node_helpers.pillow(Image.open, image_path) - - output_images = [] - output_masks = [] - w, h = None, None - - excluded_formats = ['MPO'] - - for i in ImageSequence.Iterator(img): - i = node_helpers.pillow(ImageOps.exif_transpose, i) - - if i.mode == 'I': - i = i.point(lambda i: i * (1 / 255)) - if 'A' in i.getbands(): - image = i.convert("RGBA") - else: - image = i.convert("RGB") - - if len(output_images) == 0: - w = image.size[0] - h = image.size[1] - - if image.size[0] != w or image.size[1] != h: - continue - - image = np.array(image).astype(np.float32) / 255.0 - image = torch.from_numpy(image)[None,] - if 'A' in i.getbands(): - mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0 - mask = 1. - torch.from_numpy(mask) - else: - mask = torch.zeros((64,64), dtype=torch.float32, device="cpu") - output_images.append(image) - output_masks.append(mask.unsqueeze(0)) - - if len(output_images) > 1 and img.format not in excluded_formats: - output_image = torch.cat(output_images, dim=0) - output_mask = torch.cat(output_masks, dim=0) - else: - output_image = output_images[0] - output_mask = output_masks[0] - - if output_image.shape[-1] == 4: - output_image = output_image[..., :3] * output_image[..., 3:] - - return (output_image, output_mask)