![]() |
VOOZH | about |
dotnet add package UAI_ONNX --version 1.0.8.10
NuGet\Install-Package UAI_ONNX -Version 1.0.8.10
<PackageReference Include="UAI_ONNX" Version="1.0.8.10" />
<PackageVersion Include="UAI_ONNX" Version="1.0.8.10" />Directory.Packages.props
<PackageReference Include="UAI_ONNX" />Project file
paket add UAI_ONNX --version 1.0.8.10
#r "nuget: UAI_ONNX, 1.0.8.10"
#:package UAI_ONNX@1.0.8.10
#addin nuget:?package=UAI_ONNX&version=1.0.8.10Install as a Cake Addin
#tool nuget:?package=UAI_ONNX&version=1.0.8.10Install as a Cake Tool
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.
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.
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.