Skip to content

Commit

Permalink
Initial ControlNet panel redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
carson-katri committed May 17, 2024
1 parent 5d255de commit c99b560
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 129 deletions.
4 changes: 2 additions & 2 deletions classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .operators.upscale import Upscale
from .operators.project import ProjectDreamTexture, dream_texture_projection_panels
from .operators.notify_result import NotifyResult
from .property_groups.control_net import ControlNet, SCENE_UL_ControlNetList, ControlNetsAdd, ControlNetsRemove
from .property_groups.control_net import ControlNet, ControlNetsAdd, ControlNetsRemove, ControlNetsAddMenu
from .property_groups.dream_prompt import DreamPrompt
from .property_groups.seamless_result import SeamlessResult
from .ui.panels import dream_texture, history, upscaling, render_properties
Expand Down Expand Up @@ -35,7 +35,7 @@
Upscale,
ProjectDreamTexture,

SCENE_UL_ControlNetList,
ControlNetsAddMenu,
ControlNetsAdd,
ControlNetsRemove,

Expand Down
1 change: 1 addition & 0 deletions generator_process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Generator(Actor):
from .actions.huggingface_hub import hf_snapshot_download, hf_list_models, hf_list_installed_models
from .actions.convert_original_stable_diffusion_to_diffusers import convert_original_stable_diffusion_to_diffusers
from .actions.detect_seamless import detect_seamless
from .actions.controlnet_aux import controlnet_aux

@staticmethod
def call(func, *args, **kwargs):
Expand Down
24 changes: 24 additions & 0 deletions generator_process/actions/controlnet_aux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy as np
from numpy.typing import NDArray
from ..models.optimizations import Optimizations

def controlnet_aux(
self,

processor_id: str,
image: NDArray,

optimizations: Optimizations,

**kwargs
) -> NDArray:
if processor_id == "none":
return image

from controlnet_aux.processor import Processor
processor = Processor(processor_id)
device = self.choose_device(optimizations)
processor.processor.to(device)

processed_image = processor(image)
return np.array(processed_image) / 255.0
267 changes: 157 additions & 110 deletions operators/dream_texture.py

Large diffs are not rendered by default.

75 changes: 64 additions & 11 deletions property_groups/control_net.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,88 @@
import bpy
from bpy.props import FloatProperty, EnumProperty, PointerProperty
from bpy.props import FloatProperty, EnumProperty, PointerProperty, IntProperty, BoolProperty

def control_net_options(self, context):
return [
None if model is None else (model.id, model.name, model.description)
for model in context.scene.dream_textures_prompt.get_backend().list_controlnet_models(context)
]

PROCESSOR_IDS = [
("none", "None", "No pre-processing"),
None,
("depth_leres", "Depth (LeRes)", ""),
("depth_leres++", "Depth (LeRes++)", ""),
("depth_midas", "Depth (MiDaS)", ""),
("depth_zoe", "Depth (Zoe)", ""),
None,
("canny", "Canny", "Canny edge detection"),
("mlsd", "M-LSD", ""),
("softedge_hed", "Soft Edge (HED)", ""),
("softedge_hedsafe", "Soft Edge (HED-Safe)", ""),
("softedge_pidinet", "Soft Edge (PidiNet)", ""),
("softedge_pidsafe", "Soft Edge (Pidsafe)", ""),
None,
("lineart_anime", "Lineart (Anime)", ""),
("lineart_coarse", "Lineart (Coarse)", ""),
("lineart_realistic", "Lineart (Realistic)", ""),
None,
("normal_bae", "Normal (BAE)", ""),
("normal_midas", "Normal (MiDaS)", ""),
None,
("openpose", "OpenPose", ""),
("openpose_face", "OpenPose (Face)", ""),
("openpose_faceonly", "OpenPose (Face Only)", ""),
("openpose_full", "OpenPose (Full)", ""),
("openpose_hand", "OpenPose (Hand)", ""),
("dwpose", "DWPose", ""),
("mediapipe_face", "MediaPipe Face", ""),
None,
("scribble_hed", "Scribble (HED)", ""),
("scribble_pidinet", "Scribble (PidiNet)", ""),
None,
("shuffle", "Shuffle", ""),
]

class ControlNet(bpy.types.PropertyGroup):
control_net: EnumProperty(name="ControlNet", items=control_net_options, description="Specify which ControlNet to use")
conditioning_scale: FloatProperty(name="ControlNet Conditioning Scale", default=1.0, description="Increases the strength of the ControlNet's effect")
conditioning_scale: FloatProperty(name="Conditioning Scale", default=1.0, description="Increases the strength of the ControlNet's effect")
control_image: PointerProperty(type=bpy.types.Image)
processor_id: EnumProperty(
name="Processor",
items=PROCESSOR_IDS,
description="Pre-process the control image"
)
enabled: BoolProperty(name="Enabled", default=True)

