LTW.YoloDotNet.Core 4.2.1-AotFix.1

This is a prerelease version of LTW.YoloDotNet.Core.
dotnet add package LTW.YoloDotNet.Core --version 4.2.1-AotFix.1
                    
NuGet\Install-Package LTW.YoloDotNet.Core -Version 4.2.1-AotFix.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="LTW.YoloDotNet.Core" Version="4.2.1-AotFix.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LTW.YoloDotNet.Core" Version="4.2.1-AotFix.1" />
                    
Directory.Packages.props
<PackageReference Include="LTW.YoloDotNet.Core" />
                    
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 LTW.YoloDotNet.Core --version 4.2.1-AotFix.1
                    
#r "nuget: LTW.YoloDotNet.Core, 4.2.1-AotFix.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 LTW.YoloDotNet.Core@4.2.1-AotFix.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=LTW.YoloDotNet.Core&version=4.2.1-AotFix.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=LTW.YoloDotNet.Core&version=4.2.1-AotFix.1&prerelease
                    
Install as a Cake Tool

<img src="https://github.com/NickSwardh/YoloDotNet/assets/35733515/994287a9-556c-495f-8acf-1acae8d64ac0" height=24> YoloDotNet v4.2 🚀

面向 .NET 的超快、可用于生产环境的 YOLO 推理库

YoloDotNet 是一个模块化、轻量级的 C# 库,用于在 .NET 中进行实时计算机视觉与 YOLO 推理。

它为现代 YOLO 模型家族(YOLOv5uYOLOv26YOLO-WorldYOLO-ERT-DETR)提供高性能推理,并对执行、内存和预处理提供显式控制。

YoloDotNet 构建于 .NET 8ONNX RuntimeSkiaSharp 之上,有意避免 OpenCV 这类重量级计算机视觉框架。
不依赖 Python 运行时、无隐藏预处理、无隐式行为——仅保留在 Windows / Linux / macOS 上实现快速、可预测推理所需的组件。

没有 Python。没有魔法。只有适用于 .NET 的高性能、确定性 YOLO 推理。

⭐ 为什么选择 YoloDotNet?

YOLOv5u YOLOv8-v26 YOLO-RT-DETR YOLO-World YOLO-E

YoloDotNet 专为以下需求而设计:

  • 纯 .NET —— 无 Python 运行时、无脚本依赖
  • 真实性能 —— 支持 CPU、CUDA / TensorRT、OpenVINO、CoreML、DirectML
  • 显式配置 —— 准确率与内存使用可预测
  • 生产可用 —— 引擎缓存、长时间运行稳定
  • 多视觉任务 —— 检测、OBB、分割、姿态、分类

非常适合需要确定性行为与完全控制的 桌面应用、后端服务与实时视觉流水线

🆕 v4.2 新特性

  • 新增 ROI(感兴趣区域) 支持,可仅对图像或视频流中的指定区域进行推理
    (适用于监控场景、区域告警与性能优化流水线)
  • 新增 分割对象边缘绘制 选项,提升可视化清晰度
  • 新增 JSON 导出辅助方法:
    • ToJson() —— 将推理结果转换为 JSON
    • SaveJson() —— 将推理结果直接保存为 JSON 文件
  • 新增 YOLO 标注格式辅助方法:
    • ToYoloFormat() —— 将结果转换为 YOLO 标注格式
    • SaveYoloFormat() —— 将结果保存为 YOLO 训练数据格式
  • 新增 GetContourPoints(),用于提取分割对象的有序轮廓点
  • 更新 YOLOv26 推理执行流程,与其他任务对齐,提升一致性与整体执行效率

📖 完整版本历史见:CHANGELOG.md

查看示例项目
Demo 项目中提供了可直接运行的实用示例,展示 YoloDotNet 的主要能力:
👉 浏览 Demo 目录

🚀 快速开始

💡 ONNX 模型导出要求

  • YOLOv26 模型请使用 opset=18 导出
  • YOLOv5u–YOLOv12 模型请使用 opset=17 导出

使用正确的 opset 能确保与 ONNX Runtime 的最佳兼容性与性能。
模型导出说明请参考:https://docs.ultralytics.com/modes/export/

示例导出命令(Ultralytics CLI):

# YOLOv5u–YOLOv12(opset 17)
yolo export model=yolov8n.pt format=onnx opset=17

# YOLOv26(opset 18)
yolo export model=yolo26n.pt format=onnx opset=18

模型许可证提示:
YoloDotNet 采用 MIT 许可证,但 多数 Ultralytics YOLO 模型遵循 AGPL-3.0,或在商业使用时需要单独商业授权
你需要自行确保所使用模型符合其许可证要求。
详情参见 Ultralytics 模型许可

1️⃣ 安装核心包

dotnet add package YoloDotNet

