YoloSharpOnnx 3.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package YoloSharpOnnx --version 3.2.1
                    
NuGet\Install-Package YoloSharpOnnx -Version 3.2.1
                    
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="YoloSharpOnnx" Version="3.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="YoloSharpOnnx" Version="3.2.1" />
                    
Directory.Packages.props
<PackageReference Include="YoloSharpOnnx" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add YoloSharpOnnx --version 3.2.1
                    
#r "nuget: YoloSharpOnnx, 3.2.1"
                    
#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.
#:package YoloSharpOnnx@3.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=YoloSharpOnnx&version=3.2.1
                    
Install as a Cake Addin
#tool nuget:?package=YoloSharpOnnx&version=3.2.1
                    
Install as a Cake Tool

YoloSharpOnnx

YoloSharpOnnx

YOLOv8-v26 C# .NET Version ONNX Runtime OpenCV GitHub license Release NuGet NuGet GitHub last commit GitHub commit activity

🚀a high performance, memory reuse, cross-platform, production-ready C# YOLO inference library base on OpenCV and ONNX Runtime.

Features

Example Images:

<div align="center">

Object Detection Image Classification
<img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/bus_detect.jpg?raw=true" height="600"> <img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/det_000000270579.jpg?raw=true" width="500" > <img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/cls_000000000009.jpg?raw=true" width="500" > <img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/cls_000000063409.jpg?raw=true" height="650" >
Instance Segmentation
<img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/res_seg_zidane.jpg?raw=true" height="600">
<img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/res_seg_02.png?raw=true" height="350">
Pose Estimation Pose Estimation
<img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/res_pose_01.png?raw=true" width="550"> <img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/res_pose_02.png?raw=true" width="400">
OBB Detection OBB Detection
<img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/res_obb_01.jpg?raw=true" width="500"> <img src="https://github.com/meloht/YoloSharpOnnx/blob/master/ExampleImages/res_obb_02.jpg?raw=true" width="500">

</div>

Usage

1. Export model to ONNX format:

For convert the pre-trained PyTorch model to ONNX format, run the following Python code:

from ultralytics import YOLO

# Load a model
model = YOLO('path/to/best.pt')

# Export the model to ONNX format
model.export(format='onnx')

2. Load the ONNX model with C#:

Install Nuget packages YoloSharpOnnx, OnnxRuntime, OpenCvSharp4.runtime

CPU Inference
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Microsoft.ML.OnnxRuntime
using YoloSharp yolo = new YoloSharp(new ExecutionProviderCPU("yolo11n.onnx"));
CoreML Inference
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.osx.10.15-x64
dotnet add package Microsoft.ML.OnnxRuntime
using YoloSharp yolo = new YoloSharp(new ExecutionProviderCoreML("yolo11n.onnx"));
CUDA/TensorRT Inference
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Microsoft.ML.OnnxRuntime.Gpu.Windows
using YoloSharp yolo = new YoloSharp(new ExecutionProviderCUDA("yolo11n.onnx",0));
using YoloSharp yolo = new YoloSharp(new ExecutionProviderTensorRT("yolo11n.onnx",0));
DirectML Inference
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Microsoft.ML.OnnxRuntime.DirectML
using YoloSharp yolo = new YoloSharp(new ExecutionProviderDirectML("yolo11n.onnx",0));
OpenVINO Inference
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Intel.ML.OnnxRuntime.OpenVino
using YoloSharp yolo = new YoloSharp(new ExecutionProviderOpenVINO("yolo11n.onnx", IntelDeviceType.NPU));
Use the following C# code to load the model and run basic prediction:

using Mat image = Cv2.ImRead("bus.jpg");
using YoloSharp yolo = new YoloSharp(new ExecutionProviderCPU("yolo11n.onnx"));

List<DetectionResult> res = yolo.RunDetect(image);

yolo.DrawDetections(image,res);
Cv2.ImWrite("bus_res.jpg", image);

string printString = res.Summary();
Console.WriteLine(printString);

YoloSharpOnnx performance testing api

using Mat image = Cv2.ImRead("bus.jpg");
     
using YoloSharp yolo = new YoloSharp(new ExecutionProviderDirectML("yolo11n.onnx",1));
var res = yolo.RunDetectWithTime(item.FullName);

Console.WriteLine($"{res.ToString()}, {res.SpeedResult.ToString()}");

