Compare commits

...
7 Commits
7 changed files with 140 additions and 19 deletions
+21
View File
@@ -0,0 +1,21 @@
name: Publish to Comfy registry
on:
workflow_dispatch:
push:
branches:
- main
paths:
- "pyproject.toml"
jobs:
publish-node:
name: Publish Custom Node to registry
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Publish Custom Node
uses: Comfy-Org/publish-node-action@main
with:
## Add your own personal access token to your Github Repository secrets and reference it here.
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
+16
View File
@@ -15,6 +15,22 @@ This node pack provides nodes that complement the [ComfyUI Impact Pack](https://
* civitai/[adetailer](https://civitai.com/search/models?sortBy=models_v5&query=adetailer) - You can download various types detection models....Many models are associated with NSFW content.
## How To Install?
### Install via ComfyUI-Manager (Recommended)
* Search `ComfyUI Impact Subpack` in ComfyUI-Manager and click `Install` button.
### Manual Install (Not Recommended)
1. `cd custom_nodes`
2. `git clone https://github.com/ltdrdata/ComfyUI-Impact-Subpack`
3. `cd ComfyUI-Impact-Subpack`
4. `pip install -r requirements.txt`
* **IMPORTANT**:
* You must install it within the Python environment where ComfyUI is running.
* For the portable version, use `<installed path>\python_embeded\python.exe -m pip` instead of `pip`. For a `venv`, activate the `venv` first and then use `pip`.
5. Restart ComfyUI
## Credits
ComfyUI/[ComfyUI](https://github.com/comfyanonymous/ComfyUI) - A powerful and modular stable diffusion GUI.
+3 -2
View File
@@ -6,10 +6,11 @@
"""
import importlib
import logging
version_code = [1, 0]
version_code = [1, 2]
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
print(f"### Loading: ComfyUI-Impact-Subpack ({version_str})")
logging.info(f"### Loading: ComfyUI-Impact-Subpack ({version_str})")
node_list = [
"subpack_nodes",
+86 -12
View File
@@ -1,12 +1,12 @@
from pathlib import Path
from PIL import Image
import cv2
import numpy as np
from torchvision.transforms.functional import to_pil_image
import torch
from collections import namedtuple
from . import utils
import inspect
import logging
orig_torch_load = torch.load
@@ -39,27 +39,101 @@ def create_segmasks(results):
try:
from ultralytics import YOLO
from ultralytics.nn.tasks import DetectionModel
from ultralytics.nn.tasks import SegmentationModel
from ultralytics.utils import IterableSimpleNamespace
from ultralytics.utils.tal import TaskAlignedAssigner
import ultralytics.nn.modules as modules
import ultralytics.nn.modules.block as block_modules
import torch.nn.modules as torch_modules
import ultralytics.utils.loss as loss_modules
import dill._dill
from numpy.core.multiarray import scalar
from numpy import dtype
from numpy.dtypes import Float64DType
torch_whitelist = []
# https://github.com/comfyanonymous/ComfyUI/issues/5516#issuecomment-2466152838
def build_torch_whitelist():
"""
For security, only a limited set of namespaces is allowed during loading.
Since the same module may be identified by different namespaces depending on the model,
some modules are additionally registered with aliases to ensure backward compatibility.
"""
global torch_whitelist
for name, obj in inspect.getmembers(modules):
if inspect.isclass(obj) and obj.__module__.startswith("ultralytics.nn.modules"):
aliasObj = type(name, (obj,), {})
aliasObj.__module__ = "ultralytics.nn.modules"
torch_whitelist.append(obj)
torch_whitelist.append(aliasObj)
for name, obj in inspect.getmembers(block_modules):
if inspect.isclass(obj) and obj.__module__.startswith("ultralytics.nn.modules"):
aliasObj = type(name, (obj,), {})
aliasObj.__module__ = "ultralytics.nn.modules.block"
torch_whitelist.append(obj)
torch_whitelist.append(aliasObj)
for name, obj in inspect.getmembers(loss_modules):
if inspect.isclass(obj) and obj.__module__.startswith("ultralytics.utils.loss"):
aliasObj = type(name, (obj,), {})
aliasObj.__module__ = "ultralytics.yolo.utils.loss"
torch_whitelist.append(obj)
torch_whitelist.append(aliasObj)
for name, obj in inspect.getmembers(torch_modules):
if inspect.isclass(obj) and obj.__module__.startswith("torch.nn.modules"):
torch_whitelist.append(obj)
aliasIterableSimpleNamespace = type("IterableSimpleNamespace", (IterableSimpleNamespace,), {})
aliasIterableSimpleNamespace.__module__ = "ultralytics.yolo.utils"
aliasTaskAlignedAssigner = type("TaskAlignedAssigner", (TaskAlignedAssigner,), {})
aliasTaskAlignedAssigner.__module__ = "ultralytics.yolo.utils.tal"
aliasYOLOv10DetectionModel = type("YOLOv10DetectionModel", (DetectionModel,), {})
aliasYOLOv10DetectionModel.__module__ = "ultralytics.nn.tasks"
aliasYOLOv10DetectionModel.__name__ = "YOLOv10DetectionModel"
aliasv10DetectLoss = type("v10DetectLoss", (loss_modules.E2EDetectLoss,), {})
aliasv10DetectLoss.__name__ = "v10DetectLoss"
aliasv10DetectLoss.__module__ = "ultralytics.utils.loss"
torch_whitelist += [DetectionModel, aliasYOLOv10DetectionModel, SegmentationModel, IterableSimpleNamespace,
aliasIterableSimpleNamespace, TaskAlignedAssigner, aliasTaskAlignedAssigner, aliasv10DetectLoss,
getattr, dill._dill._load_type, scalar, dtype, Float64DType]
build_torch_whitelist()
except Exception as e:
print(e)
print(f"\n!!!!!\n\n[ComfyUI-Impact-Subpack] If this error occurs, please check the following link:\n\thttps://github.com/ltdrdata/ComfyUI-Impact-Pack/blob/Main/troubleshooting/TROUBLESHOOTING.md\n\n!!!!!\n")
logging.error(e)
logging.error("\n!!!!!\n\n[ComfyUI-Impact-Subpack] If this error occurs, please check the following link:\n\thttps://github.com/ltdrdata/ComfyUI-Impact-Pack/blob/Main/troubleshooting/TROUBLESHOOTING.md\n\n!!!!!\n")
raise e
# HOTFIX: https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/754
# importing YOLO breaking original torch.load capabilities
def torch_wrapper(*args, **kwargs):
kwargs['weights_only'] = False
# https://github.com/comfyanonymous/ComfyUI/issues/5516#issuecomment-2466152838
return orig_torch_load(*args, **kwargs)
torch.load = torch_wrapper
def load_yolo(model_path: str):
try:
return YOLO(model_path)
except ModuleNotFoundError:
# https://github.com/ultralytics/ultralytics/issues/3856
YOLO("yolov8n.pt")
return YOLO(model_path)
# https://github.com/comfyanonymous/ComfyUI/issues/5516#issuecomment-2466152838
with torch.serialization.safe_globals(torch_whitelist):
try:
return YOLO(model_path)
except ModuleNotFoundError:
# https://github.com/ultralytics/ultralytics/issues/3856
YOLO("yolov8n.pt")
return YOLO(model_path)
def inference_bbox(
+12 -4
View File
@@ -2,11 +2,19 @@ import os
import folder_paths
from . import subcore
from . import utils
import logging
model_path = folder_paths.models_dir
utils.add_folder_path_and_extensions("ultralytics_bbox", [os.path.join(model_path, "ultralytics", "bbox")], folder_paths.supported_pt_extensions)
utils.add_folder_path_and_extensions("ultralytics_segm", [os.path.join(model_path, "ultralytics", "segm")], folder_paths.supported_pt_extensions)
utils.add_folder_path_and_extensions("ultralytics", [os.path.join(model_path, "ultralytics")], folder_paths.supported_pt_extensions)
def update_model_paths(model_path):
utils.add_folder_path_and_extensions("ultralytics_bbox", [os.path.join(model_path, "ultralytics", "bbox")], folder_paths.supported_pt_extensions)
utils.add_folder_path_and_extensions("ultralytics_segm", [os.path.join(model_path, "ultralytics", "segm")], folder_paths.supported_pt_extensions)
utils.add_folder_path_and_extensions("ultralytics", [os.path.join(model_path, "ultralytics")], folder_paths.supported_pt_extensions)
logging.info(f'[Impact Subpack] ultralytics_bbox: {os.path.join(model_path, "ultralytics", "bbox")}')
logging.info(f'[Impact Subpack] ultralytics_segm: {os.path.join(model_path, "ultralytics", "segm")}')
update_model_paths(folder_paths.models_dir)
if 'download_model_base' in folder_paths.folder_names_and_paths:
update_model_paths(folder_paths.get_folder_paths('download_model_base')[0])
class UltralyticsDetectorProvider:
+1
View File
@@ -2,6 +2,7 @@ import folder_paths
from PIL import Image
import numpy as np
import cv2
import torch
def add_folder_path_and_extensions(folder_name, full_folder_paths, extensions):
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui-impact-subpack"
description = "This node pack provides nodes that complement the Impact Pack, such as the UltralyticsDetectorProvider."
version = "1.0"
version = "1.2"
license = { file = "LICENSE.txt" }
dependencies = ["matplotlib", "ultralytics==8.3.40"]