This commit is contained in:
lllyasviel
2024-01-27 22:28:58 -08:00
parent e9d7f52ce5
commit 0695b4afdb
2 changed files with 6 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ from modules.paths import models_path
from modules.modelloader import load_file_from_url
from ldm_patched.modules.controlnet import load_controlnet
from modules_forge.controlnet import apply_controlnet_advanced
from modules_forge.forge_util import pytorch_to_numpy, numpy_to_pytorch
class ControlNetExampleForge(scripts.Script):
@@ -76,9 +77,11 @@ class ControlNetExampleForge(scripts.Script):
print('Preprocessor Canny finished.')
control_image = numpy_to_pytorch(canny_image)
unet = p.sd_model.forge_objects.unet
unet = apply_controlnet_advanced(unet=unet, controlnet=self.model, image=canny_image,
unet = apply_controlnet_advanced(unet=unet, controlnet=self.model, cond_hint=control_image,
strength=1.0, start_percent=0.0, end_percent=1.0,
positive_advanced_weighting=None, negative_advanced_weighting=None)

View File

@@ -1,14 +1,14 @@
def apply_controlnet_advanced(
unet,
controlnet,
image,
cond_hint,
strength,
start_percent,
end_percent,
positive_advanced_weighting=None,
negative_advanced_weighting=None):
cnet = controlnet.copy().set_cond_hint(image, strength, (start_percent, end_percent))
cnet = controlnet.copy().set_cond_hint(cond_hint, strength, (start_percent, end_percent))
cnet.positive_advanced_weighting = positive_advanced_weighting
cnet.negative_advanced_weighting = negative_advanced_weighting