Skip to content

Commit

Permalink
minor changes for b33 release
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Dec 14, 2020
1 parent a222756 commit db32484
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Code/Main/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions Code/OS/ESRGAN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public static async Task Run(string inpath, string outpath, string modelArg, str
string deviceStr = " --device cuda";
if (Config.Get("cudaFallback").GetInt() == 1 || Config.Get("cudaFallback").GetInt() == 2) deviceStr = " --device cpu";

string opt = "/C";
if (stayOpen) opt = "/K";
string opt = stayOpen ? "/K" : "/C";

string cmd = $"{opt} cd /D {Paths.esrganPath.Wrap()} & ";
cmd += $"{EmbeddedPython.GetPyCmd()} esrlmain.py {inpath}{outpath}{deviceStr} --tilesize {tilesize}{alphaStr}{modelArg}";
Expand Down Expand Up @@ -197,8 +196,7 @@ public static async Task RunJoey(string inpath, string outpath, string modelArg,
inpath = inpath.Wrap();
outpath = outpath.Wrap();

string alphaStr = "--alpha_mode 0";
if (alpha) alphaStr = $"--alpha_mode {Config.GetInt("joeyAlphaMode")}";
string alphaStr = alpha ? $"--alpha_mode {Config.GetInt("joeyAlphaMode")}" : "--alpha_mode 0";

string deviceStr = "";
if (Config.Get("cudaFallback").GetInt() == 1 || Config.Get("cudaFallback").GetInt() == 2) deviceStr = "--cpu";
Expand All @@ -212,11 +210,10 @@ public static async Task RunJoey(string inpath, string outpath, string modelArg,
case 4: seamStr = "--alpha_padding"; break;
}

string opt = "/C";
if (stayOpen) opt = "/K";
string opt = stayOpen ? "/K" : "/C";

string cmd = $"{opt} cd /D {Paths.esrganPath.Wrap()} & ";
cmd += $"{EmbeddedPython.GetPyCmd()} upscale.py --input {inpath} --output {outpath} {deviceStr} {seamStr} --tile_size {tilesize} {alphaStr} {modelArg}";
cmd += $"{EmbeddedPython.GetPyCmd()} upscale.py --input {inpath} --output {outpath} {deviceStr} {seamStr} --tile_size {tilesize} {alphaStr} {modelArg}".TrimWhitespaces();

Logger.Log("[CMD] " + cmd);
Process esrganProcess = OSUtils.NewProcess(!showWindow);
Expand Down Expand Up @@ -261,7 +258,7 @@ private static void OutputHandler(object sendingProcess, DataReceivedEventArgs o
Program.ShowMessage("Error occurred: \n\n" + data + "\n\nThe ESRGAN process was killed to avoid lock-ups.", "Error");
}

if (data.Contains("out of memory"))
if (data.ToLower().Contains("out of memory"))
Program.ShowMessage("ESRGAN ran out of memory. Try reducing the tile size and avoid running programs in the background (especially games) that take up your VRAM.", "Error");

if (data.Contains("Python was not found"))
Expand All @@ -275,6 +272,9 @@ private static void OutputHandler(object sendingProcess, DataReceivedEventArgs o

if (data.Contains("UnpicklingError"))
Program.ShowMessage("Failed to load model!", "Error");

if (PreviewUI.currentMode == PreviewUI.Mode.Interp && data.Contains("must match the size of tensor b"))
Program.ShowMessage("It seems like you tried to interpolate incompatible models!", "Error");
}

static string lastProgressString = "";
Expand Down Expand Up @@ -322,8 +322,7 @@ public static async Task RunNcnn(string inpath, string outpath, string modelPath
//DialogForm dialog = new DialogForm("Loading ESRGAN-NCNN...\nThis should take 10-25 seconds.", 14);
int scale = NcnnUtils.GetNcnnModelScale(currentNcnnModel);

string opt = "/C";
if (stayOpen) opt = "/K";
string opt = stayOpen ? "/K" : "/C";

string cmd = $"{opt} cd /D {Paths.esrganPath.Wrap()} & ";
cmd += "esrgan-ncnn-vulkan.exe -i " + inpath + " -o " + outpath + " -m " + currentNcnnModel.Wrap() + " -s " + scale;
Expand Down Expand Up @@ -379,8 +378,7 @@ public static string Interpolate (ModelData mdl)

Process py = OSUtils.NewProcess(!showWindow);

string opt = "/C";
if (stayOpen) opt = "/K";
string opt = stayOpen ? "/K" : "/C";

string alphaStr = (mdl.interp / 100f).ToString("0.00").Replace(",", ".");
string outPath = mdl.model1Path.GetParentDir();
Expand Down
23 changes: 23 additions & 0 deletions Code/UI/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

Expand Down Expand Up @@ -110,5 +111,27 @@ public static int Clamp (this int i, int min, int max)
i = max;
return i;
}

public static string TrimWhitespaces(this string str)
{
if (str == null) return str;
var newString = new StringBuilder();
bool previousIsWhitespace = false;
for (int i = 0; i < str.Length; i++)
{
if (Char.IsWhiteSpace(str[i]))
{
if (previousIsWhitespace)
continue;
previousIsWhitespace = true;
}
else
{
previousIsWhitespace = false;
}
newString.Append(str[i]);
}
return newString.ToString();
}
}
}

0 comments on commit db32484

Please sign in to comment.