基于 ONNX-Runtime 的高性能实时物体检测解决方案 YOLO11 ⚡️
A high performance real-time object detection solution using YOLO11 ⚡️ powered by ONNX-Runtime
The project provides the following NuGet packages:
| Package | Description | Dependencies |
|---|---|---|
| YoloSharp | CPU-based inference | Includes all runtime dependencies (all platforms) |
| YoloSharp.Gpu | GPU-based inference | Includes all runtime dependencies (all platforms) |
| YoloSharp.Core | Core library without runtime dependencies | None – suitable for lightweight production or for using alternative runtimes |
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')Add the YoloSharp (or YoloSharp.Gpu) package to your project:
dotnet add package YoloSharpUse the following C# code to load the model and run basic prediction:
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);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:
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:
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");| Detect | Pose |
|---|---|
| Segment | Obb |
The following features are not currently supported, they may be added later
imgszAGPL-3.0 License
Important Note: This project depends on ImageSharp, you should check the license details here
暂无开放 Issues,或尚未同步最近议题。