From db32484631ea2a91ea2fb1bc28a97dd6cdb6b8a7 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Mon, 14 Dec 2020 11:21:32 +0100 Subject: [PATCH] minor changes for b33 release --- Code/Main/MainForm.Designer.cs | 2 +- Code/OS/ESRGAN.cs | 22 ++++++++++------------ Code/UI/ExtensionMethods.cs | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Code/Main/MainForm.Designer.cs b/Code/Main/MainForm.Designer.cs index b5e2043..1114391 100644 --- a/Code/Main/MainForm.Designer.cs +++ b/Code/Main/MainForm.Designer.cs @@ -1000,7 +1000,7 @@ private void InitializeComponent() this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(364, 34); this.label5.TabIndex = 1; - this.label5.Text = "Cupscale [Build 31 - 11/12/20]"; + this.label5.Text = "Cupscale [Build 33 - 12/14/20]"; this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // panel7 diff --git a/Code/OS/ESRGAN.cs b/Code/OS/ESRGAN.cs index f57c9cf..56de7b6 100644 --- a/Code/OS/ESRGAN.cs +++ b/Code/OS/ESRGAN.cs @@ -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}"; @@ -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"; @@ -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); @@ -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")) @@ -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 = ""; @@ -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; @@ -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(); diff --git a/Code/UI/ExtensionMethods.cs b/Code/UI/ExtensionMethods.cs index c36b33f..9a59530 100644 --- a/Code/UI/ExtensionMethods.cs +++ b/Code/UI/ExtensionMethods.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Security; +using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -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(); + } } }