Beispiel #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);
        }
Beispiel #2
0
        public string Resolve()
        {
            foreach (var input in Inputs.Values)
            {
                if (!(input is IBoundInput))
                {
                    throw new InvalidOperationException("Cannot resolve the template while some inputs remain unbound.");
                }
            }
            var resolvedTokens = from tokRef in TokenSequence.AsEnumerable
                                 let tok = Tokens[tokRef.Key]
                                           let resolvedTok = (tok as IResolvedToken) ?? ((IUnresolvedToken)tok).Resolve(this)
                                                             select resolvedTok.Value;

            return((string)PostProcessingQueue.Invoke(string.Join("", resolvedTokens)));
        }
 void OnMainWindowClosed(object sender, FormClosedEventArgs e)
 {
     lock (shutdownLock) {
         if (shutdown)
         {
             return;
         }
         shutdown = true;
     }
     Cef.Shutdown();
     logger.Flush();
     logger.Dispose();
     Playlist.Terminate();
     UiSettings.Terminate();
     AppSettings.Terminate();
     ThemeSettings.Terminate();
     DownloadQueue.Terminate();
     PostProcessingQueue.Terminate();
 }
        void OnMainWindowShown(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }
            var app = AppSettings.Instance;

            InitializeLog();
            SearchEngine.Initialize(app.Providers.Keys.Where(k => app.Providers[k].Enabled));
            string[] stopList = File.ReadAllLines(AppSettings.StopListPath)
                                .Select(s => s.Trim())
                                .Where(s => !string.IsNullOrWhiteSpace(s))
                                .ToArray();
            Library.Initialize(AppSettings.GetFolderPath(), stopList);
            InitializeSettings();
            Playlist.Initialize();
            DownloadQueue.Initialize();
            PostProcessingQueue.Initialize();
            uiDownloadQueue.Initialize(DownloadQueue.Instance);
            uiPostProcessingQueue.Initialize(PostProcessingQueue.Instance);
            Action <QueueItem> enqueue = r => uiPostProcessingQueue.Enqueue(r.NewId());

            DownloadQueue.Instance.Completed += (s, evt) => BeginInvoke(new Action(() => enqueue(evt.Data)));
            if (app.UpdateLibraryAfterDownload)
            {
                PostProcessingQueue.Instance.Completed += (s, evt) => LibraryScanner.UpdateLibrary();
            }
            uiCurrentResult.SetResult(UiSettings.Instance.CurrentTrack);
            StartSearch();
            DownloadQueue.Start();
            PostProcessingQueue.Start();
            InitializePlaylist();
            InitializeSuggestions();
            SuggestionScanner.Suggested += OnScannerSuggestions;
            SuggestionScanner.Start(app.DelaySuggestionsScan, app.ScanSuggestionsInterval);
            LibraryScanner.Start(UserSettings.Instance.LibraryFolder, app.TagSeparator, app.DelayLibraryScan, app.ScanLibraryInterval);
            ShowScrollBar(uiResults.Handle, SbVert, true);
            ShowScrollBar(uiPlaylist.Handle, SbVert, true);
            initializing = false;
        }
Beispiel #5
0
        public static async Task Run(bool preprocess, bool postProcess = true, string overrideOutDir = "")
        {
            int  cudaFallback = Config.Get("cudaFallback").GetInt();
            bool useNcnn      = (cudaFallback == 2 || cudaFallback == 3);
            bool useCpu       = (cudaFallback == 1);

            string imgOutDir = outDir.Text.Trim();

            if (!string.IsNullOrWhiteSpace(overrideOutDir))
            {
                imgOutDir = overrideOutDir;
            }

            if (useNcnn && !Program.mainForm.HasValidNcnnModelSelection())
            {
                Program.ShowMessage("Invalid model selection - NCNN does not support interpolation or chaining.", "Error");
                return;
            }
            if (string.IsNullOrWhiteSpace(currentInDir) && (currentInFiles == null || currentInFiles.Length < 1))
            {
                Program.ShowMessage("No directory or files loaded.", "Error");
                return;
            }
            if (!IOUtils.HasEnoughDiskSpace(8192, imgOutDir.Substring(0, 2), 2.0f))
            {
                Program.ShowMessage($"Not enough disk space on {IOUtils.GetAppDataDir().Substring(0, 3)} to store temporary files!", "Error");
                return;
            }
            Upscale.currentMode = Upscale.UpscaleMode.Batch;
            Program.mainForm.SetBusy(true);
            Program.mainForm.SetProgress(2f, "Loading images...");
            await Task.Delay(20);

            Directory.CreateDirectory(imgOutDir);
            await CopyCompatibleImagesToTemp();

            Program.mainForm.SetProgress(3f, "Pre-Processing...");
            if (preprocess)
            {
                await ImageProcessing.PreProcessImages(Paths.imgInPath, !bool.Parse(Config.Get("alpha")));
            }
            else
            {
                IOUtils.AppendToFilenames(Paths.imgInPath, ".png");
            }
            ModelData mdl = Upscale.GetModelData();

            GetProgress(Paths.imgOutPath, IOUtils.GetAmountOfFiles(Paths.imgInPath, true));

            if (postProcess)
            {
                PostProcessingQueue.Start(imgOutDir);
            }

            List <Task> tasks = new List <Task>();

            ESRGAN.Backend backend = ESRGAN.Backend.CUDA;
            if (useCpu)
            {
                backend = ESRGAN.Backend.CPU;
            }
            if (useNcnn)
            {
                backend = ESRGAN.Backend.NCNN;
            }
            tasks.Add(ESRGAN.DoUpscale(Paths.imgInPath, Paths.imgOutPath, mdl, Config.Get("tilesize"), bool.Parse(Config.Get("alpha")), ESRGAN.PreviewMode.None, backend, false));
            if (postProcess)
            {
                tasks.Add(PostProcessingQueue.Update());
                tasks.Add(PostProcessingQueue.ProcessQueue());
            }
            sw.Restart();
            await Task.WhenAll(tasks);

            if (!Program.cancelled)
            {
                Program.mainForm.SetProgress(0, $"Done - Upscaling took {(sw.ElapsedMilliseconds / 1000f).ToString("0")}s");
            }
            Program.mainForm.SetBusy(false);
        }
 public FluTeCorePrototype AttachPostProcessingStep(IProcessingStep step)
 {
     return(new FluTeCorePrototype(Tokens, TokenSequence, Inputs, PostProcessingQueue.Extend(step)));
 }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }