Skip to content

Commit

Permalink
Merge pull request #6 from ArtVentureX/main
Browse files Browse the repository at this point in the history
Fix ModuleNotFoundError and improve start up time
  • Loading branch information
Fannovel16 authored Aug 19, 2023
2 parents d859770 + b4f6eb2 commit 582f0ad
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 21 deletions.
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .log import log, blue_text, cyan_text, get_summary, get_label

#Ref: https://github.com/comfyanonymous/ComfyUI/blob/76d53c4622fc06372975ed2a43ad345935b8a551/nodes.py#L17
sys.path.insert(0, str(Path(here, "src").resolve()))
for pkg_name in os.listdir(str(Path(here, "src"))):
sys.path.insert(0, str(Path(here, "src", pkg_name).resolve()))
print(f"Registered sys.path: {sys.path}")
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/binary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.binary import BinaryDetector
import comfy.model_management as model_management

class Binary_Preprocessor:
Expand All @@ -18,6 +17,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, bin_threshold, **kwargs):
from controlnet_aux.binary import BinaryDetector

return (common_annotator_call(BinaryDetector(), image, bin_threshold=bin_threshold), )


Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/canny.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.canny import CannyDetector
import comfy.model_management as model_management

class Canny_Edge_Preprocessor:
Expand All @@ -19,6 +18,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, low_threshold, high_threshold, **kwargs):
from controlnet_aux.canny import CannyDetector

return (common_annotator_call(CannyDetector(), image, low_threshold=low_threshold, high_threshold=high_threshold), )


Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/color.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.color import ColorDetector
import comfy.model_management as model_management

class Color_Preprocessor:
Expand All @@ -15,6 +14,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/T2IAdapter-only"

def execute(self, image, **kwargs):
from controlnet_aux.color import ColorDetector

return (common_annotator_call(ColorDetector(), image), )


Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/dwpose.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME, DWPOSE_MODEL_NAME
from controlnet_aux.dwpose import DwposeDetector
import comfy.model_management as model_management

class DWPose_Preprocessor:
Expand All @@ -19,6 +18,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Faces and Poses"

def estimate_pose(self, image, detect_hand, detect_body, detect_face, **kwargs):
from controlnet_aux.dwpose import DwposeDetector

detect_hand = detect_hand == "enable"
detect_body = detect_body == "enable"
detect_face = detect_face == "enable"
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/hed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.hed import HEDdetector
import comfy.model_management as model_management

class HED_Preprocessor:
Expand All @@ -18,6 +17,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, **kwargs):
from controlnet_aux.hed import HEDdetector

model = HEDdetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image, safe = kwargs["safe"] == "enable")
del model
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/leres.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.leres import LeresDetector
import comfy.model_management as model_management

class LERES_Depth_Map_Preprocessor:
Expand All @@ -22,6 +21,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Normal and Depth Map"

def execute(self, image, rm_nearest, rm_background, **kwargs):
from controlnet_aux.leres import LeresDetector

model = LeresDetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image, thr_a=rm_nearest, thr_b=rm_background, boost=kwargs["boost"] == "enable")
del model
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/lineart.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.lineart import LineartDetector
import comfy.model_management as model_management

class LineArt_Preprocessor:
Expand All @@ -18,6 +17,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, **kwargs):
from controlnet_aux.lineart import LineartDetector

model = LineartDetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image, coarse = kwargs["coarse"] == "enable")
del model
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/lineart_anime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.lineart_anime import LineartAnimeDetector
import comfy.model_management as model_management

class AnimeLineArt_Preprocessor:
Expand All @@ -13,6 +12,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, **kwargs):
from controlnet_aux.lineart_anime import LineartAnimeDetector

model = LineartAnimeDetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image)
del model
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/manga_line.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.manga_line import LineartMangaDetector
import comfy.model_management as model_management

class Manga2Anime_LineArt_Preprocessor:
Expand All @@ -13,6 +12,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, **kwargs):
from controlnet_aux.manga_line import LineartMangaDetector

model = LineartMangaDetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image)
del model
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/mediapipe_face.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME, DWPOSE_MODEL_NAME
from controlnet_aux.mediapipe_face import MediapipeFaceDetector
import comfy.model_management as model_management

class Media_Pipe_Face_Mesh_Preprocessor:
Expand All @@ -15,6 +14,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Faces and Poses"

def detect(self, image, max_faces, min_confidence):
from controlnet_aux.mediapipe_face import MediapipeFaceDetector

return (common_annotator_call(MediapipeFaceDetector(), image, max_faces=max_faces, min_confidence=min_confidence), )

NODE_CLASS_MAPPINGS = {
Expand Down
5 changes: 4 additions & 1 deletion node_wrappers/midas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.midas import MidasDetector
import comfy.model_management as model_management
import numpy as np

Expand All @@ -17,6 +16,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Normal and Depth Map"

def execute(self, image, a, bg_threshold, **kwargs):
from controlnet_aux.midas import MidasDetector

model = MidasDetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
#Dirty hack :))
cb = lambda image, **kargs: model(image, **kargs)[1]
Expand All @@ -38,6 +39,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Normal and Depth Map"

def execute(self, image, a, bg_threshold, **kwargs):
from controlnet_aux.midas import MidasDetector

# Ref: https://github.com/lllyasviel/ControlNet/blob/main/gradio_depth2image.py
model = MidasDetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image, a=a, bg_th=bg_threshold)
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/mlsd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.mlsd import MLSDdetector
import comfy.model_management as model_management
import numpy as np

