AI info button, custom MessageBox form

This commit is contained in:
n00mkrad
2022-07-23 14:43:57 +02:00
parent f471290503
commit 54fb84de23
11 changed files with 377 additions and 33 deletions

View File

@@ -1,6 +1,8 @@
using Flowframes.IO;
using Flowframes.MiscUtils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -13,8 +15,9 @@ namespace Flowframes.Data
public AiBackend Backend { get; set; } = AiBackend.Pytorch;
public string NameInternal { get; set; } = "";
public string NameShort { get { return NameInternal.Split(' ')[0].Split('_')[0]; } }
public string FriendlyName { get { return $"{NameShort} ({GetFrameworkString()})"; } }
public string Description { get { return $"{GetImplemString()} of {NameShort}{(Backend == AiBackend.Pytorch ? " (Nvidia Only!)" : "")}"; } }
public string NameLong { get; set; } = "";
public string FriendlyName { get { return $"{NameShort} ({GetFrameworkString(Backend)})"; } }
public string Description { get { return $"{GetImplemString(Backend)} of {NameShort}{(Backend == AiBackend.Pytorch ? " (Nvidia Only!)" : "")}"; } }
public string PkgDir { get { return NameInternal.Replace("_", "-").ToLower(); } }
public enum InterpFactorSupport { Fixed, AnyPowerOfTwo, AnyInteger, AnyFloat }
public InterpFactorSupport FactorSupport { get; set; } = InterpFactorSupport.Fixed;
@@ -23,40 +26,80 @@ namespace Flowframes.Data
public string LogFilename { get { return PkgDir + "-log"; } }
public AI(AiBackend backend, string aiName, InterpFactorSupport factorSupport = InterpFactorSupport.Fixed, int[] supportedFactors = null)
public AI(AiBackend backend, string aiName, string longName, InterpFactorSupport factorSupport = InterpFactorSupport.Fixed, int[] supportedFactors = null)
{
Backend = backend;
NameInternal = aiName;
NameLong = longName;
SupportedFactors = supportedFactors;
FactorSupport = factorSupport;
}
private string GetImplemString ()
public string GetVerboseInfo ()
{
if (Backend == AiBackend.Pytorch)
return $"Name:\n{NameShort}\n\n" +
$"Full Name:\n{NameLong}\n\n" +
$"Inference Framework:\n{FormatUtils.CapsIfShort(Backend.ToString(), 5)}\n\n" +
$"Hardware Acceleration:\n{GetHwAccelString(Backend)}\n\n" +
$"Supported Interpolation Factors:\n{GetFactorsString(FactorSupport)}\n\n" +
$"Requires Frame Extraction:\n{(Piped ? "No" : "Yes")}\n\n" +
$"Package Directory/Size:\n{PkgDir} ({FormatUtils.Bytes(IoUtils.GetDirSize(Path.Combine(Paths.GetPkgPath(), PkgDir), true))})";
}
private string GetImplemString (AiBackend backend)
{
if (backend == AiBackend.Pytorch)
return $"CUDA/Pytorch Implementation";
if(Backend == AiBackend.Ncnn)
if(backend == AiBackend.Ncnn)
return $"Vulkan/NCNN{(Piped ? "/VapourSynth" : "")} Implementation";
if (Backend == AiBackend.Tensorflow)
if (backend == AiBackend.Tensorflow)
return $"Tensorflow Implementation";
return "";
}
private string GetFrameworkString()
private string GetFrameworkString(AiBackend backend)
{
if (Backend == AiBackend.Pytorch)
if (backend == AiBackend.Pytorch)
return $"CUDA";
if (Backend == AiBackend.Ncnn)
if (backend == AiBackend.Ncnn)
return $"NCNN{(Piped ? "/VS" : "")}";
if (Backend == AiBackend.Tensorflow)
if (backend == AiBackend.Tensorflow)
return $"TF";
return "Custom";
}
private string GetHwAccelString (AiBackend backend)
{
if (Backend == AiBackend.Pytorch)
return $"GPU (Nvidia CUDA)";
if (Backend == AiBackend.Ncnn)
return $"GPU (Vulkan)";
return "Unknown";
}
private string GetFactorsString (InterpFactorSupport factorSupport)
{
if (factorSupport == InterpFactorSupport.Fixed)
return $"{string.Join(", ", SupportedFactors.Select(x => $"{x}x"))}";
if (factorSupport == InterpFactorSupport.AnyPowerOfTwo)
return "Any powers of 2 (2/4/8/16 etc.)";
if (factorSupport == InterpFactorSupport.AnyInteger)
return "Any integer (whole number)";
if (factorSupport == InterpFactorSupport.AnyFloat)
return "Any, including fractional factors";
return "Unknown";
}
}
}

