# YoloSharpOnnx
**Repository Path**: qq28069933146_admin/YoloSharpOnnx
## Basic Information
- **Project Name**: YoloSharpOnnx
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-07-06
- **Last Updated**: 2026-07-06
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README

# YoloSharpOnnx







[](https://www.nuget.org/packages/YoloSharpOnnx/)
[](https://www.nuget.org/packages/YoloSharpOnnx/)
[](https://github.com/meloht/YoloSharpOnnx)
[](https://github.com/meloht/YoloSharpOnnx)
🚀a high performance, memory reuse, cross-platform, production-ready C# YOLO inference library base on OpenCV and ONNX Runtime.
# Features
- **YOLO Task** [Detect](https://docs.ultralytics.com/tasks/detect), [Classify](https://docs.ultralytics.com/tasks/classify), [Segment](https://docs.ultralytics.com/tasks/segment), [Pose](https://docs.ultralytics.com/tasks/pose), [OBB](https://docs.ultralytics.com/tasks/obb)
- **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](https://github.com/shimat/opencvsharp)
- **Inference Engine** [ONNX Runtime](https://github.com/microsoft/onnxruntime) is a cross-platform inference and training machine-learning accelerator.
- **YOLO Versions** Includes support for: [YOLOv5u](https://docs.ultralytics.com/models/yolov5), [YOLOv8](https://docs.ultralytics.com/models/yolov8), [YOLOv9](https://docs.ultralytics.com/models/yolov9), [YOLOv10](https://docs.ultralytics.com/models/yolov10), [YOLO11](https://docs.ultralytics.com/models/yolo11), [YOLO12](https://docs.ultralytics.com/models/yolo12), [YOLO26](https://docs.ultralytics.com/models/yolo26), [YOLO-World](https://docs.ultralytics.com/zh/models/yolo-world), [YOLOE](https://docs.ultralytics.com/zh/models/yoloe), [RT-DETR](https://docs.ultralytics.com/zh/models/rtdetr)
## Example Images:
| Object Detection | Image Classification |
|---------------|---------------|
|

|

|
| Instance Segmentation |
|--------|
|

|
|

|
| Pose Estimation | Pose Estimation |
|--------|--------|
|

|

|
| OBB Detection | OBB Detection |
|--------|--------|
|

|

|
# Usage
### 1. Export model to ONNX format:
For convert the pre-trained PyTorch model to ONNX format, run the following Python code:
```python
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
```shell
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Microsoft.ML.OnnxRuntime
```
``` csharp
using YoloSharp yolo = new YoloSharp(new ExecutionProviderCPU("yolo11n.onnx"));
```
#### CoreML Inference
```shell
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.osx.10.15-x64
dotnet add package Microsoft.ML.OnnxRuntime
```
```csharp
using YoloSharp yolo = new YoloSharp(new ExecutionProviderCoreML("yolo11n.onnx"));
```
#### CUDA/TensorRT Inference
```shell
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Microsoft.ML.OnnxRuntime.Gpu.Windows
```
```csharp
using YoloSharp yolo = new YoloSharp(new ExecutionProviderCUDA("yolo11n.onnx",0));
using YoloSharp yolo = new YoloSharp(new ExecutionProviderTensorRT("yolo11n.onnx",0));
```
#### DirectML Inference
```shell
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Microsoft.ML.OnnxRuntime.DirectML
```
```csharp
using YoloSharp yolo = new YoloSharp(new ExecutionProviderDirectML("yolo11n.onnx",0));
```
#### OpenVINO Inference
```shell
dotnet add package YoloSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Intel.ML.OnnxRuntime.OpenVino
```
```csharp
using YoloSharp yolo = new YoloSharp(new ExecutionProviderOpenVINO("yolo11n.onnx", IntelDeviceType.NPU));
```
#### Use the following C# code to load the model and run basic prediction:
```csharp
using Mat image = Cv2.ImRead("bus.jpg");
using YoloSharp yolo = new YoloSharp(new ExecutionProviderCPU("yolo11n.onnx"));
List 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
```csharp
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
```csharp
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
```csharp
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
```csharp
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
```csharp
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](https://github.com/dme-compunet/YoloSharp)| 6.1.0 |SixLabors.ImageSharp 3.1.12| Triangle(Bilinear)|support | not support |
| [YoloDotNet](https://github.com/NickSwardh/YoloDotNet)| 4.2.0 |SkiaSharp 3.119.1| Linear(Bilinear) |support | support |
| [YoloSharpOnnx](https://github.com/meloht/YoloSharpOnnx)| 1.3.3 |OpenCvSharp4 4.13.0.20260318|Linear(Bilinear)|support | support |
## Performance Test Tool
[YoloOnnxWinform](https://github.com/meloht/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
## YoloDotNet test result
**Sequence inference time:** 17.665s **Memory Usage:** 169M
**Batch inference time:** 10.587s **Memory Usage:** 639M
## YoloSharpOnnx test result
**Sequence inference time:** 13.693s **Memory Usage:** 169M
**Batch inference time:** 2.980s **Memory Usage:** 601M
## Performance Test Result
|Yolo C# inference library|Version|Image Processing library|Image Resize Algorithm|Sequence inference (Time/Memory)| Batch inference (Time/Memory)|
| ------------- | ------------- | ------------- |------------- |------------- |------------- |
| [YoloSharp](https://github.com/dme-compunet/YoloSharp)| 6.1.0 |SixLabors.ImageSharp 3.1.12| Triangle(Bilinear)| 18.707s, 1374M | - |
| [YoloDotNet](https://github.com/NickSwardh/YoloDotNet)| 4.2.0 |SkiaSharp 3.119.1| Linear(Bilinear)| 17.665s, 169M | 10.587s, 639M |
| [YoloSharpOnnx](https://github.com/meloht/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 !!!**
# Model Licensing & Responsibility
* YoloSharpOnnx is licensed under the [MIT License](./LICENSE.txt) 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.