Example #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);
        }
Example #2
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);
        }