Expand All @@ -20,6 +19,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, score_threshold, dist_threshold, **kwargs):
from controlnet_aux.mlsd import MLSDdetector

model = MLSDdetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image, thr_v=score_threshold, thr_d=dist_threshold)
return (out, )
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/normalbae.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.normalbae import NormalBaeDetector
import comfy.model_management as model_management

class BAE_Normal_Map_Preprocessor:
Expand All @@ -13,6 +12,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Normal and Depth Map"

def execute(self, image, **kwargs):
from controlnet_aux.normalbae import NormalBaeDetector

model = NormalBaeDetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image)
del model
Expand Down
5 changes: 4 additions & 1 deletion node_wrappers/oneformer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.oneformer import OneformerSegmentor
import comfy.model_management as model_management

class OneFormer_COCO_SemSegPreprocessor:
Expand All @@ -13,6 +12,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Semantic Segmentation"

def semantic_segmentate(self, image):
from controlnet_aux.oneformer import OneformerSegmentor

model = OneformerSegmentor.from_pretrained(HF_MODEL_NAME, "150_16_swin_l_oneformer_coco_100ep.pth", cache_dir=annotator_ckpts_path)
model = model.to(model_management.get_torch_device())
out = common_annotator_call(model, image)
Expand All @@ -30,6 +31,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Semantic Segmentation"

def semantic_segmentate(self, image):
from controlnet_aux.oneformer import OneformerSegmentor

model = OneformerSegmentor.from_pretrained(HF_MODEL_NAME, "250_16_swin_l_oneformer_ade20k_160k.pth", cache_dir=annotator_ckpts_path)
model = model.to(model_management.get_torch_device())
out = common_annotator_call(model, image)
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/openpose.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME, DWPOSE_MODEL_NAME
from controlnet_aux.open_pose import OpenposeDetector
import comfy.model_management as model_management

class OpenPose_Preprocessor:
Expand All @@ -19,6 +18,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors"

def estimate_pose(self, image, detect_hand, detect_body, detect_face, **kwargs):
from controlnet_aux.open_pose import OpenposeDetector

detect_hand = detect_hand == "enable"
detect_body = detect_body == "enable"
detect_face = detect_face == "enable"
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/pidinet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.pidi import PidiNetDetector
import comfy.model_management as model_management

class PIDINET_Preprocessor:
Expand All @@ -13,6 +12,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, safe, **kwargs):
from controlnet_aux.pidi import PidiNetDetector

model = PidiNetDetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image, safe = safe == "enable")
del model
Expand Down
5 changes: 4 additions & 1 deletion node_wrappers/scribble.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.scribble import ScribbleDetector, ScribbleXDog_Detector
import comfy.model_management as model_management

class Scribble_Preprocessor:
Expand All @@ -13,6 +12,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, **kwargs):
from controlnet_aux.scribble import ScribbleDetector

model = ScribbleDetector()
return (common_annotator_call(model, image), )

Expand All @@ -32,6 +33,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Line Extractors"

def execute(self, image, **kwargs):
from controlnet_aux.scribble import ScribbleXDog_Detector

model = ScribbleXDog_Detector()
return (common_annotator_call(model, image), )

Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/segment_anything.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.segment_anything import SamDetector
import comfy.model_management as model_management

class SAM_Preprocessor:
Expand All @@ -15,6 +14,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/others"

def execute(self, image, **kwargs):
from controlnet_aux.segment_anything import SamDetector

mobile_sam = SamDetector.from_pretrained("dhkim2810/MobileSAM", model_type="vit_t", filename="mobile_sam.pt").to(model_management.get_torch_device())
out = common_annotator_call(mobile_sam, image)
del mobile_sam
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/shuffle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.shuffle import ContentShuffleDetector
import comfy.model_management as model_management

class Shuffle_Preprocessor:
Expand All @@ -12,6 +11,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/T2IAdapter-only"

def preprocess(self, image):
from controlnet_aux.shuffle import ContentShuffleDetector

return (common_annotator_call(ContentShuffleDetector(), image), )

NODE_CLASS_MAPPINGS = {
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/uniformer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.uniformer import UniformerSegmentor
import comfy.model_management as model_management

class Uniformer_SemSegPreprocessor:
Expand All @@ -13,6 +12,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Semantic Segmentation"

def semantic_segmentate(self, image):
from controlnet_aux.uniformer import UniformerSegmentor

model = UniformerSegmentor.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image)
del model
Expand Down
3 changes: 2 additions & 1 deletion node_wrappers/zoe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ..utils import common_annotator_call, annotator_ckpts_path, HF_MODEL_NAME
from controlnet_aux.zoe import ZoeDetector
import comfy.model_management as model_management

class Zoe_Depth_Map_Preprocessor:
Expand All @@ -14,6 +13,8 @@ def INPUT_TYPES(s):
CATEGORY = "ControlNet Preprocessors/Normal and Depth Map"

def execute(self, image, **kwargs):
from controlnet_aux.zoe import ZoeDetector

model = ZoeDetector.from_pretrained(HF_MODEL_NAME, cache_dir=annotator_ckpts_path).to(model_management.get_torch_device())
out = common_annotator_call(model, image)
del model
Expand Down

0 comments on commit 582f0ad

Please sign in to comment.