Skip to content

Commit

Permalink
ControlNet minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
ForserX committed May 18, 2023
1 parent b984aa7 commit 93a4b29
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
46 changes: 42 additions & 4 deletions ui-src/Components/HelperControlNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Automation;

namespace SD_FXUI
{
class ControlNetBase
{
protected HelperControlNet.ControlTypes ControlType;
protected string Model = "";
protected string CNModel = "";
protected string BaseOutPath = FS.GetModelDir() + "controlnet/gen/";
Expand Down Expand Up @@ -70,6 +72,7 @@ public ControlNetOpenPose()
{
Model = "sd-controlnet-openpose";
CNModel = "sd-controlnet/anannotator/ckpts/";
ControlType = HelperControlNet.ControlTypes.OpenPose;
}

public override void CheckSD()
Expand All @@ -87,7 +90,7 @@ public override void CheckCN()
if (!System.IO.File.Exists(GetModelPathCN() + "hand_pose_model.pth"))
{
Notification.SendNotification("Starting downloading pose model...");
WGetDownloadModels.DownloadCNPoser(HelperControlNet.ControlTypes.Poser);
WGetDownloadModels.DownloadCNPoser(ControlType);
Notification.SendNotification("Download pose model: done!");
}
}
Expand All @@ -110,6 +113,7 @@ public ControlNetFace()
Model = "sd-controlnet-facegen";
CNModel = "";

ControlType = HelperControlNet.ControlTypes.MediapipeFace;
System.IO.Directory.CreateDirectory(Outdir());
}

Expand Down Expand Up @@ -140,6 +144,7 @@ public ControlNetHed()
{
Model = "sd-controlnet-hed";
CNModel = "sd-controlnet/anannotator/ckpts/network-bsds500.pth";
ControlType = HelperControlNet.ControlTypes.Hed;

System.IO.Directory.CreateDirectory(Outdir());
}
Expand All @@ -159,7 +164,7 @@ public override void CheckCN()
if (!System.IO.File.Exists(GetModelPathCN()))
{
Notification.SendNotification("Starting downloading hed model...");
WGetDownloadModels.DownloadCNPoser(HelperControlNet.ControlTypes.Hed);
WGetDownloadModels.DownloadCNPoser(ControlType);
Notification.SendNotification("Download hed model: done!");
}
}
Expand All @@ -180,6 +185,7 @@ public ControlNetCanny()
{
Model = "sd-controlnet-canny";
CNModel = "";
ControlType = HelperControlNet.ControlTypes.Canny;

System.IO.Directory.CreateDirectory(Outdir());
}
Expand Down Expand Up @@ -210,6 +216,7 @@ public ControlNetDepth()
{
Model = "sd-controlnet-depth";
CNModel = "";
ControlType = HelperControlNet.ControlTypes.Depth;

System.IO.Directory.CreateDirectory(Outdir());
}
Expand Down Expand Up @@ -241,6 +248,7 @@ public ControlNetNormal()
{
Model = "sd-controlnet-normal";
CNModel = "";
ControlType = HelperControlNet.ControlTypes.NormalMap;

System.IO.Directory.CreateDirectory(Outdir());
}
Expand Down Expand Up @@ -271,6 +279,7 @@ public ControlNetScribble()
{
Model = "sd-controlnet-scribble";
CNModel = "sd-controlnet/anannotator/ckpts/network-bsds500.pth";
ControlType = HelperControlNet.ControlTypes.Scribble;

System.IO.Directory.CreateDirectory(Outdir());
}
Expand Down Expand Up @@ -301,6 +310,7 @@ public ControlNetSeg()
{
Model = "sd-controlnet-seg";
CNModel = "";
ControlType = HelperControlNet.ControlTypes.Segmentation;

System.IO.Directory.CreateDirectory(Outdir());
}
Expand Down Expand Up @@ -331,6 +341,7 @@ public ControlNetMLSD()
{
Model = "sd-controlnet-mlsd";
CNModel = "sd-controlnet\\anannotator\\ckpts\\mlsd_large_512_fp32.pth";
ControlType = HelperControlNet.ControlTypes.Mlsd;

System.IO.Directory.CreateDirectory(Outdir());
}
Expand All @@ -350,7 +361,7 @@ public override void CheckCN()
if (!System.IO.File.Exists(GetModelPathCN()))
{
Notification.SendNotification("Starting downloading mlsd model...");
WGetDownloadModels.DownloadCNPoser(HelperControlNet.ControlTypes.Mlsd);
WGetDownloadModels.DownloadCNPoser(ControlType);
Notification.SendNotification("Download mlsd model: done!");
}
}
Expand Down Expand Up @@ -388,7 +399,7 @@ public enum ControlTypes
Hed,
NormalMap,
OpenPose,
OpenPose_hand,
MediapipeFace,
Clip_vision,
Color,
Pidinet,
Expand All @@ -398,5 +409,32 @@ public enum ControlTypes
Fake_Scribble,
Binary
}