class ControlNetsAddMenu(bpy.types.Menu):
bl_idname = "DREAM_MT_control_nets_add"
bl_label = "Add ControlNet"

def draw(self, context):
layout = self.layout

class SCENE_UL_ControlNetList(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
layout.separator()
layout.prop(item, "control_net", text="")
layout.prop(item, "conditioning_scale", text="")
layout.template_ID(item, "control_image", open="image.open")
for model in control_net_options(self, context):
if model is None:
layout.separator()
else:
layout.operator("dream_textures.control_nets_add", text=model[1]).control_net = model[0]

class ControlNetsAdd(bpy.types.Operator):
bl_idname = "dream_textures.control_nets_add"
bl_label = "Add ControlNet"

control_net: EnumProperty(name="ControlNet", items=control_net_options)

def execute(self, context):
context.scene.dream_textures_prompt.control_nets.add()
net = context.scene.dream_textures_prompt.control_nets.add()
net.control_net = self.control_net
return {'FINISHED'}
class ControlNetsRemove(bpy.types.Operator):
bl_idname = "dream_textures.control_nets_remove"
bl_label = "Add ControlNet"
bl_label = "Remove ControlNet"

index: IntProperty(name="Index")

def execute(self, context):
context.scene.dream_textures_prompt.control_nets.remove(context.scene.dream_textures_prompt.active_control_net)
context.scene.dream_textures_prompt.control_nets.remove(self.index)
return {'FINISHED'}
1 change: 1 addition & 0 deletions property_groups/dream_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def generate_args(self, context, iteration=0, init_image=None, control_images=No
net.conditioning_scale
)
for i, net in enumerate(self.control_nets)
if net.enabled
]
)

Expand Down
1 change: 1 addition & 0 deletions requirements/linux-rocm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ invisible-watermark
transformers
accelerate
huggingface_hub
controlnet-aux==0.0.7

--extra-index-url https://download.pytorch.org/whl/rocm5.6/
torch>=2.1
Expand Down
3 changes: 2 additions & 1 deletion requirements/mac-mps-cpu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ git+https://github.com/huggingface/diffusers.git@d1222064669a758c476014fb7a09e24
invisible-watermark
transformers
accelerate
huggingface_hub
huggingface_hub>=0.19.3
controlnet-aux==0.0.7

torch>=2.0

Expand Down
1 change: 1 addition & 0 deletions requirements/win-dml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ invisible-watermark
transformers
accelerate
huggingface_hub
controlnet-aux==0.0.7

torch-directml
torch>=2.0
Expand Down
1 change: 1 addition & 0 deletions requirements/win-linux-cuda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ invisible-watermark
transformers
accelerate
huggingface_hub
controlnet-aux==0.0.7

--extra-index-url https://download.pytorch.org/whl/cu118
torch>=2.0
Expand Down
22 changes: 17 additions & 5 deletions ui/panels/dream_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,23 @@ def draw(self, context):
layout = self.layout
prompt = get_prompt(context)

row = layout.row()
row.template_list("SCENE_UL_ControlNetList", "", prompt, "control_nets", prompt, "active_control_net")
col = row.column(align=True)
col.operator("dream_textures.control_nets_add", icon='ADD', text="")
col.operator("dream_textures.control_nets_remove", icon='REMOVE', text="")
layout.operator("wm.call_menu", text="Add ControlNet", icon='ADD').name = "DREAM_MT_control_nets_add"
for i, control_net in enumerate(prompt.control_nets):
box = layout.box()
box.use_property_split = False
box.use_property_decorate = False

row = box.row()
row.prop(control_net, "enabled", icon="MODIFIER_ON" if control_net.enabled else "MODIFIER_OFF", icon_only=True, emboss=False)
row.prop(control_net, "control_net", text="")
row.operator("dream_textures.control_nets_remove", icon='X', emboss=False, text="").index = i

col = box.column()
col.use_property_split = True
col.template_ID(control_net, "control_image", open="image.open", text="Image")
col.prop(control_net, "processor_id")
col.prop(control_net, "conditioning_scale")

return ControlNetPanel

def advanced_panel(sub_panel, space_type, get_prompt):
Expand Down

0 comments on commit c99b560

Please sign in to comment.