Skip to content

Commit a2263c5

Browse files
authored
Add LayerMask: SegmentAnythingUltra V2 node (#285)
* Add LayerMask: SegmentAnythingUltra V2 node * refine * refine
1 parent e2ee245 commit a2263c5

3 files changed

Lines changed: 437 additions & 76 deletions

File tree

bizyair_extras/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .nodes_advanced_refluxcontrol import *
22
from .nodes_comfyui_detail_daemon import *
33
from .nodes_comfyui_instantid import *
4+
from .nodes_comfyui_layerstyle_advance import *
45
from .nodes_comfyui_pulid_flux import *
56
from .nodes_controlnet import *
67
from .nodes_custom_sampler import *
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
from bizyair import BizyAirBaseNode
2+
3+
# layerstyle advance
4+
NODE_NAME = "SegmentAnythingUltra V2"
5+
sam_model_dir_name = "sams"
6+
sam_model_list = {
7+
"sam_vit_h (2.56GB)": {
8+
"model_url": "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth"
9+
},
10+
# "sam_vit_l (1.25GB)": {
11+
# "model_url": "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth"
12+
# },
13+
# "sam_vit_b (375MB)": {
14+
# "model_url": "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth"
15+
# },
16+
# "sam_hq_vit_h (2.57GB)": {
17+
# "model_url": "https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_h.pth"
18+
# },
19+
# "sam_hq_vit_l (1.25GB)": {
20+
# "model_url": "https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_l.pth"
21+
# },
22+
# "sam_hq_vit_b (379MB)": {
23+
# "model_url": "https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_b.pth"
24+
# },
25+
# "mobile_sam(39MB)": {
26+
# "model_url": "https://github.com/ChaoningZhang/MobileSAM/blob/master/weights/mobile_sam.pt"
27+
# }
28+
}
29+
30+
groundingdino_model_dir_name = "grounding-dino"
31+
groundingdino_model_list = {
32+
"GroundingDINO_SwinT_OGC (694MB)": {
33+
"config_url": "https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/GroundingDINO_SwinT_OGC.cfg.py",
34+
"model_url": "https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swint_ogc.pth",
35+
},
36+
# "GroundingDINO_SwinB (938MB)": {
37+
# "config_url": "https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/GroundingDINO_SwinB.cfg.py",
38+
# "model_url": "https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swinb_cogcoor.pth"
39+
# },
40+
}
41+
42+
43+
def list_sam_model():
44+
return list(sam_model_list.keys())
45+
46+
47+
def list_groundingdino_model():
48+
return list(groundingdino_model_list.keys())
49+
50+
51+
class SegmentAnythingUltraV2(BizyAirBaseNode):
52+
53+
CLASS_TYPE_NAME = "LayerMask: SegmentAnythingUltra V2"
54+
NODE_DISPLAY_NAME = "LayerMask: SegmentAnythingUltra V2(Advance)"
55+
56+
def __init__(self):
57+
self.SAM_MODEL = None
58+
self.DINO_MODEL = None
59+
self.previous_sam_model = ""
60+
self.previous_dino_model = ""
61+
pass
62+
63+
@classmethod
64+
def INPUT_TYPES(cls):
65+
66+
method_list = [
67+
"VITMatte",
68+
"VITMatte(local)",
69+
"PyMatting",
70+
"GuidedFilter",
71+
]
72+
device_list = ["cuda"]
73+
return {
74+
"required": {
75+
"image": ("IMAGE",),
76+
"sam_model": (list_sam_model(),),
77+
"grounding_dino_model": (list_groundingdino_model(),),
78+
"threshold": (
79+
"FLOAT",
80+
{"default": 0.3, "min": 0, "max": 1.0, "step": 0.01},
81+
),
82+
"detail_method": (method_list,),
83+
"detail_erode": (
84+
"INT",
85+
{"default": 6, "min": 1, "max": 255, "step": 1},
86+
),
87+
"detail_dilate": (
88+
"INT",
89+
{"default": 6, "min": 1, "max": 255, "step": 1},
90+
),
91+
"black_point": (
92+
"FLOAT",
93+
{
94+
"default": 0.15,
95+
"min": 0.01,
96+
"max": 0.98,
97+
"step": 0.01,
98+
"display": "slider",
99+
},
100+
),
101+
"white_point": (
102+
"FLOAT",
103+
{
104+
"default": 0.99,
105+
"min": 0.02,
106+
"max": 0.99,
107+
"step": 0.01,
108+
"display": "slider",
109+
},
110+
),
111+
"process_detail": ("BOOLEAN", {"default": True}),
112+
"prompt": ("STRING", {"default": "subject"}),
113+
"device": (device_list,),
114+
"max_megapixels": (
115+
"FLOAT",
116+
{"default": 2.0, "min": 1, "max": 999, "step": 0.1},
117+
),
118+
"cache_model": ("BOOLEAN", {"default": True}),
119+
},
120+
"optional": {},
121+
}
122+
123+
RETURN_TYPES = (
124+
"IMAGE",
125+
"MASK",
126+
)
127+
RETURN_NAMES = (
128+
"image",
129+
"mask",
130+
)
131+
# FUNCTION = "segment_anything_ultra_v2"
132+
CATEGORY = "😺dzNodes/LayerMask"
133+
134+
135+
NODE_CLASS_MAPPINGS = {
136+
"LayerMask: SegmentAnythingUltra V2": SegmentAnythingUltraV2,
137+
}
138+
139+
NODE_DISPLAY_NAME_MAPPINGS = {
140+
"LayerMask: SegmentAnythingUltra V2": "LayerMask: SegmentAnythingUltra V2(Advance)",
141+
}

0 commit comments

Comments
 (0)