https://github.com/dme-compunet/YoloSharp
Use YOLO11 in real-time for object detection tasks 🚀 with edge performance ⚡️ powered by ONNX-Runtime.
https://github.com/dme-compunet/YoloSharp
csharp dotnet image-classification imagesharp instance-segmentation obb object-detection onnx-runtime oriented-object-detection pose-estimation ultralytics yolo yolo11 yolov10 yolov8
Last synced: 17 days ago
JSON representation
Use YOLO11 in real-time for object detection tasks 🚀 with edge performance ⚡️ powered by ONNX-Runtime.
- Host: GitHub
- URL: https://github.com/dme-compunet/YoloSharp
- Owner: dme-compunet
- License: agpl-3.0
- Created: 2023-06-20T14:41:26.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-31T07:40:38.000Z (6 months ago)
- Last Synced: 2024-10-31T08:25:50.934Z (6 months ago)
- Topics: csharp, dotnet, image-classification, imagesharp, instance-segmentation, obb, object-detection, onnx-runtime, oriented-object-detection, pose-estimation, ultralytics, yolo, yolo11, yolov10, yolov8
- Language: C#
- Homepage: https://www.nuget.org/packages/YoloSharp
- Size: 12.9 MB
- Stars: 263
- Watchers: 11
- Forks: 52
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-yolo-object-detection - dme-compunet/YOLOv8 - compunet/YOLOv8?style=social"/> : Use YOLOv8 in real-time, for object detection, instance segmentation, pose estimation and image classification, via ONNX Runtime. (Other Versions of YOLO)
README
# YoloSharp
🚀 Use [YOLO11](https://github.com/ultralytics/ultralytics) in real-time for object detection tasks, with edge performance ⚡️ powered by ONNX-Runtime.
# Features
- **YOLO Tasks** 🌟 Support for all YOLO vision tasks ([Detect](https://docs.ultralytics.com/tasks/detect) | [OBB](https://docs.ultralytics.com/tasks/obb) | [Pose](https://docs.ultralytics.com/tasks/pose) | [Segment](https://docs.ultralytics.com/tasks/segment) | [Classify](https://docs.ultralytics.com/tasks/classify))
- **High Performance** 🚀 Various techniques and use of .NET features to maximize performance
- **Reduced Memory Usage** 🧠 By reusing memory blocks and reducing the pressure on the GC
- **Plotting Options** ✏️ Draw the predictions on the target image to preview the model results
- **YOLO Versions** 🔧 Includes support for: [YOLOv8](https://docs.ultralytics.com/models/yolov8) [YOLOv10](https://docs.ultralytics.com/models/yolov10) [YOLO11](https://docs.ultralytics.com/models/yolo11)# Installation
This project provides two NuGet packages:
- For CPU inference, use the package: [YoloSharp](https://www.nuget.org/packages/YoloSharp) (includes the [Microsoft.ML.OnnxRuntime](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime) package)
- For GPU inference, use the package: [YoloSharp.Gpu](https://www.nuget.org/packages/YoloSharp.Gpu) (includes the [Microsoft.ML.OnnxRuntime.Gpu](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime.Gpu) package)# 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#:
Add the `YoloSharp` (or `YoloSharp.Gpu`) package to your project:
```shell
dotnet add package YoloSharp
```Use the following C# code to load the model and run basic prediction:
```csharp
using Compunet.YoloSharp;// Load the YOLO predictor
using var predictor = new YoloPredictor("path/to/model.onnx");// Run model
var result = predictor.Detect("path/to/image.jpg");
// or
var result = await predictor.DetectAsync("path/to/image.jpg");// Write result summary to terminal
Console.WriteLine(result);
```# Plotting
You can to plot the target image for preview the model results, this code demonstrates how to run a inference, plot the results on image and save to file:
```csharp
using Compunet.YoloSharp;
using Compunet.YoloSharp.Plotting;
using SixLabors.ImageSharp;// Load the YOLO predictor
using var predictor = new YoloPredictor("path/to/model.onnx");// Load the target image
using var image = Image.Load("path/to/image");// Run model
var result = await predictor.PoseAsync(image);// Create plotted image from model results
using var plotted = await result.PlotImageAsync(image);// Write the plotted image to file
plotted.Save("./pose_demo.jpg");
```You can also predict and save to file in one operation:
```csharp
using Compunet.YoloSharp;
using Compunet.YoloSharp.Plotting;
using SixLabors.ImageSharp;// Load the YOLO predictor
using var predictor = new YoloPredictor("path/to/model.onnx");// Run model, plot predictions and write to file
predictor.PredictAndSaveAsync("path/to/image");
```## Example Images:
#### Detection:

#### Pose:

#### Segmentation:

# Not Supported:
The following features are not currently supported, they may be added later
- **Batch Processing:** You have to predict them one by one
- **Dynamic Size:** The image resized according to `imgsz`# License
AGPL-3.0 License
**Important Note:** This project depends on ImageSharp, you should check the license details [here](https://github.com/SixLabors/ImageSharp/blob/main/LICENSE)