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); }
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); }
public static async Task Run(string inpath, string outpath, string modelArg, string tilesize, bool alpha, bool showTileProgress) { bool showWindow = Config.GetInt("cmdDebugMode") > 0; bool stayOpen = Config.GetInt("cmdDebugMode") == 2; inpath = inpath.Wrap(true, true); outpath = outpath.Wrap(true, true); string alphaStr = " --noalpha"; if (alpha) { alphaStr = ""; } string deviceStr = " --device cuda"; if (Config.Get("cudaFallback").GetInt() == 1 || Config.Get("cudaFallback").GetInt() == 2) { deviceStr = " --device cpu"; } 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}"; Logger.Log("[CMD] " + cmd); Process esrganProcess = new Process(); esrganProcess.StartInfo.UseShellExecute = showWindow; esrganProcess.StartInfo.RedirectStandardOutput = !showWindow; esrganProcess.StartInfo.RedirectStandardError = !showWindow; esrganProcess.StartInfo.CreateNoWindow = !showWindow; esrganProcess.StartInfo.FileName = "cmd.exe"; 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); }