Files
flowframes/CodeLegacy/Data/Implementations.cs

135 lines
4.4 KiB
C#
Raw Normal View History

using Flowframes.Os;
using System.Collections.Generic;
using System.Linq;
2021-08-23 16:50:18 +02:00
namespace Flowframes.Data
{
public class Implementations
2021-08-23 16:50:18 +02:00
{
public enum Ai
2022-07-26 21:08:07 +02:00
{
RifeCuda,
RifeNcnnVs,
RifeNcnn,
FlavrCuda,
DainNcnn,
XvfiCuda,
IfrnetNcnn,
}
public static AiInfo rifeCuda = new AiInfo()
{
Backend = AiInfo.AiBackend.Pytorch,
2022-07-26 21:08:07 +02:00
NameInternal = "RIFE_CUDA",
NameLong = "Real-Time Intermediate Flow Estimation",
FactorSupport = AiInfo.InterpFactorSupport.AnyInteger,
2024-09-03 22:01:32 +02:00
SupportedFactors = Enumerable.Range(2, 15).ToArray(), // 2 to 16
2022-07-26 21:08:07 +02:00
};
public static AiInfo rifeNcnn = new AiInfo()
2022-07-26 21:08:07 +02:00
{
Backend = AiInfo.AiBackend.Ncnn,
2022-07-26 21:08:07 +02:00
NameInternal = "RIFE_NCNN",
NameLong = "Real-Time Intermediate Flow Estimation",
FactorSupport = AiInfo.InterpFactorSupport.AnyFloat,
2024-09-03 22:01:32 +02:00
SupportedFactors = Enumerable.Range(2, 15).ToArray(), // 2 to 16
2022-07-26 21:08:07 +02:00
};
2022-07-23 14:43:57 +02:00
public static AiInfo rifeNcnnVs = new AiInfo()
2022-07-26 21:08:07 +02:00
{
Backend = AiInfo.AiBackend.Ncnn,
2022-07-26 21:08:07 +02:00
NameInternal = "RIFE_NCNN_VS",
NameLong = "Real-Time Intermediate Flow Estimation",
FactorSupport = AiInfo.InterpFactorSupport.AnyFloat,
2024-09-03 22:01:32 +02:00
SupportedFactors = Enumerable.Range(2, 15).ToArray(), // 2 to 16
2022-07-26 21:08:07 +02:00
Piped = true
};
public static AiInfo flavrCuda = new AiInfo()
2022-07-26 21:08:07 +02:00
{
Backend = AiInfo.AiBackend.Pytorch,
2022-07-26 21:08:07 +02:00
NameInternal = "FLAVR_CUDA",
NameLong = "Flow-Agnostic Video Representations",
FactorSupport = AiInfo.InterpFactorSupport.Fixed,
2022-07-26 21:08:07 +02:00
SupportedFactors = new int[] { 2, 4, 8 },
};
public static AiInfo dainNcnn = new AiInfo()
2022-07-26 21:08:07 +02:00
{
Backend = AiInfo.AiBackend.Ncnn,
2022-07-26 21:08:07 +02:00
NameInternal = "DAIN_NCNN",
NameLong = "Depth-Aware Video Frame Interpolation",
FactorSupport = AiInfo.InterpFactorSupport.AnyFloat,
2024-09-03 22:01:32 +02:00
SupportedFactors = Enumerable.Range(2, 7).ToArray(), // 2 to 8
2022-07-26 21:08:07 +02:00
};
public static AiInfo xvfiCuda = new AiInfo()
2022-07-26 21:08:07 +02:00
{
Backend = AiInfo.AiBackend.Pytorch,
2022-07-26 21:08:07 +02:00
NameInternal = "XVFI_CUDA",
NameLong = "eXtreme Video Frame Interpolation",
FactorSupport = AiInfo.InterpFactorSupport.AnyInteger,
2024-09-03 22:01:32 +02:00
SupportedFactors = Enumerable.Range(2, 9).ToArray(), // 2 to 10
2022-07-26 21:08:07 +02:00
};
2021-08-23 16:50:18 +02:00
public static AiInfo ifrnetNcnn = new AiInfo()
2022-07-26 21:08:07 +02:00
{
Backend = AiInfo.AiBackend.Ncnn,
2022-07-26 21:08:07 +02:00
NameInternal = "IFRNet_NCNN",
NameLong = "Intermediate Feature Refine Network",
FactorSupport = AiInfo.InterpFactorSupport.Fixed,
2022-07-26 21:08:07 +02:00
SupportedFactors = new int[] { 2 },
};
2022-05-31 22:17:22 +02:00
// Lookup table
private static readonly Dictionary<Ai, AiInfo> AiLookup = new Dictionary<Ai, AiInfo>
{
{ Ai.RifeCuda, rifeCuda },
{ Ai.RifeNcnnVs, rifeNcnnVs },
{ Ai.RifeNcnn, rifeNcnn },
{ Ai.FlavrCuda, flavrCuda },
{ Ai.DainNcnn, dainNcnn },
{ Ai.XvfiCuda, xvfiCuda },
2024-09-03 22:01:32 +02:00
/* { Ai.IfrnetNcnn, ifrnetNcnn }, */
};
public static List<AiInfo> NetworksAll => AiLookup.Values.ToList();
public static List<AiInfo> NetworksAvailable
{
get
{
bool pytorchAvailable = !Python.DisablePython && Python.IsPytorchReady();
2022-07-06 21:53:32 +02:00
if (pytorchAvailable)
return NetworksAll;
return NetworksAll.Where(x => x.Backend != AiInfo.AiBackend.Pytorch).ToList();
}
}
2021-08-23 16:50:18 +02:00
// Legacy: Get by name
public static AiInfo GetAi(string aiName)
2021-08-23 16:50:18 +02:00
{
foreach (var ai in NetworksAll)
2021-08-23 16:50:18 +02:00
{
2022-07-21 10:08:53 +02:00
if (ai.NameInternal == aiName)
2021-08-23 16:50:18 +02:00
return ai;
}
Logger.Log($"AI implementation lookup failed for '{aiName}'! This should not happen! Please tell the developer!");
return NetworksAll[0];
}
// New: Use enums
public static AiInfo GetAi(Ai ai)
{
if (AiLookup.TryGetValue(ai, out AiInfo aiObj))
return aiObj;
Logger.Log($"AI implementation lookup failed for '{ai}'! This should not happen! Please tell the developer!");
return NetworksAll[0];
2021-08-23 16:50:18 +02:00
}
}
}