Пример #1
0
        public static bool CheckAiAvailable(AI ai)
        {
            if (!PkgUtils.IsAiAvailable(ai))
            {
                ShowMessage("The selected AI is not installed!", "Error");
                I.Cancel("Selected AI not available.", true);
                return(false);
            }

            if (I.current.ai.aiName.ToUpper().Contains("CUDA") && NvApi.gpuList.Count < 1)
            {
                ShowMessage("An Nvidia GPU is required for CUDA implementations!\n\nTry an NCNN implementation instead.", "Error");
                I.Cancel("No CUDA-capable graphics card available.", true);
                return(false);
            }

            return(true);
        }
Пример #2
0
        static async Task RunRifeNcnnProcess(string inPath, string outPath, string mdl)
        {
            Directory.CreateDirectory(outPath);
            Process rifeNcnn = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());

            AiStarted(rifeNcnn, 1500, inPath);
            SetProgressCheck(outPath, 2);

            string uhdStr = await InterpolateUtils.UseUHD() ? "-u" : "";

            string ttaStr = Config.GetBool("rifeNcnnUseTta", false) ? "-x" : "";

            string oldMdlName = mdl;

            mdl = RifeNcnn2Workaround(mdl);     // TODO: REMOVE ONCE NIHUI HAS GOTTEN RID OF THE SHITTY HARDCODED VERSION CHECK

            rifeNcnn.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeNcnn).Wrap()} & rife-ncnn-vulkan.exe " +
                                           $" -v -i {inPath.Wrap()} -o {outPath.Wrap()} -m {mdl.ToLower()} {ttaStr} {uhdStr} -g {Config.Get("ncnnGpus")} -f {GetNcnnPattern()} -j {GetNcnnThreads()}";

            Logger.Log("cmd.exe " + rifeNcnn.StartInfo.Arguments, true);

            if (!OSUtils.ShowHiddenCmd())
            {
                rifeNcnn.OutputDataReceived += (sender, outLine) => { LogOutput("[O] " + outLine.Data, "rife-ncnn-log"); };
                rifeNcnn.ErrorDataReceived  += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "rife-ncnn-log", true); };
            }

            rifeNcnn.Start();

            if (!OSUtils.ShowHiddenCmd())
            {
                rifeNcnn.BeginOutputReadLine();
                rifeNcnn.BeginErrorReadLine();
            }

            while (!rifeNcnn.HasExited)
            {
                await Task.Delay(1);
            }
            RifeNcnn2Workaround(oldMdlName, true);
        }
Пример #3
0
        static bool EntryIsValid(InterpSettings entry)
        {
            if (entry.inPath == null || (IOUtils.IsPathDirectory(entry.inPath) && !Directory.Exists(entry.inPath)) || (!IOUtils.IsPathDirectory(entry.inPath) && !File.Exists(entry.inPath)))
            {
                Logger.Log("[Queue] Can't process queue entry: Input path is invalid.");
                return(false);
            }

            if (entry.outPath == null || !Directory.Exists(entry.outPath))
            {
                Logger.Log("[Queue] Can't process queue entry: Output path is invalid.");
                return(false);
            }

            if (!PkgUtils.IsAiAvailable(entry.ai))
            {
                Logger.Log("[Queue] Can't process queue entry: Selected AI is not available.");
                return(false);
            }

            return(true);
        }
Пример #4
0
        public static ComboBox FillAiModelsCombox(ComboBox combox, AI ai)
        {
            combox.Items.Clear();

            try
            {
                string   pkgPath       = PkgUtils.GetPkgFolder(ai.pkg);
                string   modelsFile    = Path.Combine(pkgPath, "models.txt");
                string[] modelsWithDec = IOUtils.ReadLines(modelsFile);

                for (int i = 0; i < modelsWithDec.Length; i++)
                {
                    string model = modelsWithDec[i];

                    if (string.IsNullOrWhiteSpace(model))
                    {
                        continue;
                    }

                    combox.Items.Add(model);

                    if (model.Contains("Recommended") || model.Contains("Default"))
                    {
                        combox.SelectedIndex = i;
                    }
                }

                if (combox.SelectedIndex < 0)
                {
                    combox.SelectedIndex = 0;
                }
            }
            catch (Exception e)
            {
                Logger.Log($"Failed to load available AI models for {ai.aiName}! {e.Message}");
            }

            return(combox);
        }
Пример #5
0
        public static async Task RunRifeCudaProcess(string inPath, string outDir, string script, float interpFactor, string mdl)
        {
            //bool parallel = false;
            string outPath  = Path.Combine(inPath.GetParentDir(), outDir);
            string wthreads = $"--wthreads {2 * (int)interpFactor}";
            string rbuffer  = $"--rbuffer {Config.GetInt("rifeCudaBufferSize", 200)}";
            string scale    = $"--scale {Config.GetFloat("rifeCudaScale", 1.0f).ToStringDot()}";
            string prec     = Config.GetBool("rifeCudaFp16") ? "--fp16" : "";
            string args     = $" --input {inPath.Wrap()} --output {outDir} --model {mdl} --exp {(int)Math.Log(interpFactor, 2)} {scale} {wthreads} {rbuffer} {prec}";
            // if (parallel) args = $" --input {inPath.Wrap()} --output {outPath} --model {mdl} --factor {interpFactor}";
            // if (parallel) script = "rife-parallel.py";

            Process rifePy = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());

            AiStarted(rifePy, 3500);
            SetProgressCheck(Path.Combine(Interpolate.current.tempFolder, outDir), interpFactor);
            rifePy.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeCuda).Wrap()} & " +
                                         $"set CUDA_VISIBLE_DEVICES={Config.Get("torchGpus")} & {Python.GetPyCmd()} {script} {args}";
            Logger.Log($"Running RIFE (CUDA)...".TrimWhitespaces(), false);
            Logger.Log("cmd.exe " + rifePy.StartInfo.Arguments, true);

            if (!OSUtils.ShowHiddenCmd())
            {
                rifePy.OutputDataReceived += (sender, outLine) => { LogOutput(outLine.Data, "rife-cuda-log"); };
                rifePy.ErrorDataReceived  += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "rife-cuda-log", true); };
            }
            rifePy.Start();
            if (!OSUtils.ShowHiddenCmd())
            {
                rifePy.BeginOutputReadLine();
                rifePy.BeginErrorReadLine();
            }

            while (!rifePy.HasExited)
            {
                await Task.Delay(1);
            }
        }