Fixed autoenc problem, RunRifeCuda now works with old and new scripts

This commit is contained in:
N00MKRAD
2020-12-03 14:53:18 +01:00
parent 9bfb785fc5
commit 0fb7b2cca3
3 changed files with 21 additions and 10 deletions

View File

@@ -97,10 +97,10 @@ namespace Flowframes
return Regex.Split(str, "\r\n|\r|\n"); return Regex.Split(str, "\r\n|\r|\n");
} }
public static string Trunc(this string value, int maxChars, bool addEllipsis = true) public static string Trunc(this string inStr, int maxChars, bool addEllipsis = true)
{ {
string str = value.Length <= maxChars ? value : value.Substring(0, maxChars); string str = inStr.Length <= maxChars ? inStr : inStr.Substring(0, maxChars);
if(addEllipsis) if(addEllipsis && inStr.Length > maxChars)
str += "…"; str += "…";
return str; return str;
} }

View File

@@ -144,6 +144,7 @@ namespace Flowframes
public static async Task PostProcessFrames (bool sbsMode = false) public static async Task PostProcessFrames (bool sbsMode = false)
{ {
bool firstFrameFix = (!sbsMode && lastAi.aiName == Networks.rifeCuda.aiName) || (sbsMode && InterpolateSteps.currentAi.aiName == Networks.rifeCuda.aiName); bool firstFrameFix = (!sbsMode && lastAi.aiName == Networks.rifeCuda.aiName) || (sbsMode && InterpolateSteps.currentAi.aiName == Networks.rifeCuda.aiName);
//firstFrameFix = false; // TODO: Remove firstframefix if new rife code works
if (!Directory.Exists(currentFramesPath) || IOUtils.GetAmountOfFiles(currentFramesPath, false, "*.png") <= 0) if (!Directory.Exists(currentFramesPath) || IOUtils.GetAmountOfFiles(currentFramesPath, false, "*.png") <= 0)
{ {
@@ -182,8 +183,10 @@ namespace Flowframes
public static async Task RunAi(string outpath, int targetFrames, int tilesize, AI ai) public static async Task RunAi(string outpath, int targetFrames, int tilesize, AI ai)
{ {
currentlyUsingAutoEnc = IOUtils.GetAmountOfFiles(currentFramesPath, false) >= (AutoEncode.chunkSize + AutoEncode.safetyBufferFrames) * 1.2f; currentlyUsingAutoEnc = IOUtils.GetAmountOfFiles(currentFramesPath, false) * lastInterpFactor >= (AutoEncode.chunkSize + AutoEncode.safetyBufferFrames) * 1.2f;
//Logger.Log("Using autoenc if there's more than " + (AutoEncode.chunkSize + AutoEncode.safetyBufferFrames) * 1.2f + " input frames, got " + IOUtils.GetAmountOfFiles(currentFramesPath, false) * lastInterpFactor);
currentlyUsingAutoEnc = false;
Directory.CreateDirectory(outpath); Directory.CreateDirectory(outpath);
List<Task> tasks = new List<Task>(); List<Task> tasks = new List<Task>();
@@ -200,8 +203,8 @@ namespace Flowframes
if (ai.aiName == Networks.rifeNcnn.aiName) if (ai.aiName == Networks.rifeNcnn.aiName)
tasks.Add(AiProcess.RunRifeNcnnMulti(currentFramesPath, outpath, tilesize, interpFactor)); tasks.Add(AiProcess.RunRifeNcnnMulti(currentFramesPath, outpath, tilesize, interpFactor));
//if(currentlyUsingAutoEnc) if(currentlyUsingAutoEnc)
// tasks.Add(AutoEncode.MainLoop(outpath)); tasks.Add(AutoEncode.MainLoop(outpath));
await Task.WhenAll(tasks); await Task.WhenAll(tasks);
} }

View File

@@ -139,13 +139,21 @@ namespace Flowframes
public static async Task RunRifeCuda(string framesPath, int interpFactor) public static async Task RunRifeCuda(string framesPath, int interpFactor)
{ {
string script = "interp-parallel.py"; string script = "interp-parallel.py";
if(Config.GetInt("rifeMode") == 0 || IOUtils.GetAmountOfFiles(framesPath, false) < 6) //if(Config.GetInt("rifeMode") == 0 || IOUtils.GetAmountOfFiles(framesPath, false) < 6)
script = "interp-basic.py"; // script = "interp-basic.py";
string rifeDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.rifeCuda.fileName)); string rifeDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.rifeCuda.fileName));
string args = $" --input {framesPath.Wrap()} --times {(int)Math.Log(interpFactor, 2)}";
if (File.Exists(Path.Combine(rifeDir, "inference_video.py"))) // Use updated script
{
script = "inference_video.py";
args = $" --img {framesPath.Wrap()} --exp {(int)Math.Log(interpFactor, 2)}";
}
Process rifePy = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd()); Process rifePy = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());
AiStarted(rifePy, 3000, "png"); AiStarted(rifePy, 3000, "png");
string args = $" --input {framesPath.Wrap()} --times {(int)Math.Log(interpFactor, 2)}";
rifePy.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeCuda).Wrap()} & " + rifePy.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeCuda).Wrap()} & " +
$"set CUDA_VISIBLE_DEVICES={Config.Get("torchGpus")} & {Pytorch.GetPyCmd()} {script} {args} --imgformat {InterpolateUtils.lastExt} --output {Paths.interpDir}"; $"set CUDA_VISIBLE_DEVICES={Config.Get("torchGpus")} & {Pytorch.GetPyCmd()} {script} {args} --imgformat {InterpolateUtils.lastExt} --output {Paths.interpDir}";
Logger.Log($"Running RIFE ({script})...", false); Logger.Log($"Running RIFE ({script})...", false);