From 8d2aa66cf70987d706e1ebdff1dc1907a4f014dd Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Wed, 13 Jan 2021 22:50:34 +0100 Subject: [PATCH] Fixed NCNN progress bar bug, removed DAIN/CAIN code --- Code/Data/InterpSettings.cs | 12 ++++ Code/Main/Interpolate.cs | 17 ++---- Code/Main/InterpolateSteps.cs | 3 +- Code/Main/InterpolateUtils.cs | 1 - Code/OS/AiProcess.cs | 102 ++-------------------------------- 5 files changed, 22 insertions(+), 113 deletions(-) diff --git a/Code/Data/InterpSettings.cs b/Code/Data/InterpSettings.cs index 8c5c8e9..9dcebb3 100644 --- a/Code/Data/InterpSettings.cs +++ b/Code/Data/InterpSettings.cs @@ -92,5 +92,17 @@ namespace Flowframes scaledResolution = InterpolateUtils.GetOutputResolution(inputResolution, false); } } + + public int GetTargetFrameCount(string overrideInputDir = "", int overrideFactor = -1) + { + if (framesFolder == null || !Directory.Exists(framesFolder)) + return 0; + + string framesDir = (!string.IsNullOrWhiteSpace(overrideInputDir)) ? overrideInputDir : framesFolder; + int frames = IOUtils.GetAmountOfFiles(framesDir, false, "*.png"); + int factor = (overrideFactor > 0) ? overrideFactor : interpFactor; + int targetFrameCount = (frames * factor) - (interpFactor - 1); + return targetFrameCount; + } } } diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index c99b0cb..f1512df 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -54,12 +54,8 @@ namespace Flowframes await Task.Delay(10); await PostProcessFrames(); if (canceled) return; - int frames = IOUtils.GetAmountOfFiles(current.framesFolder, false, "*.png"); - int targetFrameCount = (frames * current.interpFactor) - (current.interpFactor - 1); - Utils.GetProgressByFrameAmount(current.interpFolder, targetFrameCount); - if (canceled) return; Program.mainForm.SetStatus("Running AI..."); - await RunAi(current.interpFolder, targetFrameCount, current.tilesize, current.ai); + await RunAi(current.interpFolder, current.ai); if (canceled) return; Program.mainForm.SetProgress(100); if(!currentlyUsingAutoEnc) @@ -144,7 +140,7 @@ namespace Flowframes AiProcess.filenameMap = IOUtils.RenameCounterDirReversible(current.framesFolder, "png", 1, 8); } - public static async Task RunAi(string outpath, int targetFrames, int tilesize, AI ai, bool stepByStep = false) + public static async Task RunAi(string outpath, AI ai, bool stepByStep = false) { currentlyUsingAutoEnc = Utils.UseAutoEnc(stepByStep, current); @@ -152,23 +148,18 @@ namespace Flowframes List tasks = new List(); - if (ai.aiName == Networks.dainNcnn.aiName) - tasks.Add(AiProcess.RunDainNcnn(current.framesFolder, outpath, targetFrames, tilesize)); - - if (ai.aiName == Networks.cainNcnn.aiName) - tasks.Add(AiProcess.RunCainNcnnMulti(current.framesFolder, outpath, tilesize, current.interpFactor)); - if (ai.aiName == Networks.rifeCuda.aiName) tasks.Add(AiProcess.RunRifeCuda(current.framesFolder, current.interpFactor)); if (ai.aiName == Networks.rifeNcnn.aiName) - tasks.Add(AiProcess.RunRifeNcnnMulti(current.framesFolder, outpath, tilesize, current.interpFactor)); + tasks.Add(AiProcess.RunRifeNcnnMulti(current.framesFolder, outpath, current.interpFactor)); if (currentlyUsingAutoEnc) { Logger.Log($"{Logger.GetLastLine()} (Using Auto-Encode)", true); tasks.Add(AutoEncode.MainLoop(outpath)); } + await Task.WhenAll(tasks); } diff --git a/Code/Main/InterpolateSteps.cs b/Code/Main/InterpolateSteps.cs index 2642725..d6f1bfb 100644 --- a/Code/Main/InterpolateSteps.cs +++ b/Code/Main/InterpolateSteps.cs @@ -117,11 +117,10 @@ namespace Flowframes.Main int frames = IOUtils.GetAmountOfFiles(current.framesFolder, false, "*.png"); int targetFrameCount = frames * current.interpFactor; - InterpolateUtils.GetProgressByFrameAmount(current.interpFolder, targetFrameCount); if (canceled) return; Program.mainForm.SetStatus("Running AI..."); int tilesize = current.ai.supportsTiling ? Config.GetInt($"tilesize_{current.ai.aiName}") : 512; - await RunAi(current.interpFolder, targetFrameCount, tilesize, current.ai, true); + await RunAi(current.interpFolder, current.ai, true); Program.mainForm.SetProgress(0); } diff --git a/Code/Main/InterpolateUtils.cs b/Code/Main/InterpolateUtils.cs index 671c7bb..7375046 100644 --- a/Code/Main/InterpolateUtils.cs +++ b/Code/Main/InterpolateUtils.cs @@ -38,7 +38,6 @@ namespace Flowframes.Main bool firstProgUpd = true; Program.mainForm.SetProgress(0); targetFrames = target; - Logger.Log("Skipping progress count because program is not busy!!", true); while (Program.busy) { if (AiProcess.processTime.IsRunning && Directory.Exists(outdir)) diff --git a/Code/OS/AiProcess.cs b/Code/OS/AiProcess.cs index 133ace0..ad1dd19 100644 --- a/Code/OS/AiProcess.cs +++ b/Code/OS/AiProcess.cs @@ -68,104 +68,10 @@ namespace Flowframes } } - public static async Task RunDainNcnn(string framesPath, string outPath, int targetFrames, int tilesize) - { - string args = $" -v -i {framesPath.Wrap()} -o {outPath.Wrap()} -n {targetFrames} -t {GetNcnnTilesize(tilesize)} -g {Config.Get("ncnnGpus")}"; - - string dainDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.dainNcnn.fileName)); - Process dain = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd()); - AiStarted(dain, 1500, Interpolate.current.interpFactor); - dain.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {dainDir.Wrap()} & dain-ncnn-vulkan.exe {args} -f {InterpolateUtils.GetOutExt()} -j {GetNcnnThreads()}".TrimWhitespacesSafe(); - Logger.Log("Running DAIN...", false); - Logger.Log("cmd.exe " + dain.StartInfo.Arguments, true); - if (!OSUtils.ShowHiddenCmd()) - { - dain.OutputDataReceived += (sender, outLine) => { LogOutput("[O] " + outLine.Data, "dain-ncnn-log"); }; - dain.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "dain-ncnn-log"); }; - } - dain.Start(); - if (!OSUtils.ShowHiddenCmd()) - { - dain.BeginOutputReadLine(); - dain.BeginErrorReadLine(); - } - while (!dain.HasExited) - await Task.Delay(1); - - if (Interpolate.canceled) return; - - if (!Interpolate.currentlyUsingAutoEnc) - IOUtils.ZeroPadDir(outPath, InterpolateUtils.GetOutExt(), Padding.interpFrames); - - AiFinished("DAIN"); - } - - public static async Task RunCainNcnnMulti (string framesPath, string outPath, int tilesize, int times) - { - processTimeMulti.Restart(); - Logger.Log("Running CAIN...", false); - - string args = $" -v -i {framesPath.Wrap()} -o {outPath.Wrap()} -g {Config.Get("ncnnGpus")}"; - await RunCainPartial(args); - - if(times == 4 || times == 8) // #2 - { - if (Interpolate.canceled) return; - Logger.Log("Re-Running CAIN for 4x interpolation...", false); - string run1ResultsPath = outPath + "-run1"; - IOUtils.TryDeleteIfExists(run1ResultsPath); - Directory.Move(outPath, run1ResultsPath); - Directory.CreateDirectory(outPath); - args = $" -v -i {run1ResultsPath.Wrap()} -o {outPath.Wrap()} -g {Config.Get("ncnnGpus")}"; - await RunCainPartial(args); - IOUtils.TryDeleteIfExists(run1ResultsPath); - } - - if (times == 8) // #3 - { - if (Interpolate.canceled) return; - Logger.Log("Re-Running CAIN for 8x interpolation...", false); - string run2ResultsPath = outPath + "-run2"; - IOUtils.TryDeleteIfExists(run2ResultsPath); - Directory.Move(outPath, run2ResultsPath); - Directory.CreateDirectory(outPath); - args = $" -v -i {run2ResultsPath.Wrap()} -o {outPath.Wrap()} -g {Config.Get("ncnnGpus")}"; - await RunCainPartial(args); - IOUtils.TryDeleteIfExists(run2ResultsPath); - } - - if (Interpolate.canceled) return; - - if (!Interpolate.currentlyUsingAutoEnc) - IOUtils.ZeroPadDir(outPath, InterpolateUtils.GetOutExt(), Padding.interpFrames); - - AiFinished("CAIN"); - } - - static async Task RunCainPartial (string args) - { - string cainDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.cainNcnn.fileName)); - string cainExe = "cain-ncnn-vulkan.exe"; - Process cain = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd()); - AiStarted(cain, 1500, 2); - cain.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {cainDir.Wrap()} & {cainExe} {args} -f {InterpolateUtils.GetOutExt()} -j {GetNcnnThreads()}".TrimWhitespacesSafe(); - Logger.Log("cmd.exe " + cain.StartInfo.Arguments, true); - if (!OSUtils.ShowHiddenCmd()) - { - cain.OutputDataReceived += (sender, outLine) => { LogOutput("[O] " + outLine.Data, "cain-ncnn-log"); }; - cain.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "cain-ncnn-log"); }; - } - cain.Start(); - if (!OSUtils.ShowHiddenCmd()) - { - cain.BeginOutputReadLine(); - cain.BeginErrorReadLine(); - } - while (!cain.HasExited) await Task.Delay(1); - } - public static async Task RunRifeCuda(string framesPath, int interpFactor) { + InterpolateUtils.GetProgressByFrameAmount(Interpolate.current.interpFolder, Interpolate.current.GetTargetFrameCount(framesPath, interpFactor)); + string rifeDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.rifeCuda.fileName)); string script = "inference_video.py"; string uhdStr = InterpolateUtils.UseUHD() ? "--UHD" : ""; @@ -198,7 +104,7 @@ namespace Flowframes AiFinished("RIFE"); } - public static async Task RunRifeNcnnMulti(string framesPath, string outPath, int tilesize, int times) + public static async Task RunRifeNcnnMulti(string framesPath, string outPath, int times) { processTimeMulti.Restart(); Logger.Log($"Running RIFE{(InterpolateUtils.UseUHD() ? " (UHD Mode)" : "")}...", false); @@ -247,6 +153,8 @@ namespace Flowframes static async Task RunRifePartial(string inPath, string outPath) { + InterpolateUtils.GetProgressByFrameAmount(Interpolate.current.interpFolder, Interpolate.current.GetTargetFrameCount(inPath, 2)); + Process rifeNcnn = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd()); AiStarted(rifeNcnn, 1500, 2, inPath);