public static ControlNetBase GetType(string StrData)
{
string LoverName = StrData.ToLower();

if (LoverName == "canny") return Canny;
if (LoverName == "depth") return Depth;
if (LoverName == "hed") return Hed;
if (LoverName == "normalmap") return Normal;
if (LoverName == "openposedetector") return OpenPose;
if (LoverName == "scribble") return Scribble;
if (LoverName == "segmentation") return Seg;
if (LoverName == "mlsd") return MLSD;
if (LoverName == "facegen") return Face;

/*
if (LoverName == "depth_leres") ; // not implemented return canny
if (LoverName == "openpose_hand") ; // not implemented return canny
if (LoverName == "clip_vision") ; // not implemented return canny
if (LoverName == "fake_scribble") ; // not implemented return canny
if (LoverName == "pidinet") ; // not implemented return canny
if (LoverName == "binary") ; // not implemented return canny
*/

return HelperControlNet.Canny; // temp Bypass error;

}
}
}
4 changes: 2 additions & 2 deletions ui-src/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ private void btnInImgPose_Click(object sender, RoutedEventArgs e)
{
string CurrentImg = Helper.InputImagePath;

ControlNetBase CN = GetCNType(cbExtractPoseSelector.Text);
ControlNetBase CN = HelperControlNet.GetType(cbExtractPoseSelector.Text);
Task.Run(() => CMD.PoserProcess(CurrentImg, CN));

cbControlNetMode.SelectedIndex = cbExtractPoseSelector.SelectedIndex;
Expand Down Expand Up @@ -960,7 +960,7 @@ private void cbControlNetMode_SelectionChanged(object sender, SelectionChangedEv

string NewMode = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();

HelperControlNet.Current = GetCNType(NewMode);
HelperControlNet.Current = HelperControlNet.GetType(NewMode);

UpdateModelsListControlNet();
cbPose.IsEnabled = true;
Expand Down
26 changes: 0 additions & 26 deletions ui-src/MainWindows.xaml.helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,32 +586,6 @@ private string FixedPrompt(string Text)

}

ControlNetBase GetCNType(string ComboBox)
{
string LoverName = ComboBox.ToLower();

if (LoverName == "canny") return HelperControlNet.Canny;
if (LoverName == "depth") return HelperControlNet.Depth;
if (LoverName == "hed") return HelperControlNet.Hed;
if (LoverName == "normalmap") return HelperControlNet.Normal;
if (LoverName == "openposedetector") return HelperControlNet.OpenPose;
if (LoverName == "scribble") return HelperControlNet.Scribble;
if (LoverName == "segmentation") return HelperControlNet.Seg;
if (LoverName == "mlsd") return HelperControlNet.MLSD;
if (LoverName == "facegen") return HelperControlNet.Face;

/*
if (LoverName == "depth_leres") ; // not implemented return canny
if (LoverName == "openpose_hand") ; // not implemented return canny
if (LoverName == "clip_vision") ; // not implemented return canny
if (LoverName == "fake_scribble") ; // not implemented return canny
if (LoverName == "pidinet") ; // not implemented return canny
if (LoverName == "binary") ; // not implemented return canny
*/

return HelperControlNet.Canny; // temp Bypass error;

}
public void UpdateModelsListControlNet()
{
cbPose.Items.Clear();
Expand Down

0 comments on commit 93a4b29

Please sign in to comment.