2022-07-06 10:40:41 +02:00
|
|
|
|
using Flowframes.Os;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2021-08-23 16:50:18 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Flowframes.Data
|
|
|
|
|
|
{
|
2024-08-25 20:45:50 +02:00
|
|
|
|
public class Implementations
|
2021-08-23 16:50:18 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +02:00
|
|
|
|
public enum Ai
|
2022-07-26 21:08:07 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +02:00
|
|
|
|
RifeCuda,
|
|
|
|
|
|
RifeNcnn,
|
|
|
|
|
|
RifeNcnnVs,
|
|
|
|
|
|
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",
|
2024-08-21 14:45:46 +02:00
|
|
|
|
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
|
|
|
|
};
|
2021-08-31 00:09:47 +02:00
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
public static AiInfo rifeNcnn = new AiInfo()
|
2022-07-26 21:08:07 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +02:00
|
|
|
|
Backend = AiInfo.AiBackend.Ncnn,
|
2022-07-26 21:08:07 +02:00
|
|
|
|
NameInternal = "RIFE_NCNN",
|
|
|
|
|
|
NameLong = "Real-Time Intermediate Flow Estimation",
|
2024-08-21 14:45:46 +02:00
|
|
|
|
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
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
public static AiInfo rifeNcnnVs = new AiInfo()
|
2022-07-26 21:08:07 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +02:00
|
|
|
|
Backend = AiInfo.AiBackend.Ncnn,
|
2022-07-26 21:08:07 +02:00
|
|
|
|
NameInternal = "RIFE_NCNN_VS",
|
|
|
|
|
|
NameLong = "Real-Time Intermediate Flow Estimation",
|
2024-08-21 14:45:46 +02:00
|
|
|
|
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
|
|
|
|
|
|
};
|
2022-06-01 16:23:00 +02:00
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
public static AiInfo flavrCuda = new AiInfo()
|
2022-07-26 21:08:07 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +02:00
|
|
|
|
Backend = AiInfo.AiBackend.Pytorch,
|
2022-07-26 21:08:07 +02:00
|
|
|
|
NameInternal = "FLAVR_CUDA",
|
|
|
|
|
|
NameLong = "Flow-Agnostic Video Representations",
|
2024-08-21 14:45:46 +02:00
|
|
|
|
FactorSupport = AiInfo.InterpFactorSupport.Fixed,
|
2022-07-26 21:08:07 +02:00
|
|
|
|
SupportedFactors = new int[] { 2, 4, 8 },
|
|
|
|
|
|
};
|
2021-08-31 00:09:47 +02:00
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
public static AiInfo dainNcnn = new AiInfo()
|
2022-07-26 21:08:07 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +02:00
|
|
|
|
Backend = AiInfo.AiBackend.Ncnn,
|
2022-07-26 21:08:07 +02:00
|
|
|
|
NameInternal = "DAIN_NCNN",
|
|
|
|
|
|
NameLong = "Depth-Aware Video Frame Interpolation",
|
2024-08-21 14:45:46 +02:00
|
|
|
|
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
|
|
|
|
};
|
2021-08-31 00:09:47 +02:00
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
public static AiInfo xvfiCuda = new AiInfo()
|
2022-07-26 21:08:07 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +02:00
|
|
|
|
Backend = AiInfo.AiBackend.Pytorch,
|
2022-07-26 21:08:07 +02:00
|
|
|
|
NameInternal = "XVFI_CUDA",
|
|
|
|
|
|
NameLong = "eXtreme Video Frame Interpolation",
|
2024-08-21 14:45:46 +02:00
|
|
|
|
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
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
public static AiInfo ifrnetNcnn = new AiInfo()
|
2022-07-26 21:08:07 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +02:00
|
|
|
|
Backend = AiInfo.AiBackend.Ncnn,
|
2022-07-26 21:08:07 +02:00
|
|
|
|
NameInternal = "IFRNet_NCNN",
|
|
|
|
|
|
NameLong = "Intermediate Feature Refine Network",
|
2024-08-21 14:45:46 +02:00
|
|
|
|
FactorSupport = AiInfo.InterpFactorSupport.Fixed,
|
2022-07-26 21:08:07 +02:00
|
|
|
|
SupportedFactors = new int[] { 2 },
|
|
|
|
|
|
};
|
2022-05-31 22:17:22 +02:00
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
// Lookup table
|
|
|
|
|
|
private static readonly Dictionary<Ai, AiInfo> AiLookup = new Dictionary<Ai, AiInfo>
|
2022-07-06 10:40:41 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +02:00
|
|
|
|
{ Ai.RifeCuda, rifeCuda },
|
|
|
|
|
|
{ Ai.RifeNcnn, rifeNcnn },
|
|
|
|
|
|
{ Ai.RifeNcnnVs, rifeNcnnVs },
|
|
|
|
|
|
{ Ai.FlavrCuda, flavrCuda },
|
|
|
|
|
|
{ Ai.DainNcnn, dainNcnn },
|
|
|
|
|
|
{ Ai.XvfiCuda, xvfiCuda },
|
2024-09-03 22:01:32 +02:00
|
|
|
|
/* { Ai.IfrnetNcnn, ifrnetNcnn }, */
|
2024-08-21 14:45:46 +02:00
|
|
|
|
};
|
2022-07-06 10:40:41 +02:00
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
public static List<AiInfo> NetworksAll => AiLookup.Values.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
public static List<AiInfo> NetworksAvailable
|
2022-07-06 10:40:41 +02:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2024-08-15 11:34:36 +02:00
|
|
|
|
bool pytorchAvailable = !Python.DisablePython && Python.IsPytorchReady();
|
2022-07-06 21:53:32 +02:00
|
|
|
|
|
|
|
|
|
|
if (pytorchAvailable)
|
|
|
|
|
|
return NetworksAll;
|
2024-08-21 14:45:46 +02:00
|
|
|
|
|
|
|
|
|
|
return NetworksAll.Where(x => x.Backend != AiInfo.AiBackend.Pytorch).ToList();
|
2022-07-06 10:40:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-08-23 16:50:18 +02:00
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
// Legacy: Get by name
|
|
|
|
|
|
public static AiInfo GetAi(string aiName)
|
2021-08-23 16:50:18 +02:00
|
|
|
|
{
|
2024-08-21 14:45:46 +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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-21 14:45:46 +02:00
|
|
|
|
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!");
|
2022-07-06 10:40:41 +02:00
|
|
|
|
return NetworksAll[0];
|
2021-08-23 16:50:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-21 14:45:46 +02:00
|
|
|
|
}
|