YoloDotNet 1.0.0
See the version list below for details.
dotnet add package YoloDotNet --version 1.0.0
NuGet\Install-Package YoloDotNet -Version 1.0.0
<PackageReference Include="YoloDotNet" Version="1.0.0" />
paket add YoloDotNet --version 1.0.0
#r "nuget: YoloDotNet, 1.0.0"
// Install YoloDotNet as a Cake Addin
#addin nuget:?package=YoloDotNet&version=1.0.0
// Install YoloDotNet as a Cake Tool
#tool nuget:?package=YoloDotNet&version=1.0.0
YoloDotNet
YoloDotNet is a C# .NET 7.0 implementation of Yolov8 and ONNX runtime with CUDA
Yolov8 is a real-time object detection tool by Ultralytics. YoloDotNet is a .NET 7 implementation of Yolov8 for detecting objects in images and videos using ML.NET and the ONNX runtime with GPU acceleration using CUDA.
<sup>image from pexels.com</sup>
Requirements
When using YoloDotNet with GPU-acceleration, you need CUDA and cuDNN.
ℹ️ Before you install CUDA and cuDNN, make sure to verify the ONNX runtime's current compatibility with specific versions.
- Download and install CUDA
- Download cuDNN and follow the installation instructions
- Yolov8 model exported to ONNX format
ℹ️ For Video, you need FFmpeg and FFProbe
- Download FFMPEG
- Add FFmpeg and ffprobe to the Path-variable in your Environment Variables
Example - Image
using SixLabors.ImageSharp;
using YoloDotNet;
using YoloDotNet.Extensions;
// Instantiate a new Yolo object with your ONNX-model and CUDA
using var yolo = new Yolo(@"path\to\model.onnx");
// Load image
using var image = Image.Load<Rgb32>(@"path\to\image.jpg");
// Run inference
var results = yolo.RunInference(image);
// Draw boxes
image.DrawBoundingBoxes(results);
// Save image
image.Save(@"save\image.jpg");
Example - Video
using SixLabors.ImageSharp;
using YoloDotNet;
using YoloDotNet.Extensions;
// Instantiate a new Yolo object with your ONNX-model and CUDA
using var yolo = new Yolo(@"path\to\model.onnx");
// Run inference
yolo.RunInference(new VideoOptions
{
VideoFile = @"path\to\video.mp4",
OutputDir = @"path\to\outputfolder"
});
GPU
Object detection with GPU and GPU-Id = 0 is enabled by default
// Default setup. GPU with GPU-Id 0
using var yolo = new Yolo(@"path\to\model.onnx");
With a specific GPU-Id
// GPU with a user defined GPU-Id
using var yolo = new Yolo(@"path\to\model.onnx", true, 1);
CPU
YoloDotNet detection with CPU
// With CPU
using var yolo = new Yolo(@"path\to\model.onnx", false);
Access ONNX metadata and labels
The internal ONNX metadata such as input & output parameters, version, author, description, date along with the labels can be accessed via the yolo.OnnxModel
property.
Example:
using var yolo = new Yolo(@"path\to\model.onnx");
// ONNX metadata and labels resides inside yolo.OnnxModel
Console.WriteLine(yolo.OnnxModel);
Example:
// Instantiate a new object
using var yolo = new Yolo(@"path\to\model.onnx");
// Display metadata
foreach (var property in yolo.OnnxModel.GetType().GetProperties())
{
var value = property.GetValue(yolo.OnnxModel);
Console.WriteLine($"{property.Name,-20}{value!}");
}
// Get ONNX labels
var labels = yolo.OnnxModel.Labels;
Console.WriteLine();
Console.WriteLine($"Labels ({labels.Length}):");
Console.WriteLine(new string('-', 58));
// Display
for (var i = 0; i < labels.Length; i++)
Console.WriteLine($"index: {i,-8} label: {labels[i].Name,20} color: {labels[i].Color}");
// Output:
// InputName = images
// OutputName = output0
// Date = 2023-10-03 11:32:15
// Description = Ultralytics YOLOv8m model trained on coco.yaml
// Author = Ultralytics
// Task = detect
// License = AGPL-3.0 https://ultralytics.com/license
// Version = 8.0.181
// Stride = 32
// BatchSize = 1
// ImageSize = Size[Width = 640, Height = 640]
// Input = Input { BatchSize = 1, Channels = 3, Width = 640, Height = 640 }
// Output = Output { BatchSize = 1, Dimensions = 84, Channels = 8400 }
//
// Labels (80):
// ---------------------------------------------------------
// index: 0 label: person color: #5d8aa8
// index: 1 label: bicycle color: #f0f8ff
// index: 2 label: car color: #e32636
// index: 3 label: motorcycle color: #efdecd
// ...
References & Acknowledgements
https://github.com/ultralytics/ultralytics
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. |
-
net8.0
- Microsoft.ML.OnnxRuntime.Gpu (>= 1.16.3)
- Newtonsoft.Json (>= 13.0.3)
- SixLabors.Fonts (>= 2.0.1)
- SixLabors.ImageSharp (>= 3.1.0)
- SixLabors.ImageSharp.Drawing (>= 2.1.0)
- System.Drawing.Common (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.