Update controlnet_module.py
Browse files- controlnet_module.py +0 -141
controlnet_module.py
CHANGED
|
@@ -113,147 +113,6 @@ class ControlNetProcessor:
|
|
| 113 |
print(f"Fehler bei Depth Map Extraction: {e}")
|
| 114 |
return image.convert("RGB").resize((512, 512))
|
| 115 |
|
| 116 |
-
def load_controlnet_pipeline(self, controlnet_type="openpose"):
|
| 117 |
-
"""Lädt die passende ControlNet Pipeline"""
|
| 118 |
-
if controlnet_type == "openpose":
|
| 119 |
-
if self.pipe_openpose is None:
|
| 120 |
-
print("Loading OpenPose ControlNet pipeline...")
|
| 121 |
-
try:
|
| 122 |
-
self.controlnet_openpose = ControlNetModel.from_pretrained(
|
| 123 |
-
"lllyasviel/sd-controlnet-openpose",
|
| 124 |
-
torch_dtype=self.torch_dtype
|
| 125 |
-
)
|
| 126 |
-
self.pipe_openpose = StableDiffusionControlNetPipeline.from_pretrained(
|
| 127 |
-
"runwayml/stable-diffusion-v1-5",
|
| 128 |
-
controlnet=self.controlnet_openpose,
|
| 129 |
-
torch_dtype=self.torch_dtype,
|
| 130 |
-
safety_checker=None,
|
| 131 |
-
requires_safety_checker=False
|
| 132 |
-
).to(self.device)
|
| 133 |
-
|
| 134 |
-
from diffusers import EulerAncestralDiscreteScheduler
|
| 135 |
-
self.pipe_openpose.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe_openpose.scheduler.config)
|
| 136 |
-
self.pipe_openpose.enable_attention_slicing()
|
| 137 |
-
print("✅ OpenPose ControlNet pipeline loaded successfully!")
|
| 138 |
-
except Exception as e:
|
| 139 |
-
print(f"Fehler beim Laden von OpenPose ControlNet: {e}")
|
| 140 |
-
raise
|
| 141 |
-
return self.pipe_openpose
|
| 142 |
-
|
| 143 |
-
elif controlnet_type == "canny":
|
| 144 |
-
if self.pipe_canny is None:
|
| 145 |
-
print("Loading Canny ControlNet pipeline...")
|
| 146 |
-
try:
|
| 147 |
-
self.controlnet_canny = ControlNetModel.from_pretrained(
|
| 148 |
-
"lllyasviel/sd-controlnet-canny",
|
| 149 |
-
torch_dtype=self.torch_dtype
|
| 150 |
-
)
|
| 151 |
-
self.pipe_canny = StableDiffusionControlNetPipeline.from_pretrained(
|
| 152 |
-
"runwayml/stable-diffusion-v1-5",
|
| 153 |
-
controlnet=self.controlnet_canny,
|
| 154 |
-
torch_dtype=self.torch_dtype,
|
| 155 |
-
safety_checker=None,
|
| 156 |
-
requires_safety_checker=False
|
| 157 |
-
).to(self.device)
|
| 158 |
-
|
| 159 |
-
from diffusers import EulerAncestralDiscreteScheduler
|
| 160 |
-
self.pipe_canny.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe_canny.scheduler.config)
|
| 161 |
-
self.pipe_canny.enable_attention_slicing()
|
| 162 |
-
print("✅ Canny ControlNet pipeline loaded successfully!")
|
| 163 |
-
except Exception as e:
|
| 164 |
-
print(f"Fehler beim Laden von Canny ControlNet: {e}")
|
| 165 |
-
raise
|
| 166 |
-
return self.pipe_canny
|
| 167 |
-
|
| 168 |
-
elif controlnet_type == "depth":
|
| 169 |
-
if self.pipe_depth is None:
|
| 170 |
-
print("Loading Depth ControlNet pipeline...")
|
| 171 |
-
try:
|
| 172 |
-
self.controlnet_depth = ControlNetModel.from_pretrained(
|
| 173 |
-
"lllyasviel/sd-controlnet-depth",
|
| 174 |
-
torch_dtype=self.torch_dtype
|
| 175 |
-
)
|
| 176 |
-
self.pipe_depth = StableDiffusionControlNetPipeline.from_pretrained(
|
| 177 |
-
"runwayml/stable-diffusion-v1-5",
|
| 178 |
-
controlnet=self.controlnet_depth,
|
| 179 |
-
torch_dtype=self.torch_dtype,
|
| 180 |
-
safety_checker=None,
|
| 181 |
-
requires_safety_checker=False
|
| 182 |
-
).to(self.device)
|
| 183 |
-
|
| 184 |
-
from diffusers import EulerAncestralDiscreteScheduler
|
| 185 |
-
self.pipe_depth.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe_depth.scheduler.config)
|
| 186 |
-
self.pipe_depth.enable_attention_slicing()
|
| 187 |
-
print("✅ Depth ControlNet pipeline loaded successfully!")
|
| 188 |
-
except Exception as e:
|
| 189 |
-
print(f"Fehler beim Laden von Depth ControlNet: {e}")
|
| 190 |
-
raise
|
| 191 |
-
return self.pipe_depth
|
| 192 |
-
|
| 193 |
-
elif controlnet_type == "multi_inside": # OpenPose + Canny für Inside-Box
|
| 194 |
-
if self.pipe_multi_inside is None:
|
| 195 |
-
print("Loading Multi-ControlNet pipeline für Inside-Box...")
|
| 196 |
-
try:
|
| 197 |
-
if self.controlnet_openpose is None:
|
| 198 |
-
self.controlnet_openpose = ControlNetModel.from_pretrained(
|
| 199 |
-
"lllyasviel/sd-controlnet-openpose",
|
| 200 |
-
torch_dtype=self.torch_dtype
|
| 201 |
-
)
|
| 202 |
-
if self.controlnet_canny is None:
|
| 203 |
-
self.controlnet_canny = ControlNetModel.from_pretrained(
|
| 204 |
-
"lllyasviel/sd-controlnet-canny",
|
| 205 |
-
torch_dtype=self.torch_dtype
|
| 206 |
-
)
|
| 207 |
-
|
| 208 |
-
self.pipe_multi_inside = StableDiffusionControlNetPipeline.from_pretrained(
|
| 209 |
-
"runwayml/stable-diffusion-v1-5",
|
| 210 |
-
controlnet=[self.controlnet_openpose, self.controlnet_canny],
|
| 211 |
-
torch_dtype=self.torch_dtype,
|
| 212 |
-
safety_checker=None,
|
| 213 |
-
requires_safety_checker=False
|
| 214 |
-
).to(self.device)
|
| 215 |
-
|
| 216 |
-
from diffusers import EulerAncestralDiscreteScheduler
|
| 217 |
-
self.pipe_multi_inside.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe_multi_inside.scheduler.config)
|
| 218 |
-
self.pipe_multi_inside.enable_attention_slicing()
|
| 219 |
-
print("✅ Multi-ControlNet (Inside) pipeline loaded successfully!")
|
| 220 |
-
except Exception as e:
|
| 221 |
-
print(f"Fehler beim Laden von Multi-ControlNet Inside: {e}")
|
| 222 |
-
raise
|
| 223 |
-
return self.pipe_multi_inside
|
| 224 |
-
|
| 225 |
-
elif controlnet_type == "multi_outside": # Depth + Canny für Outside-Box
|
| 226 |
-
if self.pipe_multi_outside is None:
|
| 227 |
-
print("Loading Multi-ControlNet pipeline für Outside-Box...")
|
| 228 |
-
try:
|
| 229 |
-
if self.controlnet_depth is None:
|
| 230 |
-
self.controlnet_depth = ControlNetModel.from_pretrained(
|
| 231 |
-
"lllyasviel/sd-controlnet-depth",
|
| 232 |
-
torch_dtype=self.torch_dtype
|
| 233 |
-
)
|
| 234 |
-
if self.controlnet_canny is None:
|
| 235 |
-
self.controlnet_canny = ControlNetModel.from_pretrained(
|
| 236 |
-
"lllyasviel/sd-controlnet-canny",
|
| 237 |
-
torch_dtype=self.torch_dtype
|
| 238 |
-
)
|
| 239 |
-
|
| 240 |
-
self.pipe_multi_outside = StableDiffusionControlNetPipeline.from_pretrained(
|
| 241 |
-
"runwayml/stable-diffusion-v1-5",
|
| 242 |
-
controlnet=[self.controlnet_depth, self.controlnet_canny],
|
| 243 |
-
torch_dtype=self.torch_dtype,
|
| 244 |
-
safety_checker=None,
|
| 245 |
-
requires_safety_checker=False
|
| 246 |
-
).to(self.device)
|
| 247 |
-
|
| 248 |
-
from diffusers import EulerAncestralDiscreteScheduler
|
| 249 |
-
self.pipe_multi_outside.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe_multi_outside.scheduler.config)
|
| 250 |
-
self.pipe_multi_outside.enable_attention_slicing()
|
| 251 |
-
print("✅ Multi-ControlNet (Outside) pipeline loaded successfully!")
|
| 252 |
-
except Exception as e:
|
| 253 |
-
print(f"Fehler beim Laden von Multi-ControlNet Outside: {e}")
|
| 254 |
-
raise
|
| 255 |
-
return self.pipe_multi_outside
|
| 256 |
-
|
| 257 |
|
| 258 |
def prepare_controlnet_maps(self, image, keep_environment=False):
|
| 259 |
"""
|
|
|
|
| 113 |
print(f"Fehler bei Depth Map Extraction: {e}")
|
| 114 |
return image.convert("RGB").resize((512, 512))
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
def prepare_controlnet_maps(self, image, keep_environment=False):
|
| 118 |
"""
|