From 71b02a39de1fbf282e12486179b6262804e6e023 Mon Sep 17 00:00:00 2001 From: n00mkrad Date: Sun, 15 Aug 2021 11:37:41 +0200 Subject: [PATCH] XVFI test --- Code/Data/Implementations.cs | 2 ++ Code/Flowframes.csproj | 2 +- Code/Main/Interpolate.cs | 3 ++ Code/OS/AiProcess.cs | 63 +++++++++++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/Code/Data/Implementations.cs b/Code/Data/Implementations.cs index 7018381..9a4ad93 100644 --- a/Code/Data/Implementations.cs +++ b/Code/Data/Implementations.cs @@ -10,6 +10,7 @@ namespace Flowframes.Data public static AI rifeNcnn = new AI("RIFE_NCNN", "RIFE (NCNN)", "Vulkan/NCNN Implementation of RIFE", "rife-ncnn", false); public static AI flavrCuda = new AI("FLAVR_CUDA", "FLAVR", "Experimental Pytorch Implementation of FLAVR (Nvidia Only!)", "flavr-cuda", true); public static AI dainNcnn = new AI("DAIN_NCNN", "DAIN (NCNN)", "Vulkan/NCNN Implementation of DAIN", "dain-ncnn", true); + public static AI xvfiCuda = new AI("XVFI_CUDA", "XVFI", "CUDA / Pytorch Implementation of XVFI (Nvidia Only!)", "xvfi-cuda", true); public static List networks = new List(); @@ -20,6 +21,7 @@ namespace Flowframes.Data networks.Add(rifeNcnn); networks.Add(flavrCuda); networks.Add(dainNcnn); + networks.Add(xvfiCuda); } public static AI GetAi (string aiName) diff --git a/Code/Flowframes.csproj b/Code/Flowframes.csproj index cb3cf4b..9971593 100644 --- a/Code/Flowframes.csproj +++ b/Code/Flowframes.csproj @@ -339,7 +339,7 @@ - + diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index 23d97ff..d1b7290 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -190,6 +190,9 @@ namespace Flowframes if (ai.aiName == Implementations.dainNcnn.aiName) tasks.Add(AiProcess.RunDainNcnn(current.framesFolder, outpath, current.interpFactor, current.model.dir, Config.GetInt(Config.Key.dainNcnnTilesize, 512))); + if (ai.aiName == Implementations.xvfiCuda.aiName) + tasks.Add(AiProcess.RunXvfiCuda(current.framesFolder, current.interpFactor, current.model.dir)); + if (currentlyUsingAutoEnc) { Logger.Log($"{Logger.GetLastLine()} (Using Auto-Encode)", true); diff --git a/Code/OS/AiProcess.cs b/Code/OS/AiProcess.cs index 9aaab7e..d2ebcfc 100644 --- a/Code/OS/AiProcess.cs +++ b/Code/OS/AiProcess.cs @@ -208,7 +208,7 @@ namespace Flowframes string args = $" --input {inPath.Wrap()} --output {outPath.Wrap()} --model {mdl}/{mdl}.pth --factor {interpFactor}"; Process flavrPy = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd()); - AiStarted(flavrPy, 4500); + AiStarted(flavrPy, 4000); SetProgressCheck(Path.Combine(Interpolate.current.tempFolder, outDir), interpFactor); flavrPy.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {Path.Combine(Paths.GetPkgPath(), Implementations.flavrCuda.pkgDir).Wrap()} & " + $"set CUDA_VISIBLE_DEVICES={Config.Get(Config.Key.torchGpus)} & {Python.GetPyCmd()} {script} {args}"; @@ -364,6 +364,67 @@ namespace Flowframes await Task.Delay(100); } + public static async Task RunXvfiCuda(string framesPath, float interpFactor, string mdl) + { + if (Interpolate.currentlyUsingAutoEnc) // Ensure AutoEnc is not paused + AutoEncode.paused = false; + + try + { + string xvfiDir = Path.Combine(Paths.GetPkgPath(), Implementations.xvfiCuda.pkgDir); + string script = "main.py"; + + if (!File.Exists(Path.Combine(xvfiDir, script))) + { + Interpolate.Cancel("XVFI script not found! Make sure you didn't modify any files."); + return; + } + + await RunXvfiCudaProcess(framesPath, Paths.interpDir, script, interpFactor, mdl); + } + catch (Exception e) + { + Logger.Log("Error running XVFI-CUDA: " + e.Message); + } + + await AiFinished("XVFI"); + } + + public static async Task RunXvfiCudaProcess(string inPath, string outDir, string script, float interpFactor, string mdlDir) + { + string pkgPath = Path.Combine(Paths.GetPkgPath(), Implementations.xvfiCuda.pkgDir); + string basePath = inPath.GetParentDir(); + string outPath = Path.Combine(basePath, outDir); + Directory.CreateDirectory(outPath); + string mdlArgs = File.ReadAllText(Path.Combine(pkgPath, mdlDir, "args.txt")); + string args = $" --custom_path {basePath} --input {inPath.Wrap()} --output {outPath.Wrap()} --mdl_dir {mdlDir}" + + $" --multiple {interpFactor} --gpu 0 {mdlArgs}"; + + Process xvfiPy = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd()); + AiStarted(xvfiPy, 4500); + SetProgressCheck(Path.Combine(Interpolate.current.tempFolder, outDir), interpFactor); + xvfiPy.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {pkgPath.Wrap()} & " + + $"set CUDA_VISIBLE_DEVICES={Config.Get(Config.Key.torchGpus)} & {Python.GetPyCmd()} {script} {args}"; + Logger.Log($"Running XVFI (CUDA)...", false); + Logger.Log("cmd.exe " + xvfiPy.StartInfo.Arguments, true); + + if (!OSUtils.ShowHiddenCmd()) + { + xvfiPy.OutputDataReceived += (sender, outLine) => { LogOutput(outLine.Data, "xvfi-cuda-log"); }; + xvfiPy.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "xvfi-cuda-log", true); }; + } + + xvfiPy.Start(); + + if (!OSUtils.ShowHiddenCmd()) + { + xvfiPy.BeginOutputReadLine(); + xvfiPy.BeginErrorReadLine(); + } + + while (!xvfiPy.HasExited) await Task.Delay(1); + } + static void LogOutput (string line, string logFilename, bool err = false) { if (string.IsNullOrWhiteSpace(line) || line.Length < 6)