Skip to content

Commit e79d0b7

Browse files
committed
Added brightness cnet
1 parent 519e552 commit e79d0b7

File tree

5 files changed

+65
-8
lines changed

5 files changed

+65
-8
lines changed

data/repo/diffusion_scripts/convert/convert_controlnet_to_onnx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def convert_models(model_path: str, output_path: str, opset: int, attention_slic
9393
torch.randn(2, 3, 512,512).to(device=device, dtype=dtype),
9494
),
9595
output_path=cnet_path,
96-
ordered_input_names=["sample", "timestep", "encoder_hidden_states", "controlnet_cond","return_dict"],
96+
ordered_input_names=["sample", "timestep", "encoder_hidden_states", "controlnet_cond"],
9797
output_names=["down_block_res_samples", "mid_block_res_sample"], # has to be different from "sample" for correct tracing
9898
dynamic_axes={
9999
"sample": {0: "batch", 1: "channels", 2: "height", 3: "width"},

data/repo/diffusion_scripts/modules/onnx/custom_pipelines/pipeline_onnx_stable_diffusion_controlnet.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -720,12 +720,21 @@ def __call__(
720720

721721
timestep = np.array([t], dtype=timestep_dtype)
722722

723-
blocksamples = self.controlnet(
724-
sample=latent_model_input,
725-
timestep=timestep,
726-
encoder_hidden_states=prompt_embeds,
727-
controlnet_cond=image,
728-
)
723+
try:
724+
blocksamples = self.controlnet(
725+
sample=latent_model_input,
726+
timestep=timestep,
727+
encoder_hidden_states=prompt_embeds,
728+
controlnet_cond=image,
729+
conditioning_scale=1.0
730+
)
731+
except :
732+
blocksamples = self.controlnet(
733+
sample=latent_model_input,
734+
timestep=timestep,
735+
encoder_hidden_states=prompt_embeds,
736+
controlnet_cond=image
737+
)
729738

730739
mid_block_res_sample=blocksamples[12]
731740
down_block_res_samples=(

ui-src/Components/HelperControlNet.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,36 @@ override public string Outdir()
334334
return BaseOutPath + "Seg/";
335335
}
336336
}
337+
class ControlNetBrightness : ControlNetBase
338+
{
339+
public ControlNetBrightness()
340+
{
341+
Model = "sd-controlnet-brightness";
342+
CNModel = "";
343+
ControlType = HelperControlNet.ControlTypes.Brightness;
344+
345+
System.IO.Directory.CreateDirectory(Outdir());
346+
}
347+
348+
public override void CheckSD()
349+
{
350+
if (!System.IO.Directory.Exists(GetModelPathSD()))
351+
{
352+
Notification.SendNotification("Starting downloading brightness model...");
353+
WGetDownloadModels.DownloadSDCNBrg();
354+
Notification.SendNotification("Downloading brightness model: done!");
355+
}
356+
}
357+
358+
override public string PreprocessCommandLine()
359+
{
360+
return "BrgfI";
361+
}
362+
override public string Outdir()
363+
{
364+
return BaseOutPath + "brightness/";
365+
}
366+
}
337367

338368
class ControlNetMLSD : ControlNetBase
339369
{
@@ -388,6 +418,7 @@ internal class HelperControlNet
388418
public static ControlNetSeg Seg = new ControlNetSeg();
389419
public static ControlNetMLSD MLSD = new ControlNetMLSD();
390420
public static ControlNetFace Face = new ControlNetFace();
421+
public static ControlNetBrightness Brightness = new ControlNetBrightness();
391422

392423
public static ControlNetBase Current = null;
393424
public enum ControlTypes
@@ -407,7 +438,8 @@ public enum ControlTypes
407438
Mlsd,
408439
Scribble,
409440
Fake_Scribble,
410-
Binary
441+
Binary,
442+
Brightness
411443
}
412444

413445
public static ControlNetBase GetType(string StrData)
@@ -423,6 +455,7 @@ public static ControlNetBase GetType(string StrData)
423455
if (LoverName == "segmentation") return Seg;
424456
if (LoverName == "mlsd") return MLSD;
425457
if (LoverName == "facegen") return Face;
458+
if (LoverName == "brightness") return Brightness;
426459

427460
/*
428461
if (LoverName == "depth_leres") ; // not implemented return canny

ui-src/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
<ComboBoxItem Content="Facegen"/>
314314
<!-- ComboBoxItem Content="color"/ -->
315315
<ComboBoxItem Content="Scribble"/>
316+
<ComboBoxItem Content="Brightness"/>
316317
<!-- ComboBoxItem Content="pidinet"/ -->
317318
<ComboBoxItem Content="MLSD"/>
318319
<ComboBoxItem Content="Segmentation"/>

ui-src/Utils/Models/WGetDownloadModels.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ public static void DownloadSDCNSeg()
154154
FileDownloader.DownloadFileAsync("https://huggingface.co/lllyasviel/sd-controlnet-seg/resolve/main/diffusion_pytorch_model.bin", WorkingDir + @"diffusion_pytorch_model.bin");
155155
FileDownloader.DownloadFileAsync("https://huggingface.co/ForserX/sd-controlnet-seg-onnx/resolve/main/model.onnx", WorkingDir + @"model.onnx");
156156
}
157+
public static void DownloadSDCNBrg()
158+
{
159+
string WorkingDir = FS.GetModelDir() + "controlnet/sd-controlnet-brightness/";
160+
161+
if (Directory.Exists(WorkingDir))
162+
{
163+
return;
164+
}
165+
Directory.CreateDirectory(WorkingDir);
166+
167+
FileDownloader.DownloadFileAsync("https://huggingface.co/ioclab/control_v1p_sd15_brightness/raw/main/config.json", WorkingDir + @"config.json");
168+
FileDownloader.DownloadFileAsync("https://huggingface.co/ioclab/control_v1p_sd15_brightness/resolve/main/diffusion_pytorch_model.safetensors", WorkingDir + @"diffusion_pytorch_model.safetensors");
169+
FileDownloader.DownloadFileAsync("https://huggingface.co/ForserX/sd-controlnet-brightness/resolve/main/model.onnx", WorkingDir + @"model.onnx");
170+
}
157171
public static void DownloadSDCNMLSD()
158172
{
159173
string WorkingDir = FS.GetModelDir() + "controlnet/sd-controlnet-mlsd/";

0 commit comments

Comments
 (0)