Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public static async Task RunNcnn(string inpath, string outpath, string modelPath)
        {
            bool showWindow = Config.GetInt("cmdDebugMode") > 0;
            bool stayOpen   = Config.GetInt("cmdDebugMode") == 2;

            inpath  = inpath.Wrap();
            outpath = outpath.Wrap();

            Program.mainForm.SetProgress(3f, "Converting NCNN model...");
            await NcnnUtils.ConvertNcnnModel(modelPath);

            Logger.Log("[ESRGAN] NCNN Model is ready: " + currentNcnnModel);
            Program.mainForm.SetProgress(4f, "Loading ESRGAN-NCNN...");
            int scale = NcnnUtils.GetNcnnModelScale(currentNcnnModel);

            string opt = "/C";

            if (stayOpen)
            {
                opt = "/K";
            }

            string cmd = $"{opt} cd /D {Paths.esrganPath.Wrap()} & ";

            cmd += "esrgan-ncnn-vulkan.exe -i " + inpath + " -o " + outpath + " -m " + currentNcnnModel.Wrap() + " -s " + scale;
            Logger.Log("[CMD] " + cmd);

            Process ncnnProcess = new Process();

            ncnnProcess.StartInfo.UseShellExecute        = showWindow;
            ncnnProcess.StartInfo.RedirectStandardOutput = !showWindow;
            ncnnProcess.StartInfo.RedirectStandardError  = !showWindow;
            ncnnProcess.StartInfo.CreateNoWindow         = !showWindow;
            ncnnProcess.StartInfo.FileName  = "cmd.exe";
            ncnnProcess.StartInfo.Arguments = cmd;
            if (!showWindow)
            {
                ncnnProcess.OutputDataReceived += NcnnOutputHandler;
                ncnnProcess.ErrorDataReceived  += NcnnOutputHandler;
            }
            currentProcess = 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);
        }