Config
using Mat image = Cv2.ImRead("bus.jpg");
using YoloSharp yolo = new YoloSharp(new ExecutionProviderCPU("yolo11n.onnx"));
yolo.YoloConfiguration.IoU = 0.4f;
yolo.YoloConfiguration.Confidence = 0.3f;
yolo.YoloConfiguration.ResizeAlgorithm = InterpolationFlags.Linear;
yolo.YoloConfiguration.ImageExtsBatch = [".jpg", ".png"];
var res = yolo.RunDetect(image);
Asynchronous inference
private static async Task TestInferAsync()
{
    string modelPath = @"D:\code\model\best.onnx";
    string dir = @"D:\code\model\TestImages";
    using var yolo = new YoloSharp(new ExecutionProviderDirectML(modelPath, 1));
    System.Diagnostics.Stopwatch _stopwatchTotal = new System.Diagnostics.Stopwatch();
    _stopwatchTotal.Start();
    var files = Directory.GetFiles(dir);
    using (var yoloAsync = yolo.CreateAsyncChannel())
    {
        
        for (int i = 0; i < files.Length; i++)
        {
            var res = await yoloAsync.RunDetectAsync(files[i]);
            Console.WriteLine($"{i + 1} {res.Summary()}");
        }
        await yoloAsync.CompleteAndCloseAsyncChannel();// important
    }
    _stopwatchTotal.Stop();
    var avg = _stopwatchTotal.ElapsedMilliseconds / files.Length;
    Console.WriteLine($"total time:{_stopwatchTotal.Elapsed}, count:{files.Length} Infer avg time:{avg}ms");
}

private static async Task TestInferBatchAsync()
{
     using var yolo = new YoloSharp(new ExecutionProviderDirectML(modelPath, _deviceId));
     using var yoloAsync = yolo.CreateAsyncChannel();
     var files = Directory.GetFiles(dir);
     count = 1;
    for (int i = 0; i < files.Length; i++)
    {
         using Mat img = Cv2.ImRead(files[i]);
         await yoloAsync.RunDetectAsync(img, Guid.NewGuid(), null, ReceiveProcess);

    }
    await yoloAsync.CompleteAndCloseAsyncChannel();// important
}
static int count = 1;
private static void ReceiveProcess(DetectAsyncResult e)
{
    long cost = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - e.StartTimestamp;
    string ans = e.Results.Summary();
    Console.WriteLine($"{count++} {ans} time:{cost}ms");
}
Batch processing images
private static void TestBatchInfer()
{
    string modelPath = @"D:\code\model\best.onnx";
    string dir = @"D:\code\model\TestImages"
    DirectoryInfo directory = new DirectoryInfo(dir);
    var files = directory.GetFiles()
    System.Diagnostics.Stopwatch _stopwatch = new System.Diagnostics.Stopwatch();
    _stopwatch.Start();
    int num=files.Length;
    using (YoloSharp yolo = new YoloSharp(new ExecutionProviderDirectML(modelPath, 0)))
    {
        var list = yolo.RunBatchDetect(dir,new ProcessCallback(), ReceiveProcess)
    }
    _stopwatch.Stop()
    Console.WriteLine($"detect {num} images, time:{_stopwatch.Elapsed}");

}
private static void ReceiveProcess(DetectionBatchResult e)
{
    string res = e.Results.Summary();
}
internal class ProcessCallback : IBatchProcessCallback
{
   
    public void ReceiveProcessResult(DetectionBatchResult e)
    {
       
        string res = e.Results.Summary();
      
    }
}

Batch processing images foreach api
private static async Task TestBatchForeachInfer()
{
    var files = Directory.GetFiles(dir);
    System.Diagnostics.Stopwatch _stopwatch = new System.Diagnostics.Stopwatch();
    _stopwatch.Start();
    int num = files.Length;
    using (YoloSharp yolo = new YoloSharp(new ExecutionProviderDirectML(modelPath, _deviceId)))
    {
        yolo.YoloConfiguration.BatchPoolSize = 30;
        await foreach (var item in yolo.BatchDetectForeachAsync(files.ToList()))
        {
            Console.WriteLine($"{item.ImagePath} {item.Results.Summary()}");
        }
    }
    _stopwatch.Stop();
    Console.WriteLine($"detect {num} images, time:{_stopwatch.Elapsed}");
}

Performance Test

