UAI_ONNX 1.0.8.3
See the version list below for details.
dotnet add package UAI_ONNX --version 1.0.8.3
NuGet\Install-Package UAI_ONNX -Version 1.0.8.3
<PackageReference Include="UAI_ONNX" Version="1.0.8.3" />
paket add UAI_ONNX --version 1.0.8.3
#r "nuget: UAI_ONNX, 1.0.8.3"
// Install UAI_ONNX as a Cake Addin #addin nuget:?package=UAI_ONNX&version=1.0.8.3 // Install UAI_ONNX as a Cake Tool #tool nuget:?package=UAI_ONNX&version=1.0.8.3
UAI ONNX
ONNX Runner built for C# projects that target .Net8.0 or later. This library is built on top of the ONNX Runtime C# API and provides a simple way to load and run ONNX models in C#.
Microsoft.ML.OnnxRuntime.GPU
is not installed since that should be handled by the next application that uses this library.
Installation
You can restore the Nuget dependencies by running the following command in the project directory:
dotnet restore
You will need to copy the contents of UAI\thirdParty\openCV
to the output directory of your app. This is because the OpenCV dlls are not included in the Nuget package.
Usage
OnnxImageProcessor
The OnnxImageProcessor
class is a base class that can be extended to create custom image processing models. The class provides methods to load an ONNX model, preprocess input images, run inference, and post-process the output tensors. The class is designed to be used with image processing models that take an image as input and return an output.
using Microsoft.ML.OnnxRuntime;
using System.Drawing;
using UAI.Common.AI;
namespace UAI.AI.Models.FaceParsing
{
public class FaceParsing : OnnxImageProcessor
{
public override string[] labels { get { return labels_; } set { labels_ = value; } }
public string[] labels_ = new string[] { "Background", "Skin", "Nose", "Glasses", "Left Eye", "Right Eye", "Left Brow", "Right Brow", "Left Ear", "Right Ear",
"Mouth", "Upper Lip", "Lower Lip","Hair" , "Hat", "Earring", "Necklace", "Clothing" };
public FaceParsing(string modelPath) : base(modelPath)
{
}
public override void Start()
{
base.Start();
SetInputName("input","pixel_values");
SetInputDimensions("pixel_values", new List<int>() { 1, 3, 512, 512 });
SetOutputName("output","logits");
SetOutputDimensions("logits", new List<int>() { 1, 18, 512, 512 });
}
public override async Task RunOnnxInference()
{
await base.RunOnnxInference();
// Setup Ouptuts based on inputImage
config.onnxMetaData.Inputs[0].dimensions = new List<int>() { 1, 3, inputImageSize.x, inputImageSize.y };
config.onnxMetaData.Outputs[0].dimensions = new List<int>() { 1, 18, inputImageSize.x, inputImageSize.y };
var outputPath = FaceParserRuntime.args.outputPath;
// PreProcess Data
var inputData = CreateOnnxInput(MatToTensor(Texture2DToMat(inputTexture, inputImageSize)));
// Process Image
IDisposableReadOnlyCollection<DisposableNamedOnnxValue> results = _session.Run(inputData, CreateOnnxOutput());
// Process the Output Data
var rest = GetResultTensors(results);
List<Bitmap> bitmaps = ConvertTensorsToBitmaps(inputImageSize, rest);
// Save the Masks and JSON if the options are set
ProcessSaveMasks(bitmaps, outputPath, FaceParserRuntime.args.saveMasks);
ProcessJSONOutput(bitmaps, outputPath +"/" + Path.GetFileNameWithoutExtension(FaceParserRuntime.args.inputPath) + "_masks.json", FaceParserRuntime.args.saveJson);
// Send Inference Finished Signal
await SendInferenceFinished();
}
public virtual async Task SendInferenceFinished()
{
Console.WriteLine("Inference Finished");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void Update(float delta)
{
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- CommandLineParser (>= 2.9.1)
- Emgu.CV (>= 4.9.0.5494)
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Microsoft.Extensions.Hosting (>= 8.0.1)
- Microsoft.ML (>= 3.0.1)
- Microsoft.ML.OnnxRuntime (>= 1.19.2)
- System.Drawing.Common (>= 8.0.10)
- TinyEXR.NET (>= 0.3.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.