2️⃣ 安装 且仅安装一个 执行器包

# CPU(推荐起点)
dotnet add package YoloDotNet.ExecutionProvider.Cpu

# 硬件加速执行(任选其一)
dotnet add package YoloDotNet.ExecutionProvider.Cuda
dotnet add package YoloDotNet.ExecutionProvider.OpenVino
dotnet add package YoloDotNet.ExecutionProvider.CoreML
dotnet add package YoloDotNet.ExecutionProvider.DirectML

💡 说明: CUDA 执行器已包含可选 TensorRT 加速能力。
无需额外安装单独的 TensorRT NuGet 包。

3️⃣ 运行目标检测

using SkiaSharp;
using YoloDotNet;
using YoloDotNet.Models;
using YoloDotNet.Extensions;
using YoloDotNet.ExecutionProvider.Cpu;

using var yolo = new Yolo(new YoloOptions
{
    ExecutionProvider = new CpuExecutionProvider("model.onnx")
});

using var image = SKBitmap.Decode("image.jpg");

// 说明:IoU 参数用于基于 NMS 的模型。
// 对于 YOLOv10 和 YOLOv26,由于后处理由模型内部完成,IoU 会被忽略。
var results = yolo.RunObjectDetection(image, confidence: 0.25, iou: 0.7);

image.Draw(results);
image.Save("result.jpg");

你现在已经在 纯 C# 环境中运行 YOLO 推理了。

💡 重要提示:准确率取决于配置

YOLO 推理的准确率不是自动保证的。

图像缩放模式、采样方法、置信度/IoU 阈值等预处理设置,必须与模型训练时配置保持一致
这些参数直接决定准确率与性能的平衡,应视为模型的一部分。

📖 在调参或对比结果前,请先阅读:
👉 Accuracy & Configuration Guide

支持的任务

Classification Object Detection OBB Detection Segmentation Pose Estimation
<img src="https://user-images.githubusercontent.com/35733515/297393507-c8539bff-0a71-48be-b316-f2611c3836a3.jpg" width=300> <img src="https://user-images.githubusercontent.com/35733515/273405301-626b3c97-fdc6-47b8-bfaf-c3a7701721da.jpg" width=300> <img src="https://github.com/NickSwardh/YoloDotNet/assets/35733515/d15c5b3e-18c7-4c2c-9a8d-1d03fb98dd3c" width=300> <img src="https://github.com/NickSwardh/YoloDotNet/assets/35733515/3ae97613-46f7-46de-8c5d-e9240f1078e6" width=300> <img src="https://github.com/NickSwardh/YoloDotNet/assets/35733515/b7abeaed-5c00-4462-bd19-c2b77fe86260" width=300>
<sub>pexels.com</sub> <sub>pexels.com</sub> <sub>pexels.com</sub> <sub>pexels.com</sub> <sub>pexels.com</sub>

✅ 已验证的 YOLO 模型

下列 YOLO 模型已基于 Ultralytics 官方导出与默认 head,在 YoloDotNet 中完成测试与验证

Classification Object Detection Segmentation Pose Estimation OBB Detection
YOLOv8-cls<br>YOLOv11-cls<br>YOLOv12-cls<br>YOLOv26-cls YOLOv5u<br>YOLOv8<br>YOLOv9<br>YOLOv10<br>YOLOv11<br>YOLOv12<br>YOLOv26<br>RT-DETR YOLOv8-seg<br>YOLOv11-seg<br>YOLOv12-seg<br>YOLOv26-seg<br>YOLO-World (v2) YOLOv8-pose<br>YOLOv11-pose<br>YOLOv12-pose<br>YOLOv26-pose YOLOv8-obb<br>YOLOv11-obb<br>YOLOv12-obb<br>YOLOv26-obb<br>

📁 示例项目

Demo 目录提供可直接动手运行的示例:

👉 浏览 Demo 项目

覆盖图像推理、视频流、GPU 加速、分割以及大图处理等场景。

执行器支持

Provider Windows Linux macOS Documentation
CPU CPU README
CUDA / TensorRT CUDA README
OpenVINO OpenVINO README
CoreML CoreML README
DirectML DirectML README

ℹ️ 只能引用 一个 执行器包。
混用多个执行器会导致本机运行时冲突。

⚡ 性能特征

YoloDotNet 聚焦于稳定、低开销推理,运行成本主要由执行器与模型本身决定。

📊 基准测试:/test/YoloDotNet.Benchmarks

  • 预热后延迟稳定
  • CPU → GPU → TensorRT 线性扩展清晰
  • 内存分配行为可预测
  • 适用于实时与长时间运行服务

🚀 模块化执行器架构

  • 核心包与执行器解耦
  • 执行器以独立 NuGet 包提供
  • ONNX Runtime 本机依赖隔离

