public static async Task RunNcnn(string inpath, string outpath, string modelPath) { bool showWindow = Config.GetInt("cmdDebugMode") > 0; bool stayOpen = Config.GetInt("cmdDebugMode") == 2; Program.mainForm.SetProgress(1f, "Converting model..."); await NcnnUtils.ConvertNcnnModel(modelPath); Logger.Log("[ESRGAN] NCNN Model is ready: " + currentNcnnModel); Program.mainForm.SetProgress(3f, "Loading ESRGAN-NCNN..."); int scale = NcnnUtils.GetNcnnModelScale(currentNcnnModel); string opt = stayOpen ? "/K" : "/C"; string cmd = $"{opt} cd /D {Paths.esrganPath.Wrap()} & esrgan-ncnn-vulkan.exe -i {inpath.Wrap()} -o {outpath.Wrap()}" + $" -g {Config.GetInt("gpuId")} -m " + currentNcnnModel.Wrap() + " -s " + scale; Logger.Log("[CMD] " + cmd); Process ncnnProcess = OSUtils.NewProcess(!showWindow); ncnnProcess.StartInfo.Arguments = cmd; if (!showWindow) { ncnnProcess.OutputDataReceived += NcnnOutputHandler; ncnnProcess.ErrorDataReceived += NcnnOutputHandler; } Program.currentEsrganProcess = ncnnProcess; ncnnProcess.Start(); if (!showWindow) { ncnnProcess.BeginOutputReadLine(); ncnnProcess.BeginErrorReadLine(); } while (!ncnnProcess.HasExited) { await Task.Delay(50); } if (Upscale.currentMode == Upscale.UpscaleMode.Batch) { await Task.Delay(1000); Program.mainForm.SetProgress(100f, "[ESRGAN] Post-Processing..."); PostProcessingQueue.Stop(); } File.Delete(Paths.progressLogfile); }
static void RunCompact() { bool stayOpen = Config.GetInt("cmdDebugMode") == 2; string opt = "/C"; if (stayOpen) { opt = "/K"; } Process compact = OSUtils.NewProcess(false); compact.StartInfo.Arguments = $"{opt} compact /C /S:{extractPath.Wrap()}"; compact.Start(); Thread.Sleep(100); // <-- ugly hack https://stackoverflow.com/a/1016863/14274419 SetWindowText(compact.MainWindowHandle, "Compressing Python installation... Do not close this window!"); compact.WaitForExit(); }
public static string Interpolate(ModelData mdl) { bool showWindow = Config.GetInt("cmdDebugMode") > 0; bool stayOpen = Config.GetInt("cmdDebugMode") == 2; Process py = OSUtils.NewProcess(!showWindow); string opt = "/C"; if (stayOpen) { opt = "/K"; } string alphaStr = (mdl.interp / 100f).ToString("0.00").Replace(",", "."); string outPath = mdl.model1Path.GetParentDir(); string filename = $"{mdl.model1Name}-{mdl.model2Name}-interp{alphaStr}.pth"; outPath = Path.Combine(outPath, filename); string cmd = $"{opt} cd /D {Paths.esrganPath.Wrap()} & "; cmd += $"{EmbeddedPython.GetPyCmd()} interp.py {mdl.model1Path.Wrap()} {mdl.model2Path.Wrap()} {alphaStr} {outPath.Wrap()}"; py.StartInfo.Arguments = cmd; Logger.Log("[ESRGAN Interp] CMD: " + py.StartInfo.Arguments); py.Start(); py.WaitForExit(); string output = py.StandardOutput.ReadToEnd(); string err = py.StandardError.ReadToEnd(); if (!string.IsNullOrWhiteSpace(err)) { output += "\n" + err; } Logger.Log("[ESRGAN Interp] Output: " + output); if (output.ToLower().Contains("error")) { throw new Exception("Interpolation Error - Output:\n" + output); } return(outPath); }
static async Task RunConverter(string modelPath) { lastNcnnOutput = ""; bool showWindow = Config.GetInt("cmdDebugMode") > 0; bool stayOpen = Config.GetInt("cmdDebugMode") == 2; modelPath = modelPath.Wrap(); string opt = "/C"; if (stayOpen) { opt = "/K"; } string args = $"{opt} cd /D {Paths.esrganPath.Wrap()} & pth2ncnn.exe {modelPath}"; Logger.Log("[CMD] " + args); Process converterProc = OSUtils.NewProcess(!showWindow); converterProc.StartInfo.Arguments = args; if (!showWindow) { converterProc.OutputDataReceived += OutputHandler; converterProc.ErrorDataReceived += OutputHandler; } currentProcess = converterProc; converterProc.Start(); if (!showWindow) { converterProc.BeginOutputReadLine(); converterProc.BeginErrorReadLine(); } while (!converterProc.HasExited) { await Task.Delay(100); } File.Delete(Paths.progressLogfile); }
public static async Task RunJoey(string inpath, string outpath, string modelArg, bool cacheSplitDepth, bool alpha, bool showTileProgress) { bool showWindow = Config.GetInt("cmdDebugMode") > 0; bool stayOpen = Config.GetInt("cmdDebugMode") == 2; inpath = inpath.Wrap(); outpath = outpath.Wrap(); string alphaMode = alpha ? $"--alpha_mode {Config.GetInt("alphaMode")}" : "--alpha_mode 0"; string alphaDepth = ""; if (Config.GetInt("alphaDepth") == 1) { alphaDepth = "--binary_alpha"; } if (Config.GetInt("alphaDepth") == 2) { alphaDepth = "--ternary_alpha"; } string cpu = (Config.GetInt("cudaFallback") == 1 || Config.GetInt("cudaFallback") == 2) ? "--cpu" : ""; string device = $"--device_id {Config.GetInt("gpuId")}"; string seam = "--seamless "; switch (Config.GetInt("seamlessMode")) { case 1: seam += "tile"; break; case 2: seam += "mirror"; break; case 3: seam += "replicate"; break; case 4: seam += "alpha_pad"; break; } string cache = cacheSplitDepth ? "--cache_max_split_depth" : ""; string opt = stayOpen ? "/K" : "/C"; string cmd = $"{opt} cd /D {Paths.esrganPath.Wrap()} & "; cmd += $"{EmbeddedPython.GetPyCmd()} upscale.py --input {inpath} --output {outpath} {cache} {cpu} {device} {seam} {alphaMode} {alphaDepth} {modelArg}"; Logger.Log("[CMD] " + cmd); Process esrganProcess = OSUtils.NewProcess(!showWindow); esrganProcess.StartInfo.Arguments = cmd; if (!showWindow) { esrganProcess.OutputDataReceived += OutputHandler; esrganProcess.ErrorDataReceived += OutputHandler; } Program.currentEsrganProcess = esrganProcess; esrganProcess.Start(); if (!showWindow) { esrganProcess.BeginOutputReadLine(); esrganProcess.BeginErrorReadLine(); } while (!esrganProcess.HasExited) { if (showTileProgress) { await UpdateProgressFromFile(); } await Task.Delay(50); } if (Main.Upscale.currentMode == Main.Upscale.UpscaleMode.Batch) { await Task.Delay(1000); Program.mainForm.SetProgress(100f, "Post-Processing..."); PostProcessingQueue.Stop(); } File.Delete(Paths.progressLogfile); }