View File

@@ -6,20 +6,26 @@ namespace Flowframes.Data
{
class Implementations
{
public static AI rifeCuda = new AI(AI.AiBackend.Pytorch, "RIFE_CUDA", AI.InterpFactorSupport.AnyInteger, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
private static readonly string rifeLong = "Real-Time Intermediate Flow Estimation";
private static readonly string flavrLong = "Flow-Agnostic Video Representations";
private static readonly string dainLong = "Depth-Aware Video Frame Interpolation";
private static readonly string xvfiLong = "eXtreme Video Frame Interpolation";
private static readonly string ifrnetLong = "Intermediate Feature Refine Network";
public static AI rifeNcnnVs = new AI(AI.AiBackend.Ncnn, "RIFE_NCNN_VS", AI.InterpFactorSupport.AnyFloat, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 })
public static AI rifeCuda = new AI(AI.AiBackend.Pytorch, "RIFE_CUDA", rifeLong, AI.InterpFactorSupport.AnyInteger, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
public static AI rifeNcnnVs = new AI(AI.AiBackend.Ncnn, "RIFE_NCNN_VS", rifeLong, AI.InterpFactorSupport.AnyFloat, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 })
{ Piped = true };
public static AI rifeNcnn = new AI(AI.AiBackend.Ncnn, "RIFE_NCNN", AI.InterpFactorSupport.AnyFloat, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
public static AI rifeNcnn = new AI(AI.AiBackend.Ncnn, "RIFE_NCNN", rifeLong, AI.InterpFactorSupport.AnyFloat, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
public static AI flavrCuda = new AI(AI.AiBackend.Pytorch, "FLAVR_CUDA", AI.InterpFactorSupport.Fixed, new int[] { 2, 4, 8 });
public static AI flavrCuda = new AI(AI.AiBackend.Pytorch, "FLAVR_CUDA", flavrLong, AI.InterpFactorSupport.Fixed, new int[] { 2, 4, 8 });
public static AI dainNcnn = new AI(AI.AiBackend.Ncnn, "DAIN_NCNN", AI.InterpFactorSupport.AnyFloat, new int[] { 2, 3, 4, 5, 6, 7, 8 });
public static AI dainNcnn = new AI(AI.AiBackend.Ncnn, "DAIN_NCNN", dainLong, AI.InterpFactorSupport.AnyFloat, new int[] { 2, 3, 4, 5, 6, 7, 8 });
public static AI xvfiCuda = new AI(AI.AiBackend.Pytorch, "XVFI_CUDA", AI.InterpFactorSupport.AnyInteger, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
public static AI xvfiCuda = new AI(AI.AiBackend.Pytorch, "XVFI_CUDA", xvfiLong, AI.InterpFactorSupport.AnyInteger, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
public static AI ifrnetNcnn = new AI(AI.AiBackend.Ncnn, "IFRNet_NCNN", AI.InterpFactorSupport.Fixed, new int[] { 2 });
public static AI ifrnetNcnn = new AI(AI.AiBackend.Ncnn, "IFRNet_NCNN", ifrnetLong, AI.InterpFactorSupport.Fixed, new int[] { 2 });
public static List<AI> NetworksAll
{

View File

@@ -372,6 +372,12 @@
<Compile Include="Forms\DebugForm.Designer.cs">
<DependentUpon>DebugForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\MessageForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\MessageForm.Designer.cs">
<DependentUpon>MessageForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\ModelDownloadForm.cs">
<SubType>Form</SubType>
</Compile>
@@ -474,6 +480,9 @@
<EmbeddedResource Include="Forms\DebugForm.resx">
<DependentUpon>DebugForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\MessageForm.resx">
<DependentUpon>MessageForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\ModelDownloadForm.resx">
<DependentUpon>ModelDownloadForm.cs</DependentUpon>
</EmbeddedResource>

17
Code/Form1.Designer.cs generated
View File

@@ -90,6 +90,7 @@
this.label15 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.interpOptsTab = new System.Windows.Forms.TabPage();
this.aiInfoBtn = new HTAlt.WinForms.HTButton();
this.outSpeedCombox = new System.Windows.Forms.ComboBox();
this.completionActionPanel = new System.Windows.Forms.Panel();
this.completionAction = new System.Windows.Forms.ComboBox();
@@ -914,6 +915,7 @@
//
this.interpOptsTab.AllowDrop = true;
this.interpOptsTab.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.interpOptsTab.Controls.Add(this.aiInfoBtn);
this.interpOptsTab.Controls.Add(this.pictureBox5);
this.interpOptsTab.Controls.Add(this.outSpeedCombox);
this.interpOptsTab.Controls.Add(this.completionActionPanel);
@@ -953,6 +955,20 @@
this.interpOptsTab.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop);
this.interpOptsTab.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter);
//
// aiInfoBtn
//
this.aiInfoBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.aiInfoBtn.FlatAppearance.BorderSize = 0;
this.aiInfoBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.aiInfoBtn.ForeColor = System.Drawing.Color.White;
this.aiInfoBtn.Location = new System.Drawing.Point(689, 7);
this.aiInfoBtn.Name = "aiInfoBtn";
this.aiInfoBtn.Size = new System.Drawing.Size(206, 23);
this.aiInfoBtn.TabIndex = 45;
this.aiInfoBtn.Text = "About This Implementation...";
this.aiInfoBtn.UseVisualStyleBackColor = false;
this.aiInfoBtn.Click += new System.EventHandler(this.aiInfoBtn_Click);
//
// outSpeedCombox
//
this.outSpeedCombox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
@@ -1824,6 +1840,7 @@
private System.Windows.Forms.Label label25;
private System.Windows.Forms.ComboBox outSpeedCombox;
private System.Windows.Forms.PictureBox pictureBox5;
private HTAlt.WinForms.HTButton aiInfoBtn;
}
}

View File

@@ -376,16 +376,21 @@ namespace Flowframes
public AI GetAi()
{
foreach(AI ai in Implementations.NetworksAll)
try
{
if (GetAiComboboxName(ai) == aiCombox.Text)
return ai;
foreach (AI ai in Implementations.NetworksAll)
{
if (GetAiComboboxName(ai) == aiCombox.Text)
return ai;
}
Logger.Log($"AI implementation lookup failed! This should not happen! Please tell the developer!");
return Implementations.NetworksAvailable[0];
}
catch
{
return null;
}
Logger.Log($"AI implementation lookup failed! This should not happen! Please tell the developer!");
return Implementations.NetworksAvailable[0];
//return Implementations.networks[aiCombox.SelectedIndex];
}
void inputTbox_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Copy; }
@@ -747,5 +752,13 @@ namespace Flowframes
ValidateFactor();
fpsOutTbox.Text = $"{inFps * interpFactorCombox.GetFloat()} FPS";
}
private void aiInfoBtn_Click(object sender, EventArgs e)
{
var ai = GetAi();
if(ai != null)
UiUtils.ShowMessageBox(ai.GetVerboseInfo(), UiUtils.MessageType.Message);
}
}
}

