UAI_ONNX 1.0.8.10

dotnet add package UAI_ONNX --version 1.0.8.10                
NuGet\Install-Package UAI_ONNX -Version 1.0.8.10                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UAI_ONNX" Version="1.0.8.10" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UAI_ONNX --version 1.0.8.10                
#r "nuget: UAI_ONNX, 1.0.8.10"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UAI_ONNX as a Cake Addin
#addin nuget:?package=UAI_ONNX&version=1.0.8.10

// Install UAI_ONNX as a Cake Tool
#tool nuget:?package=UAI_ONNX&version=1.0.8.10                

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 RunFrameOnnxInference()
        {

            await base.RunFrameOnnxInference();

            // 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 gets sent when all the this.frames are finished.
        }

       
        public override async Task SendInferenceFinished()
        {
           Console.WriteLine("Inference Finished");
           base.SendInferenceFinished();
        }

        // Called every frame. 'delta' is the elapsed time since the previous frame.
        public override void Update(float delta)
	{
	}
}
}


Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.8.10 89 11/14/2024
1.0.8.9 84 11/14/2024
1.0.8.8 85 11/14/2024
1.0.8.7 86 11/14/2024
1.0.8.5 90 11/13/2024
1.0.8.4 93 11/10/2024
1.0.8.3 92 11/10/2024
1.0.8.2 88 11/10/2024
1.0.8.1 88 11/4/2024
1.0.8 88 11/4/2024
1.0.7.5 91 11/3/2024