mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-16 08:27:44 +01:00
Load AI models info from JSON
This commit is contained in:
60
Code/Data/ModelCollection.cs
Normal file
60
Code/Data/ModelCollection.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Flowframes.IO;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Flowframes.Data
|
||||
{
|
||||
class ModelCollection
|
||||
{
|
||||
public AI ai;
|
||||
public List<ModelInfo> models;
|
||||
|
||||
public class ModelInfo
|
||||
{
|
||||
public AI ai;
|
||||
public string name;
|
||||
public string desc;
|
||||
public string dir;
|
||||
public bool isDefault;
|
||||
|
||||
public ModelInfo(AI ai, string name, string desc, string dir, bool isDefault)
|
||||
{
|
||||
this.ai = ai;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.dir = dir;
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
public string GetUiString()
|
||||
{
|
||||
return $"{name} - {desc}{(isDefault ? " (Recommended)" : "")}";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{name} - {desc} ({dir}){(isDefault ? " (Recommended)" : "")}";
|
||||
}
|
||||
}
|
||||
|
||||
public ModelCollection(AI ai, string jsonContentOrPath)
|
||||
{
|
||||
if (IOUtils.IsPathValid(jsonContentOrPath) && File.Exists(jsonContentOrPath))
|
||||
jsonContentOrPath = File.ReadAllText(jsonContentOrPath);
|
||||
|
||||
models = new List<ModelInfo>();
|
||||
dynamic data = JsonConvert.DeserializeObject(jsonContentOrPath);
|
||||
|
||||
foreach (var item in 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, def));
|
||||
}
|
||||
|
||||
Logger.Log($"Loaded {models.Count} {ai.aiName} models from JSON.", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,6 +124,9 @@
|
||||
<Reference Include="Microsoft.WindowsAPICodePack.Shell, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>packages\WindowsAPICodePack-Shell.1.1.1\lib\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NvAPIWrapper, Version=0.8.1.100, Culture=neutral, PublicKeyToken=310fd07b25df79b3, processorArchitecture=MSIL">
|
||||
<HintPath>packages\NvAPIWrapper.Net.0.8.1.101\lib\net45\NvAPIWrapper.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -328,6 +331,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Data\AI.cs" />
|
||||
<Compile Include="Data\AudioTrack.cs" />
|
||||
<Compile Include="Data\ModelCollection.cs" />
|
||||
<Compile Include="Data\VidExtraData.cs" />
|
||||
<Compile Include="Data\Fraction.cs" />
|
||||
<Compile Include="Data\InterpSettings.cs" />
|
||||
|
||||
@@ -377,7 +377,7 @@ namespace Flowframes
|
||||
|
||||
public void UpdateAiModelCombox ()
|
||||
{
|
||||
aiModel = UIUtils.FillAiModelsCombox(aiModel, GetAi());
|
||||
aiModel = UIUtils.LoadAiModelsIntoGui(aiModel, GetAi());
|
||||
}
|
||||
|
||||
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Flowframes
|
||||
string ffprobeOutput = GetFfprobeOutput(ffprobeArgs);
|
||||
string fpsStr = ffprobeOutput.SplitIntoLines().Where(x => x.Contains("r_frame_rate")).First();
|
||||
string[] numbers = fpsStr.Split('=')[1].Split('/');
|
||||
Logger.Log($"Accurate FPS: {numbers[0]}/{numbers[1]} = {((float)numbers[0].GetInt() / numbers[1].GetInt())}", true, false, "ffmpeg");
|
||||
Logger.Log($"Fractional FPS from ffprobe: {numbers[0]}/{numbers[1]} = {((float)numbers[0].GetInt() / numbers[1].GetInt())}", true, false, "ffmpeg");
|
||||
return new Fraction(numbers[0].GetInt(), numbers[1].GetInt());
|
||||
}
|
||||
catch (Exception ffprobeEx)
|
||||
|
||||
@@ -35,26 +35,26 @@ namespace Flowframes.UI
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ComboBox FillAiModelsCombox (ComboBox combox, AI ai)
|
||||
public static ComboBox LoadAiModelsIntoGui (ComboBox combox, AI ai)
|
||||
{
|
||||
combox.Items.Clear();
|
||||
|
||||
try
|
||||
{
|
||||
string pkgPath = Path.Combine(Paths.GetPkgPath(), ai.pkgDir);
|
||||
string modelsFile = Path.Combine(pkgPath, "models.txt");
|
||||
string[] modelsWithDec = IOUtils.ReadLines(modelsFile);
|
||||
string modelsFile = Path.Combine(pkgPath, "models.json");
|
||||
ModelCollection modelCollection = new ModelCollection(ai, modelsFile);
|
||||
|
||||
for (int i = 0; i < modelsWithDec.Length; i++)
|
||||
for (int i = 0; i < modelCollection.models.Count; i++)
|
||||
{
|
||||
string model = modelsWithDec[i];
|
||||
ModelCollection.ModelInfo modelInfo = modelCollection.models[i];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(model))
|
||||
if (string.IsNullOrWhiteSpace(modelInfo.name))
|
||||
continue;
|
||||
|
||||
combox.Items.Add(model);
|
||||
combox.Items.Add(modelInfo.GetUiString());
|
||||
|
||||
if (model.Contains("Recommended") || model.Contains("Default"))
|
||||
if (modelInfo.isDefault)
|
||||
combox.SelectedIndex = i;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ namespace Flowframes.UI
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log($"Failed to load available AI models for {ai.aiName}! {e.Message}");
|
||||
Logger.Log($"Stack Trace: {e.StackTrace}", true);
|
||||
}
|
||||
|
||||
return combox;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<package id="Microsoft-WindowsAPICodePack-Core" version="1.1.4" targetFramework="net472" />
|
||||
<package id="Microsoft-WindowsAPICodePack-Shell" version="1.1.4" targetFramework="net472" />
|
||||
<package id="NETStandard.Library" version="1.6.1" targetFramework="net472" />
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
|
||||
<package id="NvAPIWrapper.Net" version="0.8.1.101" targetFramework="net472" />
|
||||
<package id="PagedControl" version="2.2.0" targetFramework="net472" />
|
||||
<package id="System.AppContext" version="4.3.0" targetFramework="net472" />
|
||||
|
||||
8
Pkgs/dain-ncnn/models.json
Normal file
8
Pkgs/dain-ncnn/models.json
Normal file
@@ -0,0 +1,8 @@
|
||||
[
|
||||
{
|
||||
"name": "Default",
|
||||
"desc": "Official Pretrained Model",
|
||||
"dir": "best",
|
||||
"isDefault": "true"
|
||||
}
|
||||
]
|
||||
18
Pkgs/flavr-cuda/models.json
Normal file
18
Pkgs/flavr-cuda/models.json
Normal file
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"name": "FLAVR 2x",
|
||||
"desc": "Official model, only works for 2x interpolation",
|
||||
"dir": "FLAVR2X",
|
||||
"isDefault": "true"
|
||||
},
|
||||
{
|
||||
"name": "FLAVR 4x",
|
||||
"desc": "Official model, only works for 4x interpolation",
|
||||
"dir": "FLAVR4X"
|
||||
},
|
||||
{
|
||||
"name": "FLAVR 8x",
|
||||
"desc": "Official model, only works for 8x interpolation",
|
||||
"dir": "FLAVR8X"
|
||||
}
|
||||
]
|
||||
23
Pkgs/rife-cuda/models.json
Normal file
23
Pkgs/rife-cuda/models.json
Normal file
@@ -0,0 +1,23 @@
|
||||
[
|
||||
{
|
||||
"name": "RIFE 1.8",
|
||||
"desc": "Old 2D Animation Model",
|
||||
"dir": "RIFE18"
|
||||
},
|
||||
{
|
||||
"name": "RIFE 2.3",
|
||||
"desc": "Updated General Model",
|
||||
"dir": "RIFE23"
|
||||
},
|
||||
{
|
||||
"name": "RIFE 2.4",
|
||||
"desc": "Updated General Model (Sometimes worse than 2.3)",
|
||||
"dir": "RIFE24"
|
||||
},
|
||||
{
|
||||
"name": "RIFE 3.0",
|
||||
"desc": "Latest General Model",
|
||||
"dir": "RIFE30",
|
||||
"isDefault": "true"
|
||||
}
|
||||
]
|
||||
18
Pkgs/rife-ncnn/models.json
Normal file
18
Pkgs/rife-ncnn/models.json
Normal file
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"name": "RIFE 1.8",
|
||||
"desc": "Old 2D Animation Model",
|
||||
"dir": "rife-anime"
|
||||
},
|
||||
{
|
||||
"name": "RIFE 2.4",
|
||||
"desc": "Updated General Model",
|
||||
"dir": "rife-v2.4"
|
||||
},
|
||||
{
|
||||
"name": "RIFE 3.0",
|
||||
"desc": "Latest General Model",
|
||||
"dir": "rife-v3.0",
|
||||
"isDefault": "true"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user