85
Code/Forms/MessageForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,85 @@
namespace Flowframes.Forms
{
partial class MessageForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textLabel = new System.Windows.Forms.Label();
this.okBtn = new HTAlt.WinForms.HTButton();
this.SuspendLayout();
//
// textLabel
//
this.textLabel.AutoSize = true;
this.textLabel.ForeColor = System.Drawing.Color.White;
this.textLabel.Location = new System.Drawing.Point(15, 15);
this.textLabel.Margin = new System.Windows.Forms.Padding(8, 0, 3, 0);
this.textLabel.Name = "textLabel";
this.textLabel.Size = new System.Drawing.Size(0, 13);
this.textLabel.TabIndex = 8;
//
// okBtn
//
this.okBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.okBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.okBtn.FlatAppearance.BorderSize = 0;
this.okBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.okBtn.ForeColor = System.Drawing.Color.White;
this.okBtn.Location = new System.Drawing.Point(232, 126);
this.okBtn.Name = "okBtn";
this.okBtn.Size = new System.Drawing.Size(100, 23);
this.okBtn.TabIndex = 46;
this.okBtn.Text = "OK";
this.okBtn.UseVisualStyleBackColor = false;
this.okBtn.Click += new System.EventHandler(this.okBtn_Click);
//
// MessageForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
this.ClientSize = new System.Drawing.Size(344, 161);
this.Controls.Add(this.okBtn);
this.Controls.Add(this.textLabel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MessageForm";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Load += new System.EventHandler(this.MessageForm_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label textLabel;
private HTAlt.WinForms.HTButton okBtn;
}
}

