Fixed NCNN progress bar bug, removed DAIN/CAIN code

This commit is contained in:
N00MKRAD
2021-01-13 22:50:34 +01:00
parent 561aca4eee
commit 8d2aa66cf7
5 changed files with 22 additions and 113 deletions

View File

@@ -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;
}
}
}

View File

@@ -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<Task> tasks = new List<Task>();
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);
}

View File

@@ -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);
}

View File

@@ -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))

View File

@@ -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);