Rename to sampler selection method

This commit is contained in:
nkchocoai
2024-02-17 23:08:39 +09:00
parent a72209e266
commit 92ff5c907f
7 changed files with 144 additions and 106 deletions
+53 -17
View File
@@ -1,6 +1,6 @@
{
"last_node_id": 10,
"last_link_id": 16,
"last_node_id": 11,
"last_link_id": 17,
"nodes": [
{
"id": 1,
@@ -123,7 +123,7 @@
"1": 318
},
"flags": {},
"order": 6,
"order": 7,
"mode": 0,
"inputs": [
{
@@ -266,7 +266,7 @@
"1": 318
},
"flags": {},
"order": 7,
"order": 8,
"mode": 0,
"inputs": [
{
@@ -292,10 +292,10 @@
1050,
266
],
"size": [
323.57684936523447,
422
],
"size": {
"0": 323.57684326171875,
"1": 422
},
"flags": {},
"order": 3,
"mode": 0,
@@ -401,10 +401,10 @@
603,
89
],
"size": [
339.13239746093757,
350
],
"size": {
"0": 339.13238525390625,
"1": 350
},
"flags": {},
"order": 2,
"mode": 0,
@@ -477,7 +477,8 @@
"name": "IMAGE",
"type": "IMAGE",
"links": [
14
14,
17
],
"shape": 3
}
@@ -506,10 +507,10 @@
603,
720
],
"size": [
312.24350280761723,
334
],
"size": {
"0": 312.2434997558594,
"1": 334
},
"flags": {},
"order": 4,
"mode": 0,
@@ -582,6 +583,33 @@
],
"bgcolor": "#553355",
"shape": 1
},
{
"id": 11,
"type": "SaveImage",
"pos": [
1077,
-79
],
"size": {
"0": 263.2173767089844,
"1": 273.5193786621094
},
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 17,
"slot_index": 0
}
],
"properties": {},
"widgets_values": [
"eff-without-meta"
]
}
],
"links": [
@@ -712,6 +740,14 @@
10,
0,
"IMAGE"
],
[
17,
3,
5,
11,
0,
"IMAGE"
]
],
"groups": [],
Binary file not shown.

Before

Width:  |  Height:  |  Size: 646 KiB

After

Width:  |  Height:  |  Size: 775 KiB

