Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controlnet conditioning updates #126

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Inputs: 1 to 1
Subnet: true
Python: false
Empty: false
Modified: Sun Jul 9 13:12:03 2023
Modified: Tue Sep 12 09:06:21 2023

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ matchesdef = 0
Content-Disposition: attachment; filename="hdaroot.def"
Content-Type: text/plain

sopflags sopflags =
sopflags sopflags =
comment ""
position -0.851307 -0.411438
connectornextid 1
Expand All @@ -53,7 +53,7 @@ stat
author Paul@DESKTOP-PAFFS1R
access 0777
}
color UT_Color RGB 0.8 0.8 0.8
color UT_Color RGB 0.8 0.8 0.8
delscript ""
exprlanguage hscript
end
Expand Down Expand Up @@ -87,7 +87,7 @@ matchesdef = 1
Content-Disposition: attachment; filename="hdaroot/output0.def"
Content-Type: text/plain

sopflags sopflags =
sopflags sopflags =
comment ""
position -4.94997 2.43356
connectornextid 1
Expand All @@ -110,7 +110,7 @@ stat
author Paul@M16AMTA
access 0777
}
color UT_Color RGB 0.8 0.8 0.8
color UT_Color RGB 0.8 0.8 0.8
delscript ""
exprlanguage hscript
end
Expand Down Expand Up @@ -146,7 +146,7 @@ matchesdef = 1
Content-Disposition: attachment; filename="hdaroot/python1.def"
Content-Type: text/plain

sopflags sopflags =
sopflags sopflags =
comment ""
position -4.94997 5.51136
connectornextid 2
Expand All @@ -170,7 +170,7 @@ stat
author Paul@DESKTOP-PAFFS1R
access 0777
}
color UT_Color RGB 0.8 0.8 0.8
color UT_Color RGB 0.8 0.8 0.8
delscript ""
exprlanguage hscript
end
Expand All @@ -189,7 +189,7 @@ from imagepipeline import controlnet_condition_image
from imp import reload
reload(mlops_utils)
reload(mlops_image_utils)
reload(controlnet_condition_image)
reload(controlnet_condition_image)

# Input Geometry
node = hou.pwd()
Expand All @@ -198,7 +198,7 @@ geo = node.geometry()
# Parameters
cache_only = node.parent().parm(\"cache_only\").evalAsInt()
model_type = node.parent().parm(\"conditioning\").evalAsString()
model = node.parent().parm(\"model\").evalAsString()
model = node.parent().parm(\"model\").evalAsString()

# Attributes
input_colors = mlops_image_utils.colored_points_to_numpy_array(geo)
Expand Down Expand Up @@ -233,7 +233,7 @@ matchesdef = 1
Content-Disposition: attachment; filename="hdaroot/attribwrangle2.def"
Content-Type: text/plain

sopflags sopflags =
sopflags sopflags =
comment ""
position -4.95297 6.54926
connectornextid 2
Expand All @@ -257,7 +257,7 @@ stat
author Paul@M16AMTA
access 0777
}
color UT_Color RGB 0.8 0.8 0.8
color UT_Color RGB 0.8 0.8 0.8
delscript ""
exprlanguage hscript
end
Expand Down Expand Up @@ -314,7 +314,7 @@ matchesdef = 1
Content-Disposition: attachment; filename="hdaroot/attribwrangle3.def"
Content-Type: text/plain

sopflags sopflags =
sopflags sopflags =
comment ""
position -4.95297 4.47146
connectornextid 2
Expand All @@ -338,7 +338,7 @@ stat
author Paul@M16AMTA
access 0777
}
color UT_Color RGB 0.8 0.8 0.8
color UT_Color RGB 0.8 0.8 0.8
delscript ""
exprlanguage hscript
end
Expand Down Expand Up @@ -393,7 +393,7 @@ matchesdef = 1
Content-Disposition: attachment; filename="hdaroot/attribdelete1.def"
Content-Type: text/plain

sopflags sopflags =
sopflags sopflags =
comment ""
position -4.95342 3.43356
connectornextid 2
Expand All @@ -417,7 +417,7 @@ stat
author Paul@DESKTOP-PAFFS1R
access 0777
}
color UT_Color RGB 0.8 0.8 0.8
color UT_Color RGB 0.8 0.8 0.8
delscript ""
exprlanguage hscript
end
Expand Down Expand Up @@ -463,7 +463,7 @@ matchesdef = 1
Content-Disposition: attachment; filename="hdaroot/resize_image1.def"
Content-Type: text/plain

sopflags sopflags =
sopflags sopflags =
comment ""
position -4.94997 7.58916
connectornextid 2
Expand All @@ -487,7 +487,7 @@ stat
author Paul@DESKTOP-PAFFS1R
access 0777
}
color UT_Color RGB 0.8 0.8 0.8
color UT_Color RGB 0.8 0.8 0.8
delscript ""
exprlanguage hscript
end
Expand Down Expand Up @@ -559,7 +559,7 @@ matchesdef = 1
Content-Disposition: attachment; filename="hdaroot/null1.def"
Content-Type: text/plain

