YoloSharpOnnx 2.0.1
See the version list below for details.
dotnet add package YoloSharpOnnx --version 2.0.1
NuGet\Install-Package YoloSharpOnnx -Version 2.0.1
<PackageReference Include="YoloSharpOnnx" Version="2.0.1" />
<PackageVersion Include="YoloSharpOnnx" Version="2.0.1" />
<PackageReference Include="YoloSharpOnnx" />
paket add YoloSharpOnnx --version 2.0.1
#r "nuget: YoloSharpOnnx, 2.0.1"
#:package YoloSharpOnnx@2.0.1
#addin nuget:?package=YoloSharpOnnx&version=2.0.1
#tool nuget:?package=YoloSharpOnnx&version=2.0.1
YoloSharpOnnx
🚀a high performance, memory reuse, cross-platform, production-ready C# YOLO inference library base on OpenCV and ONNX Runtime.
Features
- YOLO Task Object Detection Image Classification
- Execution Provider CPU, CUDA / TensorRT, OpenVINO, CoreML, DirectML
- Batch processing images Preprocess and Inference are executed asynchronously with Producer/Consumer pattern
- High Performance Inference Memory reuse, GPU Inference with I/O Binding
- Image Processing OpenCvSharp4
- Inference Engine ONNX Runtime is a cross-platform inference and training machine-learning accelerator.
- YOLO Versions Includes support for: YOLOv8, YOLO11, YOLO26
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" > |
</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 = YoloUtils.GetResult(res);
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} {YoloUtils.GetResult(res)}");
}
}
_stopwatchTotal.Stop();
var avg = _stopwatchTotal.ElapsedMilliseconds / files.Length;
Console.WriteLine($"total time:{_stopwatchTotal.Elapsed}, count:{files.Length} Infer avg time:{avg}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, 30)
}
_stopwatch.Stop()
Console.WriteLine($"detect {num} images, time:{_stopwatch.Elapsed}");
}
private static void ReceiveProcess(DetectionBatchResult e)
{
string res = YoloUtils.GetResult(e.Results)
}
internal class ProcessCallback : IBatchProcessCallback
{
public void ReceiveProcessResult(DetectionBatchResult e)
{
string res = YoloUtils.GetResult(e.Results);
}
}
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} {YoloUtils.GetResult(item.Results)}");
}
}
_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
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 |
|---|---|---|
The accuracy and performance of YoloSharpOnnx are the best !!!
Roadmap
| Time | Feature |
|---|---|
| 2026-11 | Yolo task Instance Segmentation |
| 2026-11 | Yolo task Pose Estimation |
| 2026-12 | Yolo task OBB |
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 | 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. 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. |
-
net10.0
- Microsoft.ML.OnnxRuntime.Managed (>= 1.25.1)
- OpenCvSharp4 (>= 4.13.0.20260427)
-
net8.0
- Microsoft.ML.OnnxRuntime.Managed (>= 1.25.1)
- OpenCvSharp4 (>= 4.13.0.20260427)
-
net9.0
- Microsoft.ML.OnnxRuntime.Managed (>= 1.25.1)
- OpenCvSharp4 (>= 4.13.0.20260427)
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 |
YoloSharpOnnx 2.0.1 model task validation