HEL-892: add pinned controlnet aux reference widget conversion

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-29 23:48:20 +08:00
co-authored by multica-agent
parent d3c8ab1238
commit 28d05b4dc3
15 changed files with 3649 additions and 16 deletions
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@@ -0,0 +1,224 @@
import sys, os
# Disable NPU device initialization and problematic MMCV ops to prevent RuntimeError
# Must be set BEFORE any MMCV imports happen anywhere in ComfyUI
os.environ['NPU_DEVICE_COUNT'] = '0'
os.environ['MMCV_WITH_OPS'] = '0'
from .utils import here, define_preprocessor_inputs, INPUT
from pathlib import Path
import traceback
import importlib
from .log import log, blue_text, cyan_text, get_summary, get_label
from .hint_image_enchance import NODE_CLASS_MAPPINGS as HIE_NODE_CLASS_MAPPINGS
from .hint_image_enchance import NODE_DISPLAY_NAME_MAPPINGS as HIE_NODE_DISPLAY_NAME_MAPPINGS
#Ref: https://github.com/comfyanonymous/ComfyUI/blob/76d53c4622fc06372975ed2a43ad345935b8a551/nodes.py#L17
sys.path.insert(0, str(Path(here, "src").resolve()))
for pkg_name in ["custom_controlnet_aux", "custom_mmpkg"]:
sys.path.append(str(Path(here, "src", pkg_name).resolve()))
#Enable CPU fallback for ops not being supported by MPS like upsample_bicubic2d.out
#https://github.com/pytorch/pytorch/issues/77764
#https://github.com/Fannovel16/comfyui_controlnet_aux/issues/2#issuecomment-1763579485
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = os.getenv("PYTORCH_ENABLE_MPS_FALLBACK", '1')
def load_nodes():
shorted_errors = []
full_error_messages = []
node_class_mappings = {}
node_display_name_mappings = {}
for filename in (here / "node_wrappers").iterdir():
module_name = filename.stem
if module_name.startswith('.'): continue #Skip hidden files created by the OS (e.g. [.DS_Store](https://en.wikipedia.org/wiki/.DS_Store))
try:
module = importlib.import_module(
f".node_wrappers.{module_name}", package=__package__
)
node_class_mappings.update(getattr(module, "NODE_CLASS_MAPPINGS"))
if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS"):
node_display_name_mappings.update(getattr(module, "NODE_DISPLAY_NAME_MAPPINGS"))
log.debug(f"Imported {module_name} nodes")
except AttributeError:
pass # wip nodes
except Exception:
error_message = traceback.format_exc()
full_error_messages.append(error_message)
error_message = error_message.splitlines()[-1]
shorted_errors.append(
f"Failed to import module {module_name} because {error_message}"
)
if len(shorted_errors) > 0:
full_err_log = '\n\n'.join(full_error_messages)
print(f"\n\nFull error log from comfyui_controlnet_aux: \n{full_err_log}\n\n")
log.info(
f"Some nodes failed to load:\n\t"
+ "\n\t".join(shorted_errors)
+ "\n\n"
+ "Check that you properly installed the dependencies.\n"
+ "If you think this is a bug, please report it on the github page (https://github.com/Fannovel16/comfyui_controlnet_aux/issues)"
)
return node_class_mappings, node_display_name_mappings
AUX_NODE_MAPPINGS, AUX_DISPLAY_NAME_MAPPINGS = load_nodes()
#For nodes not mapping image to image or has special requirements
AIO_NOT_SUPPORTED = ["InpaintPreprocessor", "MeshGraphormer+ImpactDetector-DepthMapPreprocessor", "DiffusionEdge_Preprocessor"]
AIO_NOT_SUPPORTED += ["SavePoseKpsAsJsonFile", "FacialPartColoringFromPoseKps", "UpperBodyTrackingFromPoseKps", "RenderPeopleKps", "RenderAnimalKps"]
AIO_NOT_SUPPORTED += ["Unimatch_OptFlowPreprocessor", "MaskOptFlow"]
def preprocessor_options():
auxs = list(AUX_NODE_MAPPINGS.keys())
auxs.insert(0, "none")
for name in AIO_NOT_SUPPORTED:
if name in auxs:
auxs.remove(name)
return auxs
PREPROCESSOR_OPTIONS = preprocessor_options()
class AIO_Preprocessor:
@classmethod
def INPUT_TYPES(s):
return define_preprocessor_inputs(
preprocessor=INPUT.COMBO(PREPROCESSOR_OPTIONS, default="none"),
resolution=INPUT.RESOLUTION()
)
RETURN_TYPES = ("IMAGE",)
FUNCTION = "execute"
CATEGORY = "ControlNet Preprocessors"
def execute(self, preprocessor, image, resolution=512):
if preprocessor == "none":
return (image, )
else:
aux_class = AUX_NODE_MAPPINGS[preprocessor]
input_types = aux_class.INPUT_TYPES()
input_types = {
**input_types["required"],
**(input_types["optional"] if "optional" in input_types else {})
}
params = {}
for name, input_type in input_types.items():
if name == "image":
params[name] = image
continue
if name == "resolution":
params[name] = resolution
continue
if len(input_type) == 2 and ("default" in input_type[1]):
params[name] = input_type[1]["default"]
continue
default_values = { "INT": 0, "FLOAT": 0.0 }
if type(input_type[0]) is list:
for input_type_value in input_type[0]:
if input_type_value in default_values:
params[name] = default_values[input_type[0]]
else:
if input_type[0] in default_values:
params[name] = default_values[input_type[0]]
return getattr(aux_class(), aux_class.FUNCTION)(**params)
class ControlNetAuxSimpleAddText:
@classmethod
def INPUT_TYPES(s):
return dict(
required=dict(image=INPUT.IMAGE(), text=INPUT.STRING())
)
RETURN_TYPES = ("IMAGE",)
FUNCTION = "execute"
CATEGORY = "ControlNet Preprocessors"
def execute(self, image, text):
from PIL import Image, ImageDraw, ImageFont
import numpy as np
import torch
font = ImageFont.truetype(str((here / "NotoSans-Regular.ttf").resolve()), 40)
img = Image.fromarray(image[0].cpu().numpy().__mul__(255.).astype(np.uint8))
ImageDraw.Draw(img).text((0,0), text, fill=(0,255,0), font=font)
return (torch.from_numpy(np.array(img)).unsqueeze(0) / 255.,)
class ExecuteAllControlNetPreprocessors:
@classmethod
def INPUT_TYPES(s):
return define_preprocessor_inputs(resolution=INPUT.RESOLUTION())
RETURN_TYPES = ("IMAGE",)
FUNCTION = "execute"
CATEGORY = "ControlNet Preprocessors"
def execute(self, image, resolution=512):
try:
from comfy_execution.graph_utils import GraphBuilder
except:
raise RuntimeError("ExecuteAllControlNetPreprocessor requries [Execution Model Inversion](https://github.com/comfyanonymous/ComfyUI/commit/5cfe38). Update ComfyUI/SwarmUI to get this feature")
graph = GraphBuilder()
curr_outputs = []
for preprocc in PREPROCESSOR_OPTIONS:
preprocc_node = graph.node("AIO_Preprocessor", preprocessor=preprocc, image=image, resolution=resolution)
hint_img = preprocc_node.out(0)
add_text_node = graph.node("ControlNetAuxSimpleAddText", image=hint_img, text=preprocc)
curr_outputs.append(add_text_node.out(0))
while len(curr_outputs) > 1:
_outputs = []
for i in range(0, len(curr_outputs), 2):
if i+1 < len(curr_outputs):
image_batch = graph.node("ImageBatch", image1=curr_outputs[i], image2=curr_outputs[i+1])
_outputs.append(image_batch.out(0))
else:
_outputs.append(curr_outputs[i])
curr_outputs = _outputs
return {
"result": (curr_outputs[0],),
"expand": graph.finalize(),
}
class ControlNetPreprocessorSelector:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"preprocessor": (PREPROCESSOR_OPTIONS,),
}
}
RETURN_TYPES = (PREPROCESSOR_OPTIONS,)
RETURN_NAMES = ("preprocessor",)
FUNCTION = "get_preprocessor"
CATEGORY = "ControlNet Preprocessors"
def get_preprocessor(self, preprocessor: str):
return (preprocessor,)
NODE_CLASS_MAPPINGS = {
**AUX_NODE_MAPPINGS,
"AIO_Preprocessor": AIO_Preprocessor,
"ControlNetPreprocessorSelector": ControlNetPreprocessorSelector,
**HIE_NODE_CLASS_MAPPINGS,
"ExecuteAllControlNetPreprocessors": ExecuteAllControlNetPreprocessors,
"ControlNetAuxSimpleAddText": ControlNetAuxSimpleAddText
}
NODE_DISPLAY_NAME_MAPPINGS = {
**AUX_DISPLAY_NAME_MAPPINGS,
"AIO_Preprocessor": "AIO Aux Preprocessor",
"ControlNetPreprocessorSelector": "Preprocessor Selector",
**HIE_NODE_DISPLAY_NAME_MAPPINGS,
"ExecuteAllControlNetPreprocessors": "Execute All ControlNet Preprocessors"
}
@@ -0,0 +1,26 @@
[
{
"local_file": "registry-1.1.5.json",
"url": "https://api.comfy.org/nodes/comfyui_controlnet_aux/versions/1.1.5",
"sha256": "694322dabd4cca87edfbf52369e3b9b8221ee6e26c0a5d2878dfd702ead373a7",
"retrieved_at": "2026-10-29T15:47:36.895566+00:00"
},
{
"local_file": "tags-response.json",
"url": "https://api.github.com/repos/Fannovel16/comfyui_controlnet_aux/tags?per_page=100",
"sha256": "2ba33ca0557f1bb5b7ba88d67f9d0093c7185a36ec51fe2b7bd9372d3e001d6d",
"retrieved_at": "2026-10-29T15:47:36.895566+00:00"
},
{
"local_file": "pyproject-history.json",
"url": "https://api.github.com/repos/Fannovel16/comfyui_controlnet_aux/commits?path=pyproject.toml&per_page=30",
"sha256": "e37aa0920b0b4ea1905867db5bb8505cc2210ee90ab6accbfe6552cf21edcf57",
"retrieved_at": "2026-10-29T15:47:36.895566+00:00"
},
{
"local_file": "version-commit.json",
"url": "https://api.github.com/repos/Fannovel16/comfyui_controlnet_aux/commits/e8b689a513c3e6b63edc44066560ca5919c0576e",
"sha256": "4e3c1379b671b6be3549deccfc4cbace9ac900e2c78bee025627a07e7c34fc43",
"retrieved_at": "2026-10-29T15:47:36.895566+00:00"
}
]
@@ -0,0 +1,55 @@
from ..utils import common_annotator_call, define_preprocessor_inputs, INPUT
import comfy.model_management as model_management
class Depth_Anything_Preprocessor:
@classmethod
def INPUT_TYPES(s):
return define_preprocessor_inputs(
ckpt_name=INPUT.COMBO(
["depth_anything_vitl14.pth", "depth_anything_vitb14.pth", "depth_anything_vits14.pth"]
),
resolution=INPUT.RESOLUTION()
)
RETURN_TYPES = ("IMAGE",)
FUNCTION = "execute"
CATEGORY = "ControlNet Preprocessors/Normal and Depth Estimators"
def execute(self, image, ckpt_name="depth_anything_vitl14.pth", resolution=512, **kwargs):
from custom_controlnet_aux.depth_anything import DepthAnythingDetector
model = DepthAnythingDetector.from_pretrained(filename=ckpt_name).to(model_management.get_torch_device())
out = common_annotator_call(model, image, resolution=resolution)
del model
return (out, )
class Zoe_Depth_Anything_Preprocessor:
@classmethod
def INPUT_TYPES(s):
return define_preprocessor_inputs(
environment=INPUT.COMBO(["indoor", "outdoor"]),
resolution=INPUT.RESOLUTION()
)
RETURN_TYPES = ("IMAGE",)
FUNCTION = "execute"
CATEGORY = "ControlNet Preprocessors/Normal and Depth Estimators"
def execute(self, image, environment="indoor", resolution=512, **kwargs):
from custom_controlnet_aux.zoe import ZoeDepthAnythingDetector
ckpt_name = "depth_anything_metric_depth_indoor.pt" if environment == "indoor" else "depth_anything_metric_depth_outdoor.pt"
model = ZoeDepthAnythingDetector.from_pretrained(filename=ckpt_name).to(model_management.get_torch_device())
out = common_annotator_call(model, image, resolution=resolution)
del model
return (out, )
NODE_CLASS_MAPPINGS = {
"DepthAnythingPreprocessor": Depth_Anything_Preprocessor,
"Zoe_DepthAnythingPreprocessor": Zoe_Depth_Anything_Preprocessor
}
NODE_DISPLAY_NAME_MAPPINGS = {
"DepthAnythingPreprocessor": "Depth Anything",
"Zoe_DepthAnythingPreprocessor": "Zoe Depth Anything"
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,14 @@
[project]
name = "comfyui_controlnet_aux"
description = "Plug-and-play ComfyUI node sets for making ControlNet hint images"
version = "1.1.5"
dependencies = ["torch", "importlib_metadata", "huggingface_hub", "scipy", "opencv-python>=4.7.0.72", "filelock", "numpy", "Pillow", "einops", "torchvision", "pyyaml", "scikit-image", "python-dateutil", "mediapipe", "fvcore", "yapf", "omegaconf", "ftfy", "addict", "yacs", "trimesh[easy]", "albumentations", "scikit-learn", "matplotlib"]
[project.urls]
Repository = "https://github.com/Fannovel16/comfyui_controlnet_aux"
[tool.comfy]
PublisherId = "fannovel16"
DisplayName = "comfyui_controlnet_aux"
Icon = ""
@@ -0,0 +1 @@
{"changelog":"","createdAt":"2026-04-13T10:46:14.267759Z","dependencies":["torch","importlib_metadata","huggingface_hub","scipy","opencv-python\u003e=4.7.0.72","filelock","numpy","Pillow","einops","torchvision","pyyaml","scikit-image","python-dateutil","mediapipe","fvcore","yapf","omegaconf","ftfy","addict","yacs","trimesh[easy]","albumentations","scikit-learn","matplotlib"],"deprecated":false,"downloadUrl":"https://cdn.comfy.org/fannovel16/comfyui_controlnet_aux/1.1.5/node.zip","id":"ddfa09d9-8aae-47c5-8426-9659a9f40703","node_id":"comfyui_controlnet_aux","status":"NodeVersionStatusActive","supported_accelerators":[],"supported_comfyui_frontend_version":"","supported_comfyui_version":"","supported_os":[],"tags":[],"version":"1.1.5"}
@@ -0,0 +1,119 @@
{
"authority": "public_reference_only_not_object_info",
"profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference",
"declared_source_version": "1.1.5",
"reference_commit": "e8b689a513c3e6b63edc44066560ca5919c0576e",
"version_basis": "Upstream commit bumps pyproject version to 1.1.5. No git tags. Registry version API gives no commit; exact release artifact mapping remains unknown.",
"registry_artifact_commit_match": "unknown",
"target_version_match": "unknown",
"ue_serializer_match": "unknown",
"dynamic_combo_membership": "unknown_not_evaluated",
"sources": [
{
"id": "controlnet_aux:__init__.py",
"repository": "https://github.com/Fannovel16/comfyui_controlnet_aux",
"commit": "e8b689a513c3e6b63edc44066560ca5919c0576e",
"file": "__init__.py",
"lines": [
[
25,
65
],
[
67,
130
],
[
209,
224
]
],
"url": "https://github.com/Fannovel16/comfyui_controlnet_aux/blob/e8b689a513c3e6b63edc44066560ca5919c0576e/__init__.py",
"raw_url": "https://raw.githubusercontent.com/Fannovel16/comfyui_controlnet_aux/e8b689a513c3e6b63edc44066560ca5919c0576e/__init__.py",
"local_file": "__init__.py",
"sha256": "9a5786ef9569223acd235676c08297aff78b2de1e46ab69c96665222b8c2a4b4",
"retrieved_at": "2026-10-29T15:47:36.895566+00:00",
"target_version_match": "unknown"
},
{
"id": "controlnet_aux:utils.py",
"repository": "https://github.com/Fannovel16/comfyui_controlnet_aux",
"commit": "e8b689a513c3e6b63edc44066560ca5919c0576e",
"file": "utils.py",
"lines": [
[
60,
70
],
[
94,
120
]
],
"url": "https://github.com/Fannovel16/comfyui_controlnet_aux/blob/e8b689a513c3e6b63edc44066560ca5919c0576e/utils.py",
"raw_url": "https://raw.githubusercontent.com/Fannovel16/comfyui_controlnet_aux/e8b689a513c3e6b63edc44066560ca5919c0576e/utils.py",
"local_file": "utils.py",
"sha256": "7d217c7ba934556ee0ffa2ff8cd7a705873381b274db179623c11b829f71a375",
"retrieved_at": "2026-10-29T15:47:36.895566+00:00",
"target_version_match": "unknown"
},
{
"id": "controlnet_aux:node_wrappers/depth_anything.py",
"repository": "https://github.com/Fannovel16/comfyui_controlnet_aux",
"commit": "e8b689a513c3e6b63edc44066560ca5919c0576e",
"file": "node_wrappers/depth_anything.py",
"lines": [
[
4,
25
],
[
48,
55
]
],
"url": "https://github.com/Fannovel16/comfyui_controlnet_aux/blob/e8b689a513c3e6b63edc44066560ca5919c0576e/node_wrappers/depth_anything.py",
"raw_url": "https://raw.githubusercontent.com/Fannovel16/comfyui_controlnet_aux/e8b689a513c3e6b63edc44066560ca5919c0576e/node_wrappers/depth_anything.py",
"local_file": "node_wrappers__depth_anything.py",
"sha256": "f769ac091bd2725065f4d8cddc6fba9ae636d659d16c3d2a79b9c202b099ec17",
"retrieved_at": "2026-10-29T15:47:36.895566+00:00",
"target_version_match": "unknown"
},
{
"id": "controlnet_aux:pyproject.toml",
"repository": "https://github.com/Fannovel16/comfyui_controlnet_aux",
"commit": "e8b689a513c3e6b63edc44066560ca5919c0576e",
"file": "pyproject.toml",
"lines": [
[
1,
14
]
],
"url": "https://github.com/Fannovel16/comfyui_controlnet_aux/blob/e8b689a513c3e6b63edc44066560ca5919c0576e/pyproject.toml",
"raw_url": "https://raw.githubusercontent.com/Fannovel16/comfyui_controlnet_aux/e8b689a513c3e6b63edc44066560ca5919c0576e/pyproject.toml",
"local_file": "pyproject.toml",
"sha256": "e8ec5486ae4d2fd82192e56efbbcecaa80e27f217ba06c216b10fac6ef147894",
"retrieved_at": "2026-10-29T15:47:36.895566+00:00",
"target_version_match": "unknown"
},
{
"id": "controlnet_aux:LICENSE.txt",
"repository": "https://github.com/Fannovel16/comfyui_controlnet_aux",
"commit": "e8b689a513c3e6b63edc44066560ca5919c0576e",
"file": "LICENSE.txt",
"lines": [
[
1,
201
]
],
"url": "https://github.com/Fannovel16/comfyui_controlnet_aux/blob/e8b689a513c3e6b63edc44066560ca5919c0576e/LICENSE.txt",
"raw_url": "https://raw.githubusercontent.com/Fannovel16/comfyui_controlnet_aux/e8b689a513c3e6b63edc44066560ca5919c0576e/LICENSE.txt",
"local_file": "LICENSE.txt",
"sha256": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4",
"retrieved_at": "2026-10-29T15:47:36.895566+00:00",
"target_version_match": "unknown"
}
]
}
@@ -0,0 +1,3 @@
[
]
+250
View File
@@ -0,0 +1,250 @@
import torch
import numpy as np
import os
import cv2
import yaml
from pathlib import Path
from enum import Enum
from .log import log
import subprocess
import threading
import comfy
import tempfile
here = Path(__file__).parent.resolve()
config_path = Path(here, "config.yaml")
if os.path.exists(config_path):
config = yaml.load(open(config_path, "r"), Loader=yaml.FullLoader)
annotator_ckpts_path = str(Path(here, config["annotator_ckpts_path"]))
TEMP_DIR = config["custom_temp_path"]
USE_SYMLINKS = config["USE_SYMLINKS"]
ORT_PROVIDERS = config["EP_list"]
if USE_SYMLINKS is None or type(USE_SYMLINKS) != bool:
log.error("USE_SYMLINKS must be a boolean. Using False by default.")
USE_SYMLINKS = False
if TEMP_DIR is None:
TEMP_DIR = tempfile.gettempdir()
elif not os.path.isdir(TEMP_DIR):
try:
os.makedirs(TEMP_DIR)
except:
log.error("Failed to create custom temp directory. Using default.")
TEMP_DIR = tempfile.gettempdir()
if not os.path.isdir(annotator_ckpts_path):
try:
os.makedirs(annotator_ckpts_path)
except:
log.error("Failed to create config ckpts directory. Using default.")
annotator_ckpts_path = str(Path(here, "./ckpts"))
else:
annotator_ckpts_path = str(Path(here, "./ckpts"))
TEMP_DIR = tempfile.gettempdir()
USE_SYMLINKS = False
ORT_PROVIDERS = ["CUDAExecutionProvider", "DirectMLExecutionProvider", "OpenVINOExecutionProvider", "ROCMExecutionProvider", "CPUExecutionProvider", "CoreMLExecutionProvider"]
os.environ['AUX_ANNOTATOR_CKPTS_PATH'] = os.getenv('AUX_ANNOTATOR_CKPTS_PATH', annotator_ckpts_path)
os.environ['AUX_TEMP_DIR'] = os.getenv('AUX_TEMP_DIR', str(TEMP_DIR))
os.environ['AUX_USE_SYMLINKS'] = os.getenv('AUX_USE_SYMLINKS', str(USE_SYMLINKS))
os.environ['AUX_ORT_PROVIDERS'] = os.getenv('AUX_ORT_PROVIDERS', str(",".join(ORT_PROVIDERS)))
log.info(f"Using ckpts path: {annotator_ckpts_path}")
log.info(f"Using symlinks: {USE_SYMLINKS}")
log.info(f"Using ort providers: {ORT_PROVIDERS}")
# Sync with theoritical limit from Comfy base
# https://github.com/comfyanonymous/ComfyUI/blob/eecd69b53a896343775bcb02a4f8349e7442ffd1/nodes.py#L45
MAX_RESOLUTION=16384
def common_annotator_call(model, tensor_image, input_batch=False, show_pbar=True, **kwargs):
if "detect_resolution" in kwargs:
del kwargs["detect_resolution"] #Prevent weird case?
if "resolution" in kwargs:
detect_resolution = kwargs["resolution"] if type(kwargs["resolution"]) == int and kwargs["resolution"] >= 64 else 512
del kwargs["resolution"]
else:
detect_resolution = 512
if input_batch:
np_images = np.asarray(tensor_image * 255., dtype=np.uint8)
np_results = model(np_images, output_type="np", detect_resolution=detect_resolution, **kwargs)
return torch.from_numpy(np_results.astype(np.float32) / 255.0)
batch_size = tensor_image.shape[0]
if show_pbar:
pbar = comfy.utils.ProgressBar(batch_size)
out_tensor = None
for i, image in enumerate(tensor_image):
np_image = np.asarray(image.cpu() * 255., dtype=np.uint8)
np_result = model(np_image, output_type="np", detect_resolution=detect_resolution, **kwargs)
out = torch.from_numpy(np_result.astype(np.float32) / 255.0)
if out_tensor is None:
out_tensor = torch.zeros(batch_size, *out.shape, dtype=torch.float32)
out_tensor[i] = out
if show_pbar:
pbar.update(1)
return out_tensor
def define_preprocessor_inputs(**arguments):
return dict(
required=dict(image=INPUT.IMAGE()),
optional=arguments
)
class INPUT(Enum):
def IMAGE():
return ("IMAGE",)
def LATENT():
return ("LATENT",)
def MASK():
return ("MASK",)
def SEED(default=0):
return ("INT", dict(default=default, min=0, max=0xffffffffffffffff))
def RESOLUTION(default=512, min=64, max=MAX_RESOLUTION, step=64):
return ("INT", dict(default=default, min=min, max=max, step=step))
def INT(default=0, min=0, max=MAX_RESOLUTION, step=1):
return ("INT", dict(default=default, min=min, max=max, step=step))
def FLOAT(default=0, min=0, max=1, step=0.01):
return ("FLOAT", dict(default=default, min=min, max=max, step=step))
def STRING(default='', multiline=False):
return ("STRING", dict(default=default, multiline=multiline))
def COMBO(values, default=None):
return (values, dict(default=values[0] if default is None else default))
def BOOLEAN(default=True):
return ("BOOLEAN", dict(default=default))
class ResizeMode(Enum):
"""
Resize modes for ControlNet input images.
"""
RESIZE = "Just Resize"
INNER_FIT = "Crop and Resize"
OUTER_FIT = "Resize and Fill"
def int_value(self):
if self == ResizeMode.RESIZE:
return 0
elif self == ResizeMode.INNER_FIT:
return 1
elif self == ResizeMode.OUTER_FIT:
return 2
assert False, "NOTREACHED"
#https://github.com/Mikubill/sd-webui-controlnet/blob/e67e017731aad05796b9615dc6eadce911298ea1/internal_controlnet/external_code.py#L89
#Replaced logger with internal log
def pixel_perfect_resolution(
image: np.ndarray,
target_H: int,
target_W: int,
resize_mode: ResizeMode,
) -> int:
"""
Calculate the estimated resolution for resizing an image while preserving aspect ratio.
The function first calculates scaling factors for height and width of the image based on the target
height and width. Then, based on the chosen resize mode, it either takes the smaller or the larger
scaling factor to estimate the new resolution.
If the resize mode is OUTER_FIT, the function uses the smaller scaling factor, ensuring the whole image
fits within the target dimensions, potentially leaving some empty space.
If the resize mode is not OUTER_FIT, the function uses the larger scaling factor, ensuring the target
dimensions are fully filled, potentially cropping the image.
After calculating the estimated resolution, the function prints some debugging information.
Args:
image (np.ndarray): A 3D numpy array representing an image. The dimensions represent [height, width, channels].
target_H (int): The target height for the image.
target_W (int): The target width for the image.
resize_mode (ResizeMode): The mode for resizing.
Returns:
int: The estimated resolution after resizing.
"""
raw_H, raw_W, _ = image.shape
k0 = float(target_H) / float(raw_H)
k1 = float(target_W) / float(raw_W)
if resize_mode == ResizeMode.OUTER_FIT:
estimation = min(k0, k1) * float(min(raw_H, raw_W))
else:
estimation = max(k0, k1) * float(min(raw_H, raw_W))
log.debug(f"Pixel Perfect Computation:")
log.debug(f"resize_mode = {resize_mode}")
log.debug(f"raw_H = {raw_H}")
log.debug(f"raw_W = {raw_W}")
log.debug(f"target_H = {target_H}")
log.debug(f"target_W = {target_W}")
log.debug(f"estimation = {estimation}")
return int(np.round(estimation))
#https://github.com/Mikubill/sd-webui-controlnet/blob/e67e017731aad05796b9615dc6eadce911298ea1/scripts/controlnet.py#L404
def safe_numpy(x):
# A very safe method to make sure that Apple/Mac works
y = x
# below is very boring but do not change these. If you change these Apple or Mac may fail.
y = y.copy()
y = np.ascontiguousarray(y)
y = y.copy()
return y
#https://github.com/Mikubill/sd-webui-controlnet/blob/e67e017731aad05796b9615dc6eadce911298ea1/scripts/utils.py#L140
def get_unique_axis0(data):
arr = np.asanyarray(data)
idxs = np.lexsort(arr.T)
arr = arr[idxs]
unique_idxs = np.empty(len(arr), dtype=np.bool_)
unique_idxs[:1] = True
unique_idxs[1:] = np.any(arr[:-1, :] != arr[1:, :], axis=-1)
return arr[unique_idxs]
#Ref: https://github.com/ltdrdata/ComfyUI-Manager/blob/284e90dc8296a2e1e4f14b4b2d10fba2f52f0e53/__init__.py#L14
def handle_stream(stream, prefix):
for line in stream:
print(prefix, line, end="")
def run_script(cmd, cwd='.'):
process = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
stdout_thread = threading.Thread(target=handle_stream, args=(process.stdout, ""))
stderr_thread = threading.Thread(target=handle_stream, args=(process.stderr, "[!]"))
stdout_thread.start()
stderr_thread.start()
stdout_thread.join()
stderr_thread.join()
return process.wait()
def nms(x, t, s):
x = cv2.GaussianBlur(x.astype(np.float32), (0, 0), s)
f1 = np.array([[0, 0, 0], [1, 1, 1], [0, 0, 0]], dtype=np.uint8)
f2 = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]], dtype=np.uint8)
f3 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=np.uint8)
f4 = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]], dtype=np.uint8)
y = np.zeros_like(x)
for f in [f1, f2, f3, f4]:
np.putmask(y, cv2.dilate(x, kernel=f) == x, x)
z = np.zeros_like(y, dtype=np.uint8)
z[y > t] = 255
return z
File diff suppressed because one or more lines are too long