sopflags sopflags =
sopflags sopflags =
comment ""
position -4.94997 8.68186
connectornextid 2
Expand All @@ -583,7 +583,7 @@ stat
author Mo@MO-GPU
access 0777
}
color UT_Color RGB 0.6 0.7 0.77
color UT_Color RGB 0.6 0.7 0.77
delscript ""
exprlanguage hscript
end
Expand Down Expand Up @@ -620,7 +620,7 @@ matchesdef = 1
Content-Disposition: attachment; filename="hdaroot/python2.def"
Content-Type: text/plain

sopflags sopflags =
sopflags sopflags =
comment ""
position -8.47403 4.9679
connectornextid 0
Expand All @@ -641,7 +641,7 @@ stat
author Paul@DESKTOP-PAFFS1R
access 0777
}
color UT_Color RGB 0.8 0.8 0.8
color UT_Color RGB 0.8 0.8 0.8
delscript ""
exprlanguage hscript
end
Expand Down Expand Up @@ -704,3 +704,4 @@ Content-Type: text/plain
1

--HOUDINIMIMEBOUNDARY0xD3ADD339-0x00000F49-0x56B122C9-0x00000001HOUDINIMIMEBOUNDARY--

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@
}
parmtag { "script_callback_language" "python" }
}
parm {
name "sepparm"
label "Separator"
type separator
default { "" }
}
groupcollapsible {
name "xn__DetectorParameters_cra"
label "Detector Parameters"

parm {
name "low_threshold"
label "Low Threshold"
type integer
default { "100" }
range { 0 255 }
parmtag { "script_callback_language" "python" }
}
parm {
name "high_threshold"
label "High Threshold"
type integer
default { "200" }
range { 0 255 }
parmtag { "script_callback_language" "python" }
}
}

}

}
Binary file added otls/mlops.sd_controlnet_conditioning.2.1.hdanc
Binary file not shown.
33 changes: 20 additions & 13 deletions scripts/python/imagepipeline/controlnet_condition_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,46 @@
from transformers import AutoImageProcessor, UperNetForSemanticSegmentation


def run(model, mode, input_colors, cache_only):
def run(model, mode, input_colors, cache_only,low_threshold=None, high_threshold=None):
img = mlops_image_utils.colors_numpy_array_to_pil(input_colors)

width, height = img.width, img.height
args = dict()
args['detect_resolution'] = width
args['image_resolution'] = width
if mode == "hed":
hed = HEDdetector.from_pretrained(model)
processed_image = hed(img)
processed_image = hed(img, **args)
elif mode == "midas":
midas = MidasDetector.from_pretrained(model)
processed_image = midas(img)
processed_image = midas(img, **args)
elif mode == "mlsd":
mlsd = MLSDdetector.from_pretrained(model)
processed_image = mlsd(img)
processed_image = mlsd(img, **args)
elif mode == "openpose":
open_pose = OpenposeDetector.from_pretrained(model)
processed_image = open_pose(img, hand_and_face=True)
processed_image = open_pose(img, hand_and_face=True, **args)
elif mode == "pidi":
pidi = PidiNetDetector.from_pretrained(model)
processed_image = pidi(img, safe=True)
processed_image = pidi(img, safe=True, **args)
elif mode == "bae":
normal_bae = NormalBaeDetector.from_pretrained(model)
processed_image = normal_bae(img)
processed_image = normal_bae(img, **args)
elif mode == "lineart":
lineart = LineartDetector.from_pretrained(model)
processed_image = lineart(img, coarse=True)
processed_image = lineart(img, coarse=True, **args)
elif mode == "lineartanime":
lineart_anime = LineartAnimeDetector.from_pretrained(model)
processed_image = lineart_anime(img)
processed_image = lineart_anime(img, **args)
elif mode == "zoe":
zoe = ZoeDetector.from_pretrained(model)
processed_image = zoe(img)
processed_image = zoe(img, **args)
elif mode == "canny":
if low_threshold is not None:
args['low_threshold'] = low_threshold
if high_threshold is not None:
args['high_threshold'] = high_threshold
canny = CannyDetector()
processed_image = canny(img)
processed_image = canny(img, **args)
elif mode == "content":
content = ContentShuffleDetector()
processed_image = content(img)
Expand All @@ -61,7 +68,7 @@ def run(model, mode, input_colors, cache_only):
processed_image = face_detector(img)
elif mode == "leres":
leres_detector = LeresDetector.from_pretrained(model)
processed_image = leres_detector(img)
processed_image = leres_detector(img, **args)
elif mode == "segment":
image_processor = AutoImageProcessor.from_pretrained(
"openmmlab/upernet-convnext-small", local_files_only=cache_only
Expand Down