Skip to content

Commit

Permalink
commit QueueStop node
Browse files Browse the repository at this point in the history
  • Loading branch information
chflame163 committed Jun 27, 2024
1 parent 49004bb commit b352799
Show file tree
Hide file tree
Showing 9 changed files with 402 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ When this error has occurred, please check the network environment.
## Update
<font size="4">**If the dependency package error after updating, please reinstall the relevant dependency packages. </font><br />

* Commit [QueueStop](#QueueStop) node, used to terminate the queue operation.
* Optimize performance of the ```vitmate``` method for Ultra nodes when processing large-size image.
* [CropByMaskV2](#CropByMaskV2) add option to round the cutting size by multiples.
* Commit [CheckMask](#CheckMask) node, it detect whether the mask contains sufficient effective areas. Commit [HSVValue](#HSVValue) node, it convert color values to HSV values.
Expand Down Expand Up @@ -1216,6 +1217,14 @@ Node Options:
* case_2: case_2 string.
* case_3: case_3 string.

### <a id="table1">QueueStop</a>
![image](image/queue_stop_example.jpg)
Stop the current queue. When executed at this node, the queue will stop. The workflow diagram above illustrates that if the image is larger than 1Mega pixels, the queue will stop executing.

Node Options:
![image](image/queue_stop_node.jpg)
* mode: Stop mode. Currently, only stop mode can be selected.
* stop: If true, the queue will stop. If false, the queue will continue to execute.

### <a id="table1">PurgeVRAM</a>
![image](image/purge_vram_example.jpg)
Expand Down
10 changes: 10 additions & 0 deletions README_CN.MD
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ git clone https://github.com/chflame163/ComfyUI_LayerStyle.git
## 更新说明
<font size="4">**如果本插件更新后出现依赖包错误,请重新安装相关依赖包。

* 添加 [QueueStop](#QueueStop) 节点,用于停止队列。
* 优化Ultra节点的```vitmatte```方法在处理大尺寸图片时的性能。
* [CropByMaskV2](#CropByMaskV2) 增加裁切尺寸按倍数取整选项。
* 添加 [CheckMask](#CheckMask) 节点, 用于检测遮罩是否包含足够的有效区域。
Expand Down Expand Up @@ -1206,6 +1207,15 @@ BooleanOperator的升级版,增加了节点内数值输入,增加了大于
* case_2: case_2字符串。
* case_3: case_3字符串。

### <a id="table1">QueueStop</a>
![image](image/queue_stop_example.jpg)
停止当前的队列。执行到此节点时,队列将停止。上图工作流示意了如果图片大于1Mega像素时,队列将停止执行。

节点选项说明:
![image](image/queue_stop_node.jpg)
* mode: 停止模式。当前仅能选择stop一种模式。
* stop: 如果为True,队列将停止。如果为False,队列将继续执行。


### <a id="table1">PurgeVRAM</a>
![image](image/purge_vram_example.jpg)
Expand Down
Binary file added image/queue_stop_example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/queue_stop_node.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 30 additions & 2 deletions py/data_nodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .imagefunc import AnyType
from .imagefunc import extract_all_numbers_from_str
from .imagefunc import AnyType, log, extract_all_numbers_from_str

any = AnyType("*")

Expand Down Expand Up @@ -420,8 +419,36 @@ def switch_case(self, switch_condition, case_1, case_2, case_3, input_default, i

return (output,)

class QueueStopNode():
def __init__(self):
pass

@classmethod
def INPUT_TYPES(self):
mode_list = ["stop"]
return {
"required": {
"any": (any, ),
"mode": (mode_list,),
"stop": ("BOOLEAN", {"default": True}),
},
}

RETURN_TYPES = (any,)
RETURN_NAMES = ("any",)
FUNCTION = 'stop_node'
CATEGORY = '😺dzNodes/LayerUtility/SystemIO'

def stop_node(self, any, mode,stop):
if mode == "stop":
if stop:
log(f"Queue stopped, it was terminated by node.", "error")
from comfy.model_management import InterruptProcessingException
raise InterruptProcessingException()
return (any,)

NODE_CLASS_MAPPINGS = {
"LayerUtility: QueueStop": QueueStopNode,
"LayerUtility: SwitchCase": SwitchCaseNode,
"LayerUtility: If ": IfExecute,
"LayerUtility: StringCondition": StringCondition,
Expand All @@ -438,6 +465,7 @@ def switch_case(self, switch_condition, case_1, case_2, case_3, input_default, i
}

NODE_DISPLAY_NAME_MAPPINGS = {
"LayerUtility: QueueStop": "LayerUtility: Queue Stop",
"LayerUtility: SwitchCase": "LayerUtility: Switch Case",
"LayerUtility: If ": "LayerUtility: If",
"LayerUtility: StringCondition": "LayerUtility: String Condition",
Expand Down
10 changes: 8 additions & 2 deletions py/imagefunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,9 +1404,15 @@ def generate_VITMatte(image:Image, trimap:Image, local_files_only:bool=False) ->
trimap = trimap.convert('L')
max_size = 2048
width, height = image.size
ratio = width / height
target_width = math.sqrt(ratio * max_size * max_size)
target_height = target_width / ratio
target_width = int(target_width)
target_height = int(target_height)
log(f"vitmatte image size {width}x{height} too large, resize to {target_width}x{target_height} for processing.")
if width * height > max_size * max_size:
image = image.resize((max_size, max_size), Image.BILINEAR)
trimap = trimap.resize((max_size, max_size), Image.BILINEAR)
image = image.resize((target_width, target_height), Image.BILINEAR)
trimap = trimap.resize((target_width, target_height), Image.BILINEAR)
model_name = "hustvl/vitmatte-small-composition-1k"
vit_matte_model = load_VITMatte_model(model_name=model_name, local_files_only=local_files_only)
inputs = vit_matte_model.processor(images=image, trimaps=trimap, return_tensors="pt")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui_layerstyle"
description = "A set of nodes for ComfyUI it generate image like Adobe Photoshop's Layer Style. the Drop Shadow is first completed node, and follow-up work is in progress."
version = "1.0.9"
version = "1.0.10"
license = "MIT"
dependencies = ["numpy", "pillow", "torch", "matplotlib", "Scipy", "scikit_image", "opencv-contrib-python", "pymatting", "segment_anything", "timm", "addict", "yapf", "colour-science", "wget", "mediapipe", "loguru", "typer_config", "fastapi", "rich", "google-generativeai", "diffusers", "omegaconf", "tqdm", "transformers", "kornia", "image-reward", "ultralytics", "blend_modes", "blind-watermark", "qrcode", "pyzbar", "psd-tools"]

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy
numpy<2.0
pillow
torch
matplotlib
Expand All @@ -21,7 +21,7 @@ google-generativeai
diffusers
omegaconf
tqdm
transformers
transformers>=4.38.2
kornia
image-reward
ultralytics
Expand Down
Loading

0 comments on commit b352799

Please sign in to comment.