Save fixed factors for specific AI models in models.json

This commit is contained in:
n00mkrad 2022-07-27 15:18:37 +02:00
parent a0b145ae0d
commit 233f037716
15 changed files with 86 additions and 64 deletions

View File

@ -39,7 +39,7 @@ namespace Flowframes.Data
Backend = AI.AiBackend.Pytorch,
NameInternal = "FLAVR_CUDA",
NameLong = "Flow-Agnostic Video Representations",
FactorSupport = AI.InterpFactorSupport.AnyFloat,
FactorSupport = AI.InterpFactorSupport.Fixed,
SupportedFactors = new int[] { 2, 4, 8 },
};
@ -75,7 +75,7 @@ namespace Flowframes.Data
{
get
{
return new List<AI> { rifeCuda, rifeNcnnVs, rifeNcnn, flavrCuda, dainNcnn, xvfiCuda, ifrnetNcnn };
return new List<AI> { rifeNcnnVs, rifeNcnn, rifeCuda, flavrCuda, dainNcnn, xvfiCuda, ifrnetNcnn };
}
}

View File

@ -181,7 +181,7 @@ namespace Flowframes
{
try
{
bool alphaModel = model.supportsAlpha;
bool alphaModel = model.SupportsAlpha;
bool png = outMode == Interpolate.OutMode.ImgPng;
bool gif = outMode == Interpolate.OutMode.VidGif;
bool proResAlpha = outMode == Interpolate.OutMode.VidProRes && Config.GetInt(Config.Key.proResProfile) > 3;
@ -240,7 +240,7 @@ namespace Flowframes
s += $"OUTFPS|{outFps}\n";
s += $"INTERPFACTOR|{interpFactor}\n";
s += $"OUTMODE|{outMode}\n";
s += $"MODEL|{model.name}\n";
s += $"MODEL|{model.Name}\n";
s += $"INPUTRES|{InputResolution.Width}x{InputResolution.Height}\n";
s += $"OUTPUTRES|{ScaledResolution.Width}x{ScaledResolution.Height}\n";
s += $"ALPHA|{alpha}\n";

View File

@ -1,58 +1,54 @@
using Flowframes.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Flowframes.Data
{
public class ModelCollection
{
public AI ai;
public List<ModelInfo> models = new List<ModelInfo>();
public AI Ai { get; set; } = null;
public List<ModelInfo> Models { get; set; } = new List<ModelInfo>();
public class ModelInfo
{
public AI ai;
public string name;
public string desc;
public string dir;
public bool supportsAlpha;
public bool isDefault;
public AI Ai { get; set; } = null;
public string Name { get; set; } = "";
public string Desc { get; set; } = "";
public string Dir { get; set; } = "";
public bool SupportsAlpha { get; set; } = false;
public bool IsDefault { get; set; } = false;
private int[] _fixedFactors = null;
public int[] FixedFactors { get { return _fixedFactors == null ? new int[0] : _fixedFactors; } set { _fixedFactors = value; } }
public ModelInfo(AI ai, string name, string desc, string dir, bool supportsAlpha, bool isDefault)
{
this.ai = ai;
this.name = name;
this.desc = desc;
this.dir = dir;
this.supportsAlpha = supportsAlpha;
this.isDefault = isDefault;
}
public ModelInfo() { }
public string GetUiString()
{
return $"{name} - {desc}{(supportsAlpha ? " (Supports Transparency)" : "")}{(isDefault ? " (Recommended)" : "")}";
return $"{Name} - {Desc}{(SupportsAlpha ? " (Supports Transparency)" : "")}{(FixedFactors.Count() > 0 ? $" ({GetFactorsString()})" : "")}{(IsDefault ? " (Recommended)" : "")}";
}
public override string ToString()
public string GetFactorsString ()
{
return $"{name} - {desc} ({dir}){(supportsAlpha ? " (Supports Transparency)" : "")}{(isDefault ? " (Recommended)" : "")}";
return string.Join(", ", FixedFactors.Select(x => $"{x}x"));
}
}
public ModelCollection(AI ai)
{
this.ai = ai;
Ai = ai;
}
public ModelCollection(AI ai, string jsonContentOrPath)
{
this.ai = ai;
Ai = ai;
if (IoUtils.IsPathValid(jsonContentOrPath) && File.Exists(jsonContentOrPath))
jsonContentOrPath = File.ReadAllText(jsonContentOrPath);
models = new List<ModelInfo>();
Models = new List<ModelInfo>();
dynamic data = JsonConvert.DeserializeObject(jsonContentOrPath);
foreach (var item in data)
@ -63,7 +59,18 @@ namespace Flowframes.Data
bool def = false;
bool.TryParse((string)item.isDefault, out def);
models.Add(new ModelInfo(ai, (string)item.name, (string)item.desc, (string)item.dir, alpha, def));
ModelInfo modelInfo = new ModelInfo()
{
Ai = ai,
Name = (string)item.name,
Desc = (string)item.desc,
Dir = (string)item.dir,
SupportsAlpha = alpha,
IsDefault = def,
FixedFactors = ((JArray)item.fixedFactors)?.Select(x => (int)x).ToArray(),
};
Models.Add(modelInfo);
}
}
}

View File

@ -337,7 +337,7 @@ namespace Flowframes
{
try
{
return AiModels.GetModels(currentAi).models[aiModel.SelectedIndex];
return AiModels.GetModels(currentAi).Models[aiModel.SelectedIndex];
}
catch
{

View File

@ -34,7 +34,7 @@ namespace Flowframes.Forms
InterpSettings entry = Program.batchQueue.ElementAt(i);
string niceOutMode = entry.outMode.ToString().ToUpper().Remove("VID").Remove("IMG");
string str = $"#{i+1}: {Path.GetFileName(entry.inPath).Trunc(40)} - {entry.inFps.GetFloat()} FPS => " +
$"{entry.interpFactor}x {entry.ai.NameShort} ({entry.model.name}) => {niceOutMode}";
$"{entry.interpFactor}x {entry.ai.NameShort} ({entry.model.Name}) => {niceOutMode}";
taskList.Items.Add(str);
}
}

View File

@ -579,7 +579,7 @@ namespace Flowframes.IO
filename = filename.Replace("[FULLNAME]", Path.GetFileName(curr.inPath));
filename = filename.Replace("[FACTOR]", curr.interpFactor.ToStringDot());
filename = filename.Replace("[AI]", curr.ai.NameShort.ToUpper());
filename = filename.Replace("[MODEL]", curr.model.name.Remove(" "));
filename = filename.Replace("[MODEL]", curr.model.Name.Remove(" "));
filename = filename.Replace("[FPS]", fps.ToStringDot());
filename = filename.Replace("[ROUNDFPS]", fps.RoundToInt().ToString());
filename = filename.Replace("[RES]", $"{outRes.Width}x{outRes.Height}");

View File

@ -201,9 +201,9 @@ namespace Flowframes.IO
string aiPkgFolder = Path.Combine(Paths.GetPkgPath(), ai.PkgDir);
ModelCollection aiModels = AiModels.GetModels(ai);
foreach(ModelCollection.ModelInfo model in aiModels.models)
foreach(ModelCollection.ModelInfo model in aiModels.Models)
{
string mdlFolder = Path.Combine(aiPkgFolder, model.dir);
string mdlFolder = Path.Combine(aiPkgFolder, model.Dir);
if (Directory.Exists(mdlFolder))
modelPaths.Add(mdlFolder);

View File

@ -29,7 +29,7 @@ namespace Flowframes.Main
{
string name = customModel.Remove("_alpha").Remove("_custom");
bool alpha = customModel.Contains("_alpha");
modelCollection.models.Add(new ModelCollection.ModelInfo(ai, name, "Custom Model", customModel, alpha, false));
modelCollection.Models.Add(new ModelCollection.ModelInfo() { Ai = ai, Name = name, Desc = "Custom Model", SupportsAlpha = alpha, IsDefault = false });
}
return modelCollection;
@ -53,9 +53,9 @@ namespace Flowframes.Main
{
ModelCollection modelCollection = GetModels(ai);
foreach(ModelCollection.ModelInfo model in modelCollection.models)
foreach(ModelCollection.ModelInfo model in modelCollection.Models)
{
if (model.name == modelName)
if (model.Name == modelName)
return model;
}
@ -66,9 +66,9 @@ namespace Flowframes.Main
{
ModelCollection modelCollection = GetModels(ai);
foreach (ModelCollection.ModelInfo model in modelCollection.models)
foreach (ModelCollection.ModelInfo model in modelCollection.Models)
{
if (model.dir == dirName)
if (model.Dir == dirName)
return model;
}

View File

@ -89,7 +89,7 @@ namespace Flowframes
public static async Task Realtime ()
{
await AiProcess.RunRifeNcnnVs(currentSettings.framesFolder, "", currentSettings.interpFactor, currentSettings.model.dir, true);
await AiProcess.RunRifeNcnnVs(currentSettings.framesFolder, "", currentSettings.interpFactor, currentSettings.model.Dir, true);
}
public static async Task GetFrames()
@ -186,8 +186,14 @@ namespace Flowframes
if (!ai.Piped || (ai.Piped && dedupe))
await Task.Run(async () => { await FrameOrder.CreateFrameOrderFile(currentSettings.framesFolder, Config.GetBool(Config.Key.enableLoop), currentSettings.interpFactor); });
if (currentSettings.model.FixedFactors.Count() > 0 && (currentSettings.interpFactor != (int)currentSettings.interpFactor || !currentSettings.model.FixedFactors.Contains(currentSettings.interpFactor.RoundToInt())))
Cancel($"The selected model does not support {currentSettings.interpFactor}x interpolation.\n\nSupported Factors: {currentSettings.model.GetFactorsString()}");
if (canceled) return;
Program.mainForm.SetStatus("Downloading models...");
await ModelDownloader.DownloadModelFiles(ai, currentSettings.model.dir);
await ModelDownloader.DownloadModelFiles(ai, currentSettings.model.Dir);
if (canceled) return;
currentlyUsingAutoEnc = Utils.CanUseAutoEnc(stepByStep, currentSettings);
@ -197,25 +203,25 @@ namespace Flowframes
List<Task> tasks = new List<Task>();
if (ai.NameInternal == Implementations.rifeCuda.NameInternal)
tasks.Add(AiProcess.RunRifeCuda(currentSettings.framesFolder, currentSettings.interpFactor, currentSettings.model.dir));
tasks.Add(AiProcess.RunRifeCuda(currentSettings.framesFolder, currentSettings.interpFactor, currentSettings.model.Dir));
if (ai.NameInternal == Implementations.rifeNcnn.NameInternal)
tasks.Add(AiProcess.RunRifeNcnn(currentSettings.framesFolder, outpath, currentSettings.interpFactor, currentSettings.model.dir));
tasks.Add(AiProcess.RunRifeNcnn(currentSettings.framesFolder, outpath, currentSettings.interpFactor, currentSettings.model.Dir));
if (ai.NameInternal == Implementations.rifeNcnnVs.NameInternal)
tasks.Add(AiProcess.RunRifeNcnnVs(currentSettings.framesFolder, outpath, currentSettings.interpFactor, currentSettings.model.dir));
tasks.Add(AiProcess.RunRifeNcnnVs(currentSettings.framesFolder, outpath, currentSettings.interpFactor, currentSettings.model.Dir));
if (ai.NameInternal == Implementations.flavrCuda.NameInternal)
tasks.Add(AiProcess.RunFlavrCuda(currentSettings.framesFolder, currentSettings.interpFactor, currentSettings.model.dir));
tasks.Add(AiProcess.RunFlavrCuda(currentSettings.framesFolder, currentSettings.interpFactor, currentSettings.model.Dir));
if (ai.NameInternal == Implementations.dainNcnn.NameInternal)
tasks.Add(AiProcess.RunDainNcnn(currentSettings.framesFolder, outpath, currentSettings.interpFactor, currentSettings.model.dir, Config.GetInt(Config.Key.dainNcnnTilesize, 512)));
tasks.Add(AiProcess.RunDainNcnn(currentSettings.framesFolder, outpath, currentSettings.interpFactor, currentSettings.model.Dir, Config.GetInt(Config.Key.dainNcnnTilesize, 512)));
if (ai.NameInternal == Implementations.xvfiCuda.NameInternal)
tasks.Add(AiProcess.RunXvfiCuda(currentSettings.framesFolder, currentSettings.interpFactor, currentSettings.model.dir));
tasks.Add(AiProcess.RunXvfiCuda(currentSettings.framesFolder, currentSettings.interpFactor, currentSettings.model.Dir));
if(ai.NameInternal == Implementations.ifrnetNcnn.NameInternal)
tasks.Add(AiProcess.RunIfrnetNcnn(currentSettings.framesFolder, outpath, currentSettings.interpFactor, currentSettings.model.dir));
tasks.Add(AiProcess.RunIfrnetNcnn(currentSettings.framesFolder, outpath, currentSettings.interpFactor, currentSettings.model.Dir));
if (currentlyUsingAutoEnc)
{

View File

@ -154,7 +154,7 @@ namespace Flowframes.Main
return false;
}
if (model == null || model.dir.Trim() == "")
if (model == null || model.Dir.Trim() == "")
{
UiUtils.ShowMessageBox("No valid AI model has been selected!", UiUtils.MessageType.Error);
I.Cancel("No valid model selected.", true);

View File

@ -48,14 +48,14 @@ namespace Flowframes.MiscUtils
{
ModelCollection modelCollection = AiModels.GetModels(ai);
for (int i = 0; i < modelCollection.models.Count; i++)
for (int i = 0; i < modelCollection.Models.Count; i++)
{
if (canceled)
return;
ModelCollection.ModelInfo modelInfo = modelCollection.models[i];
form.SetStatus($"Downloading files for {modelInfo.ai.NameInternal.Replace("_", "-")}...");
await ModelDownloader.DownloadModelFiles(ai, modelInfo.dir, false);
ModelCollection.ModelInfo modelInfo = modelCollection.Models[i];
form.SetStatus($"Downloading files for {modelInfo.Ai.NameInternal.Replace("_", "-")}...");
await ModelDownloader.DownloadModelFiles(ai, modelInfo.Dir, false);
taskCounter++;
UpdateProgressBar();
}
@ -79,7 +79,7 @@ namespace Flowframes.MiscUtils
foreach(AI ai in ais)
{
ModelCollection modelCollection = AiModels.GetModels(ai);
count += modelCollection.models.Count;
count += modelCollection.Models.Count;
}
return count;

View File

@ -161,7 +161,7 @@ namespace Flowframes.Ui
{
AI ai = Program.mainForm.GetAi();
if (ai.NameInternal == Implementations.rifeNcnn.NameInternal && !Program.mainForm.GetModel(ai).dir.Contains("v4"))
if (ai.NameInternal == Implementations.rifeNcnn.NameInternal && !Program.mainForm.GetModel(ai).Dir.Contains("v4"))
{
if (factor != 2)
Logger.Log($"{ai.FriendlyName} models before 4.0 only support 2x interpolation!");

View File

@ -38,19 +38,19 @@ namespace Flowframes.Ui
{
ModelCollection modelCollection = AiModels.GetModels(ai);
if (modelCollection.models == null || modelCollection.models.Count < 1)
if (modelCollection.Models == null || modelCollection.Models.Count < 1)
return combox;
for (int i = 0; i < modelCollection.models.Count; i++)
for (int i = 0; i < modelCollection.Models.Count; i++)
{
ModelCollection.ModelInfo modelInfo = modelCollection.models[i];
ModelCollection.ModelInfo modelInfo = modelCollection.Models[i];
if (string.IsNullOrWhiteSpace(modelInfo.name))
if (string.IsNullOrWhiteSpace(modelInfo.Name))
continue;
combox.Items.Add(modelInfo.GetUiString());
if (modelInfo.isDefault)
if (modelInfo.IsDefault)
combox.SelectedIndex = i;
}

View File

@ -1,18 +1,21 @@
[
{
"name": "FLAVR 2x",
"desc": "Official model, only works for 2x interpolation",
"desc": "Official model",
"dir": "FLAVR2X",
"fixedFactors": [2],
"isDefault": "true"
},
{
"name": "FLAVR 4x",
"desc": "Official model, only works for 4x interpolation",
"dir": "FLAVR4X"
"desc": "Official model",
"dir": "FLAVR4X",
"fixedFactors": [4],
},
{
"name": "FLAVR 8x",
"desc": "Official model, only works for 8x interpolation",
"dir": "FLAVR8X"
"desc": "Official model",
"dir": "FLAVR8X",
"fixedFactors": [8],
}
]

View File

@ -1,4 +1,10 @@
[
{
"name": "RIFE 2.3",
"desc": "Old Model",
"dir": "rife-v2.3",
"fixedFactors": [2]
},
{
"name": "RIFE 4.0",
"desc": "New Fast General Model",