价值: 减少冲突、部署可预测、生产环境更安全稳定。

支持 YoloDotNet

⭐ 点亮 Star
💬 反馈建议
🤝 赞助项目开发

GitHub Sponsors
PayPal

许可证

MIT License

Copyright (c) Niklas Swärd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


模型许可证与责任说明

  • YoloDotNet 采用 MIT License,并提供用于运行由 Ultralytics 工具导出的 YOLO ONNX 模型的推理引擎。

  • 本项目内置、分发、下载或捆绑任何预训练模型。

  • 用户需自行提供 ONNX 模型。

  • 使用 Ultralytics 工具生成的 YOLO ONNX 模型,通常受 AGPL-3.0 或 Ultralytics 单独商业许可证约束。

  • YoloDotNet 不会对用户提供模型的许可条款进行附加、修改或转移。

  • 用户需自行负责确保所用模型符合相关许可证条款,包括商业使用、分发或网络部署等要求。

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 was computed.  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 (5)

Showing the top 5 NuGet packages that depend on LTW.YoloDotNet.Core:

Package Downloads
LTW.YoloDotNet.Cuda.TensorRT.Execution.Provider

YoloDotNet 的 CUDA / TensorRT 执行器,可基于 ONNX Runtime 在 NVIDIA 硬件上实现 GPU 加速推理。 该执行器支持 CUDA 通用 GPU 加速,并可选集成 NVIDIA TensorRT,以获得更高性能、更低延迟和更优化的引擎执行。适用于在 Windows 与 Linux 上、具备受支持 NVIDIA GPU 的高吞吐与实时推理场景。 该执行器与 YoloDotNet 核心库完全兼容,并遵循 YoloDotNet v4.0 引入的模块化、与执行器解耦的架构设计。

LTW.YoloDotNet.OpenVINO.Execution.Provider

YoloDotNet OpenVINO 执行器可在受支持的 Intel CPU、核显与加速器上,通过 Intel® OpenVINO™ 实现优化推理。 该执行器将 ONNX Runtime 与 Intel OpenVINO 集成,在 Windows 与 Linux 的 Intel 硬件上提供高性能、低延迟推理。适用于以 CPU 为主的部署、边缘设备场景,以及优先采用 Intel 硬件加速而非 CUDA 的环境。 该执行器采用完全模块化设计,可与 YoloDotNet v4.0 引入的执行器解耦核心库协同工作。每个项目仅应引用一个执行器包。

LTW.YoloDotNet.Cpu.Execution.Provider

YoloDotNet.ExecutionProvider.Cpu 为 YoloDotNet 提供完全可移植、基于 CPU 的执行器,使用 ONNX Runtime 内置 CPU 后端。 该执行器无需额外系统级依赖,开箱即用,支持 Windows、Linux 与 macOS。非常适合开发、测试、CI 环境,以及无 GPU/NPU 加速条件下的生产场景。 CPU 执行器与 YoloDotNet 在 v4.0 引入的模块化执行器架构无缝集成,支持目标检测、分割、分类、姿态估计与 OBB 检测等全部推理任务。

LTW.YoloDotNet.CoreML.Execution.Provider

YoloDotNet.ExecutionProvider.CoreML 基于 Apple 原生 Core ML 框架,在 macOS 上提供硬件加速推理能力。 该执行器集成 ONNX Runtime 的 CoreML 后端,可利用系统级机器学习加速在 Apple Silicon 上高效运行模型。除受支持的 macOS 版本外,无需额外运行时、驱动或 SDK。 CoreML 执行器遵循 YoloDotNet 的模块化、执行器解耦架构,可与核心库无缝集成,并提供可预测、显式的推理行为。适用于需要快速、低功耗、原生推理能力且不希望引入额外依赖的 macOS 应用。

LTW.YoloDotNet.DirectML.Execution.Provider

YoloDotNet.ExecutionProvider.DirectML 基于 Microsoft DirectML 框架,在 Windows 上提供硬件加速推理能力。 该执行器集成 ONNX Runtime 的 DirectML 后端,并运行在 DirectX 12 之上,可借助 Windows 图形驱动栈在多种 GPU 上实现推理加速。DirectML 为 Windows 专属技术,支持 Windows 10/11 且需具备支持 DirectX 12 的 GPU。 除标准 Windows 显卡驱动外,无需厂商专属 SDK 或额外运行时,因此 DirectML 执行器是 Windows GPU 加速的低门槛选择。 DirectML 执行器遵循 YoloDotNet 的模块化、执行器解耦架构,可与核心库无缝集成,并提供显式、可预测的推理行为。适用于希望获得 GPU 加速、同时避免绑定特定硬件厂商或专有 ML 技术栈的 Windows 应用。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.2.1-AotFix.1 68 5/6/2026