Yolo C# inference library Version Image Processing library Image Resize Algorithm Sequence inference Batch inference
YoloSharp 6.1.0 SixLabors.ImageSharp 3.1.12 Triangle(Bilinear) support not support
YoloDotNet 4.2.0 SkiaSharp 3.119.1 Linear(Bilinear) support support
YoloSharpOnnx 1.3.3 OpenCvSharp4 4.13.0.20260318 Linear(Bilinear) support support

Performance Test Tool

YoloOnnxWinform

Performance Test PC

Hardware Summary
Windows Windows 10 OS Version 19045.6466
CPU AMD Ryzen 7 5800X 8-Core Processor 3.8GHz
RAM DDR4 3200 MHz 32GB
GPU AMD Radeom RX6800 16GB
Storage SSD 2TB

Performance Test Data

Images: 300 images (image size: 2480x3494)

Yolo Model: Yolo11n.onnx InputShape float32[1,3,1280,1280]

Inference Provider: DirectML Inference Microsoft.ML.OnnxRuntime.DirectML 1.24.3

YoloSharp test result

Sequence inference time: 18.707s Memory Usage: 1374M

<img width="1251" height="737" alt="image" src="https://github.com/user-attachments/assets/b89ad044-ecc7-4857-93dd-329994c31c23" />

YoloDotNet test result

Sequence inference time: 17.665s Memory Usage: 169M

Batch inference time: 10.587s Memory Usage: 639M

<img width="1156" height="744" alt="image" src="https://github.com/user-attachments/assets/0dff1405-be54-46c1-88bf-d7e556d6fa32" />

<img width="1156" height="744" alt="image" src="https://github.com/user-attachments/assets/8fa757eb-e678-4fd5-9374-4c7dd81865fa" />

YoloSharpOnnx test result

Sequence inference time: 13.693s Memory Usage: 169M

Batch inference time: 2.980s Memory Usage: 601M

<img width="1206" height="733" alt="image" src="https://github.com/user-attachments/assets/f63c2399-8989-4986-a225-63f0f35a5769" />

<img width="1206" height="733" alt="image" src="https://github.com/user-attachments/assets/c0c1e6d9-6469-436c-b103-0437ff85dddc" />

Performance Test Result

Yolo C# inference library Version Image Processing library Image Resize Algorithm Sequence inference (Time/Memory) Batch inference (Time/Memory)
YoloSharp 6.1.0 SixLabors.ImageSharp 3.1.12 Triangle(Bilinear) 18.707s, 1374M -
YoloDotNet 4.2.0 SkiaSharp 3.119.1 Linear(Bilinear) 17.665s, 169M 10.587s, 639M
YoloSharpOnnx 1.3.3 OpenCvSharp4 4.13.0.20260318 Linear(Bilinear) 13.693s, 169M 2.980s, 601M
YoloSharpOnnx YoloSharp YoloDotNet
YoloSharpOnnx YoloSharp YoloDotNet

The accuracy and performance of YoloSharpOnnx are the best !!!

Model Licensing & Responsibility

  • YoloSharpOnnx is licensed under the MIT License and provides an ONNX inference engine for YOLO models exported using Ultralytics YOLO tooling.

  • This project does not include, distribute, download, or bundle any pretrained models.

  • Users must supply their own ONNX models.

  • YOLO ONNX models produced using Ultralytics tooling are typically licensed under AGPL-3.0 or a separate commercial license from Ultralytics.

  • YoloSharpOnnx does not impose, modify, or transfer any license terms related to user-supplied models.

  • Users are solely responsible for ensuring that their use of any model complies with the applicable license terms, including requirements related to commercial use, distribution, or network deployment.

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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
3.4.0 169 11/9/2026
3.3.3 199 10/8/2026
3.3.2 212 8/11/2026
3.3.1 163 7/17/2026
3.3.0 162 7/8/2026
3.2.3 204 6/16/2026
3.2.2 163 5/29/2026
3.2.1 148 5/29/2026
3.2.0 143 5/28/2026
3.1.0 155 5/27/2026
3.0.0 148 5/25/2026
2.2.0 146 5/21/2026
2.1.2 139 5/19/2026
2.1.1 147 5/19/2026
2.1.0 152 5/18/2026
2.0.2 139 5/11/2026
2.0.1 146 5/10/2026
2.0.0 149 5/10/2026
1.3.4 142 4/28/2026
1.3.3 176 4/3/2026
Loading failed

YoloSharpOnnx 3.2.1 batch api improvements