+78 -78
View File
@@ -177,32 +177,6 @@
"Node name for S&R": "PreviewImage"
}
},
{
"id": 14,
"type": "SaveImage",
"pos": [
1740,
570
],
"size": {
"0": 263.2173767089844,
"1": 273.5193786621094
},
"flags": {},
"order": 19,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 19
}
],
"properties": {},
"widgets_values": [
"ComfyUI-without-meta"
]
},
{
"id": 11,
"type": "LatentUpscaleBy",
@@ -250,10 +224,10 @@
21,
204
],
"size": [
210,
58
],
"size": {
"0": 210,
"1": 58
},
"flags": {},
"order": 0,
"mode": 0,
@@ -281,10 +255,10 @@
23,
313
],
"size": [
210,
93.83313587283294
],
"size": {
"0": 210,
"1": 93.83313751220703
},
"flags": {},
"order": 1,
"mode": 0,
@@ -313,10 +287,10 @@
31,
614
],
"size": [
306.86521218039763,
58
],
"size": {
"0": 306.8652038574219,
"1": 58
},
"flags": {},
"order": 2,
"mode": 0,
@@ -521,10 +495,10 @@
35,
733
],
"size": [
270.42571113523366,
58
],
"size": {
"0": 270.42572021484375,
"1": 58
},
"flags": {},
"order": 4,
"mode": 0,
@@ -672,9 +646,9 @@
}
],
"properties": {
"Node name for S&R": "Prompts Everywhere",
"group_restricted": false,
"color_restricted": false
"color_restricted": false,
"Node name for S&R": "Prompts Everywhere"
}
},
{
@@ -716,7 +690,7 @@
161
],
"size": {
"0": 315,
"0": 319.20001220703125,
"1": 122
},
"flags": {},
@@ -784,37 +758,6 @@
"upper body, v sign, smile, looking at viewer"
]
},
{
"id": 9,
"type": "SaveImageWithMetaData",
"pos": [
2029,
572
],
"size": [
307.9046630859375,
317.66292780095876
],
"flags": {},
"order": 18,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 11,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "SaveImageWithMetaData"
},
"widgets_values": [
"ComfyUI-with-meta-far",
"Farthest",
0
]
},
{
"id": 27,
"type": "Anything Everywhere3",
@@ -853,10 +796,67 @@
}
],
"properties": {
"Node name for S&R": "Anything Everywhere3",
"group_restricted": false,
"color_restricted": false
"color_restricted": false,
"Node name for S&R": "Anything Everywhere3"
}
},
{
"id": 9,
"type": "SaveImageWithMetaData",
"pos": [
2029,
572
],
"size": [
307.9046630859375,
318
],
"flags": {},
"order": 18,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 11,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "SaveImageWithMetaData"
},
"widgets_values": [
"ComfyUI-with-meta-far",
"Farthest",
0
]
},
{
"id": 14,
"type": "SaveImage",
"pos": [
1740,
570
],
"size": {
"0": 263.2173767089844,
"1": 273.5193786621094
},
"flags": {},
"order": 19,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 19
}
],
"properties": {},
"widgets_values": [
"ComfyUI-without-meta"
]
}
],
"links": [
Binary file not shown.

Before

Width:  |  Height:  |  Size: 668 KiB

After

Width:  |  Height:  |  Size: 668 KiB

+1 -1
View File
@@ -1 +1 @@
SAMPLER_FIND_METHOD = ["Farthest", "Nearest", "By node ID"]
SAMPLER_SELECTION_METHOD = ["Farthest", "Nearest", "By node ID"]
+8 -6
View File
@@ -14,7 +14,7 @@ from ..capture import Capture
from .. import hook
from ..trace import Trace
from ..defs.combo import SAMPLER_FIND_METHOD
from ..defs.combo import SAMPLER_SELECTION_METHOD
# refer. https://github.com/comfyanonymous/ComfyUI/blob/38b7ac6e269e6ecc5bdd6fefdfb2fb1185b09c9d/nodes.py#L1411
@@ -31,7 +31,7 @@ class SaveImageWithMetaData(BaseNode):
"required": {
"images": ("IMAGE",),
"filename_prefix": ("STRING", {"default": "ComfyUI"}),
"sampler_find_method": (SAMPLER_FIND_METHOD,),
"sampler_selection_method": (SAMPLER_SELECTION_METHOD,),
"sampler_find_node_id": (
"INT",
{"default": 0, "min": 0, "max": 999999999, "step": 1},
@@ -49,7 +49,7 @@ class SaveImageWithMetaData(BaseNode):
self,
images,
filename_prefix="ComfyUI",
sampler_find_method=SAMPLER_FIND_METHOD[0],
sampler_selection_method=SAMPLER_SELECTION_METHOD[0],
sampler_find_node_id=0,
prompt=None,
extra_pnginfo=None,
@@ -68,7 +68,9 @@ class SaveImageWithMetaData(BaseNode):
i = 255.0 * image.cpu().numpy()
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
pnginfo_dict = self.gen_pnginfo(sampler_find_method, sampler_find_node_id)
pnginfo_dict = self.gen_pnginfo(
sampler_selection_method, sampler_find_node_id
)
if len(images) >= 2:
pnginfo_dict["Batch index"] = index
pnginfo_dict["Batch size"] = len(images)
@@ -100,7 +102,7 @@ class SaveImageWithMetaData(BaseNode):
return {"ui": {"images": results}}
@classmethod
def gen_pnginfo(cls, sampler_find_method, sampler_find_node_id):
def gen_pnginfo(cls, sampler_selection_method, sampler_find_node_id):
# get all node inputs
inputs = Capture.get_inputs()
@@ -109,7 +111,7 @@ class SaveImageWithMetaData(BaseNode):
hook.current_node_id, hook.current_prompt
)
sampler_node_id = Trace.find_sampler_node_id(
trace_tree_from_this_node, sampler_find_method, sampler_find_node_id
trace_tree_from_this_node, sampler_selection_method, sampler_find_node_id
)
# get inputs before sampler node
+4 -4
View File
@@ -3,7 +3,7 @@ import json
from collections import deque
from .defs.samplers import SAMPLERS
from .defs.combo import SAMPLER_FIND_METHOD
from .defs.combo import SAMPLER_SELECTION_METHOD
class Trace:
@@ -25,8 +25,8 @@ class Trace:
return trace_tree
@classmethod
def find_sampler_node_id(cls, trace_tree, sampler_find_method, node_id):
if sampler_find_method == SAMPLER_FIND_METHOD[2]:
def find_sampler_node_id(cls, trace_tree, sampler_selection_method, node_id):
if sampler_selection_method == SAMPLER_SELECTION_METHOD[2]:
node_id = str(node_id)
_, class_type = trace_tree.get(node_id, (-1, None))
if class_type in SAMPLERS.keys():
@@ -36,7 +36,7 @@ class Trace:
sorted_by_distance_trace_tree = sorted(
[(k, v[0], v[1]) for k, v in trace_tree.items()],
key=lambda x: x[1],
reverse=(sampler_find_method == SAMPLER_FIND_METHOD[0]),
reverse=(sampler_selection_method == SAMPLER_SELECTION_METHOD[0]),
)
for nid, _, class_type in sorted_by_distance_trace_tree:
if class_type in SAMPLERS.keys():