44
Code/Forms/MessageForm.cs Normal file
View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Flowframes.Forms
{
public partial class MessageForm : Form
{
private string _text = "";
private string _title = "";
public MessageForm(string text, string title)
{
_text = text;
_title = title;
InitializeComponent();
}
private void MessageForm_Load(object sender, EventArgs e)
{
Text = _title;
textLabel.Text = _text;
Size labelSize = GetLabelSize(textLabel);
Size = new Size((labelSize.Width + 60).Clamp(360, Program.mainForm.Size.Width), (labelSize.Height + 120).Clamp(200, Program.mainForm.Size.Height));
CenterToScreen();
}
private Size GetLabelSize(Label label)
{
return TextRenderer.MeasureText(label.Text, label.Font, label.ClientSize, TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);
}
private void okBtn_Click(object sender, EventArgs e)
{
Close();
}
}
}

120
Code/Forms/MessageForm.resx Normal file
View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -225,7 +225,7 @@ namespace Flowframes.Main
{
string enc = FfmpegUtils.GetEnc(FfmpegUtils.GetCodec(I.currentSettings.outMode));
float maxAv1Fps = 240;
float maxAv1Fps = 480;
if (enc.ToLower().Contains("av1") && encodeFps > maxAv1Fps)
{

View File

@@ -183,5 +183,13 @@ namespace Flowframes.MiscUtils
return line;
}
public static string CapsIfShort(string codec, int capsIfShorterThan = 5)
{
if (codec.Length < capsIfShorterThan)
return codec.ToUpper();
else
return codec.ToTitleCase();
}
}
}

View File

@@ -1,4 +1,5 @@
using Flowframes.Data;
using Flowframes.Forms;
using Flowframes.IO;
using Flowframes.Main;
using Flowframes.Os;
@@ -91,16 +92,14 @@ namespace Flowframes.Ui
return new DialogResult();
}
if (BatchProcessing.busy)
return new DialogResult();
MessageBoxIcon icon = MessageBoxIcon.Information;
if (type == MessageType.Warning) icon = MessageBoxIcon.Warning;
else if (type == MessageType.Error) icon = MessageBoxIcon.Error;
DialogResult res = MessageBox.Show(text, $"Flowframes - {type}", MessageBoxButtons.OK, icon, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
Program.mainForm.Activate();
return res;
//DialogResult res = MessageBox.Show(text, $"Flowframes - {type}", MessageBoxButtons.OK, icon, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
MessageForm form = new MessageForm(text, type.ToString());
form.ShowDialog();
return DialogResult.OK;
}
public enum MoveDirection { Up = -1, Down = 1 };